|
|
@@ -13,42 +13,24 @@ use \GatewayWorker\Lib\Gateway;
|
|
|
*/
|
|
|
class Events
|
|
|
{
|
|
|
- /**
|
|
|
- * 当客户端连接时触发
|
|
|
- * 如果业务不需此回调可以删除onConnect
|
|
|
- *
|
|
|
- * @param int $client_id 连接id
|
|
|
- */
|
|
|
+ // 当有客户端连接时,将client_id返回,让mvc框架判断当前uid并执行绑定
|
|
|
public static function onConnect($client_id)
|
|
|
{
|
|
|
- // 向当前client_id发送数据
|
|
|
- //Gateway::sendToClient($client_id, "Hello $client_id\r\n");
|
|
|
- // 向所有人发送
|
|
|
- //Gateway::sendToAll("$client_id login\r\n");
|
|
|
Gateway::sendToClient($client_id, json_encode(array(
|
|
|
- 'type' => 'init',
|
|
|
+ 'type' => 'init',
|
|
|
'client_id' => $client_id
|
|
|
)));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 当客户端发来消息时触发
|
|
|
- * @param int $client_id 连接id
|
|
|
- * @param mixed $message 具体消息
|
|
|
- */
|
|
|
+ // GatewayWorker建议不做任何业务逻辑,onMessage留空即可
|
|
|
public static function onMessage($client_id, $message)
|
|
|
{
|
|
|
- // 向所有人发送
|
|
|
- //Gateway::sendToAll("$client_id said $message\r\n");
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 当用户断开连接时触发
|
|
|
- * @param int $client_id 连接id
|
|
|
- */
|
|
|
+ }
|
|
|
+
|
|
|
+ //当用户断开连接时触发
|
|
|
public static function onClose($client_id)
|
|
|
{
|
|
|
- // 向所有人发送
|
|
|
- //GateWay::sendToAll("$client_id logout\r\n");
|
|
|
+
|
|
|
}
|
|
|
}
|