【发布时间】:2022-01-05 13:11:15
【问题描述】:
如果在用户聊天应用中消息是“从客户端”或“从任何其他用户”发送的,则以下方法 (check video at this Link) 以 php 形式描述。
public function onMessage(ConnectionInterface $from, $msg) {
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, o == 1 ? '' : 's');
$data=json_decode($msg,true);
foreach($this->$clients as $client){
if ($from == $client){
$data['from']='Me';
}else{
$data['from']=get_current_user_id();
}
$client->send(json_encode($data));
}
我想检测上述过程而不在 php 中调用这个函数。这是否可以通过 websockets 代码中的 javascript 来实现,例如在 package.json 文件中?
我想检测消息是从套接字发送还是从套接字接收,因为我必须根据发送消息的人(客户端用户或其他人)向左或向右排列它们。
提前感谢您的支持
J.
【问题讨论】: