我正在将此package用于聊天应用程序。我面临获取在线用户列表的问题。我尝试过的人提出了一种建议,但没有成功。
下面用于获取在线用户列表的代码。
/**
* Subscribe to messages
*
* @param ConnectionInterface $client
* @param string $msg
*/
public function commandSubscribe(ConnectionInterface $client, $msg)
{
$request = @json_decode($msg, true);
$client->talkId = $request['talk_id'] ?? null;
$client->userId = $request['user_id'] ?? null;
$this->clients = $client;
foreach ($this->clients as $key=>$chatClient) {
$onlineUsers[] = $chatClient->name;
}
$client->send( json_encode(['onlineUsers'=> $onlineUsers, 'room'=>$client->talkId, 'user' =>$client->userId ,'message'=> 'User added to room']) );
}
我得到以下答复:
响应:{“ onlineUsers”:{},“房间”:“提供者”,“用户”:“ hassan”,“消息”:“用户添加到房间”}