2023-09-27 17:54:21 +08:00
|
|
|
|
<?php
|
2023-10-21 11:56:43 +08:00
|
|
|
|
namespace app\common\service\workerim;
|
2023-09-27 17:54:21 +08:00
|
|
|
|
|
|
|
|
|
use GatewayClient\Gateway;
|
2023-10-21 11:56:43 +08:00
|
|
|
|
|
2023-09-27 17:54:21 +08:00
|
|
|
|
/**
|
|
|
|
|
* 主逻辑
|
|
|
|
|
* 主要是处理 onConnect onMessage onClose 三个方法
|
|
|
|
|
* onConnect 和 onClose 如果不需要可以不用实现并删除
|
|
|
|
|
*/
|
|
|
|
|
class Events
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// 当有客户端连接时,将client_id返回,让mvc框架判断当前uid并执行绑定
|
|
|
|
|
public static function onConnect($client_id): void
|
|
|
|
|
{
|
|
|
|
|
Gateway::sendToClient($client_id, json_encode(array(
|
|
|
|
|
'type' => 'init',
|
|
|
|
|
'client_id' => $client_id
|
|
|
|
|
)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GatewayWorker建议不做任何业务逻辑,onMessage留空即可
|
|
|
|
|
public static function onMessage($client_id, $message): void
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|