コード例 #1
0
ファイル: Event.php プロジェクト: bennysuh/workerman-game
 /**
  * 有消息时
  * @param int $uid
  * @param string $message
  */
 public static function onMessage($uid, $message)
 {
     $message_data = json_decode($message, true);
     // 向所有人发送
     if ($message_data['to_uid'] == 'all') {
         return GateWay::sendToAll($message);
     } else {
         return GateWay::sendToUid($message_data['to_uid'], $message);
     }
 }
コード例 #2
0
ファイル: Event.php プロジェクト: bajian/js-web-skills
 public static function onMessage($client_id, $message)
 {
     // 获取客户端请求
     $message_data = json_decode($message, true);
     echo 'message' . $message . 'ID' . $client_id;
     if (!$message_data) {
         return;
     }
     //text-info 是系统发送的。text-user 是其他用户发送的。
     switch ($message_data['type']) {
         case 'JOIN':
             // 转播给所有用户
             Gateway::sendToAll(json_encode(array('type' => 'NOTE', 'id' => $client_id, 'text_type' => 'text-info', 'msg' => $message_data['user_nickname'] . '加入聊天。当前共有' . count(Gateway::getOnlineStatus()) . '把剪子在线。')));
             break;
         case 'QUIT':
             // 转播给所有用户
             GateWay::sendToAll(json_encode(array('type' => 'QUIT', 'msg' => $message_data['from'] . '退出聊天啦 T^T'), true));
             break;
         case 'EDIT':
             // 转播给所有用户
             Gateway::sendToAll(json_encode(array('type' => 'EDIT', 'from' => $message_data['from'], 'to' => $message_data['to'], 'head' => $message_data['head'])));
             break;
         case 'NAME':
             // var_export(Gateway::getOnlineStatus());
             // echo 'online num :'.count(Gateway::getOnlineStatus());
             $id = mt_rand(1, 9);
             Gateway::sendToCurrentClient('{"type":"NAME","head":"http://img3.178.com/acg1/201507/230072993522/230073874484.jpg","name":"剪纸' . $client_id . '号","msg":"大家好,剪纸' . $client_id . '号来啦。"}');
             echo 'NAME IS come ';
             break;
             // 更新用户
         // 更新用户
         case 'POST':
             // 转播给所有用户
             echo 'POST IS IN';
             Gateway::sendToAll(json_encode(array('type' => 'POST', 'from' => $message_data['from'], 'msg' => $message_data['context'], 'head' => $message_data['head'])));
             return;
             // 聊天
         // 聊天
         case 'message':
             // 向大家说
             $new_message = array('type' => 'message', 'id' => $client_id, 'message' => $message_data['message']);
             return Gateway::sendToAll(json_encode($new_message));
     }
 }
コード例 #3
0
ファイル: Events.php プロジェクト: hugtale/think
 /**
  * 当用户断开连接时触发
  * @param int $client_id 连接id
  */
 public static function onClose($client_id)
 {
     // 向所有人发送
     GateWay::sendToAll("{$client_id} logout");
 }
コード例 #4
0
ファイル: Event.php プロジェクト: eseawind/qian_dao
 /**
  * 当用户断开连接时触发的方法
  * @param integer $client_id 断开连接的用户id
  * @return void
  */
 public static function onClose($client_id)
 {
     // 广播 xxx 退出了
     GateWay::sendToAll(TextProtocol::encode("{$_SESSION['name']}[{$client_id}] logout"));
 }
コード例 #5
0
 /**
  * 当用户断开连接时
  * @param integer $client_id 用户id
  */
 public static function onClose($client_id)
 {
     // 广播 xxx 退出了
     GateWay::sendToAll(json_encode(array('type' => 'closed', 'id' => $client_id)));
 }
コード例 #6
0
ファイル: Event.php プロジェクト: jzgenius/GatewayWorker
 /**
  * 当用户断开连接时触发
  * @param int $client_id 连接id
  */
 public static function onClose($client_id)
 {
     // 向所有人发送 @see http://gatewayworker-doc.workerman.net/gateway-worker-development/send-to-all.html
     GateWay::sendToAll("{$client_id} logout");
 }
コード例 #7
0
ファイル: Event.php プロジェクト: bennysuh/myself-wokerman
 /**
  * 有消息时触发该方法
  * @param int $uid 发消息的uid
  * @param string $message 消息
  * @return void
  */
 public static function onMessage($uid, $message)
 {
     $message_data = TextProtocol::decode($message);
     // 判断是否是私聊,私聊数据格式 uid:xxxxx
     $explode_array = explode(':', $message, 2);
     if (count($explode_array) > 1) {
         $to_uid = (int) $explode_array[0];
         GateWay::sendToUid($uid, TextProtocol::encode($_SESSION['name'] . "[{$uid}] said said to [{$to_uid}] :" . $explode_array[1]));
         return GateWay::sendToUid($to_uid, TextProtocol::encode($_SESSION['name'] . "[{$uid}] said to You :" . $explode_array[1]));
     }
     // 群聊
     return GateWay::sendToAll(TextProtocol::encode($_SESSION['name'] . "[{$uid}] said :" . $message));
 }