在thinkphp 5 里如何使用 SocketIO 呢? Workerman version:4.0.6
主要想實現(xiàn)電腦端客服在線長連接,手機端用戶發(fā)表問題,存入數(shù)據(jù)庫后會分配一個客服ID,這個客服ID,在客服登錄的時候已經(jīng)和后端握手了,發(fā)送的時候發(fā)送的時候會提示 Call to a member function emit() on null,不知道如何記錄客服的ID,判斷客服是不是在線對指定客服進行消息推送,可是推送會報錯 Call to a member function emit() on null?
$inner_http_worker->onMessage = function ($http_connection, $data) use ( $sender_io) {
global $uidConnectionMap;
global $socket;
global $sender_io;
$to = $data->post('to');
$res=json_decode($data->post('content'),true);
// 有指定uid則向uid所在socket組發(fā)送數(shù)據(jù)
if($to){
$sender_io->to($to)->emit('kline', $res);
// 否則向所有uid推送數(shù)據(jù)
}else{
$sender_io->emit('kline', $res);
}
if(!$data->post('msg')) {
$rb=input('param.');
$rc=input('');
$http_connection->send('fail, $_GET["msg"] not found!!rb:');
}
$http_connection->send('ok');
};
我是按照文檔來的,部分參考了一下論壇的其他帖子,但是報錯!Call to a member function emit() on null ?? chuxian出現(xiàn)問題的地方在 $sender_io->to($to)->emit('kline', $res);附近