Websocket Ratchet WAMP onpublish始终发布到所有客户端,是否包括发布调用方?
我刚刚为Ratchet WAMP+autobahn版本1创建了一个hello world聊天室。Websocket Ratchet WAMP onpublish始终发布到所有客户端,是否包括发布调用方?,websocket,autobahn,ratchet,autobahnws,Websocket,Autobahn,Ratchet,Autobahnws,我刚刚为Ratchet WAMP+autobahn版本1创建了一个hello world聊天室。 JavaScript客户端发送聊天消息: PHP Ratchet服务器发布消息: 我不明白为什么使用excludeme发布不起作用。 在上面的2个firefox中,右firefox说:我是bar。消息不应该显示在他自己身上,但它是 我刚刚修好了。 我真是个傻瓜。我没有处理参数“array$exclude” 我还使用$topic->broadcast($event)强制向所有人广播。 现在我创
JavaScript客户端发送聊天消息: PHP Ratchet服务器发布消息: 我不明白为什么使用excludeme发布不起作用。
在上面的2个firefox中,右firefox说:我是bar。消息不应该显示在他自己身上,但它是 我刚刚修好了。
我真是个傻瓜。我没有处理参数“array$exclude”
我还使用$topic->broadcast($event)强制向所有人广播。
现在我创建一个函数 在onPublish中,我不再使用$topic->broadcast($event) 连接类有一个“偶数”方法,可以直接向“订户”发送消息。
Ratchet可能不支持该选项。顺便说一句:高速公路+横杆有什么问题吗?你好,奥伯斯特先生,我还没有试过,明天再试。谢谢。哈哈,也许你还记得我在另一篇关于PHP服务器RPC的文章中。。。。。无论如何,如果不局限于PHP,您可以建议哪台服务器最适合Crossbar?将有一个WAMP服务器项目?哦,我刚刚发现您的示例现在Crossbar支持多种语言来创建应用程序组件:。您上面链接的代码示例是为那些想要实现自己的路由器的人准备的,您不需要(因为有Crossbar)。可能还不够清楚:除了Crossbar之外,您不需要另一台“服务器”。Crossbar将托管(并监控)您的应用程序组件,并直接服务于客户端(对于WebSocket,以及静态Web资产,如果您愿意的话)。
function click_send_btn() {
var json_data = {
"message": $.trim($("#input_message").val())
};
sess.publish("send_message", json_data, true);
}
public function onPublish(\Ratchet\ConnectionInterface $conn, $topic, $event, array $exclude, array $eligible) {
switch ($topic) {
case 'http://localhost/enter_room':
$foundChater = $this->allChater[$conn];
$newChaterName = $event['username'];
$foundChater->setChatName($newChaterName);
break;
case 'send_message':
$foundChater = $this->allChater[$conn];
$event['username']=$foundChater->getChatName();
break;
}
$topic->broadcast($event);
echo "onPublish {$conn->resourceId}\n";
}
/**
* check whitelist and blacklist
*
* @param array of sessionId $exclude -- blacklist
* @param array of sessionId $eligible -- whitelist
* @return array of \Ratchet\ConnectionInterface
*/
private function getPublishFinalList(array $exclude, array $eligible) {
//array of sessionId
$allSessionId = array();
$this->allChater->rewind();
while ($this->allChater->valid()) {
array_push($allSessionId, $this->allChater->current()->WAMP->sessionId);
$this->allChater->next();
}
//if whitelist exist, use whitelist to filter
if (count($eligible) > 0) {
$allSessionId = array_intersect($allSessionId, $eligible);
}
//then if blacklist exist, use blacklist to filter
if (count($exclude) > 0) {
$allSessionId = array_diff($allSessionId, $exclude);
}
//return array of connection
$result = array();
$this->allChater->rewind();
while ($this->allChater->valid()) {
$currentConn = $this->allChater->current();
if (in_array($currentConn->WAMP->sessionId, $allSessionId)) {
array_push($result, $currentConn);
}
$this->allChater->next();
}
return $result;
}
$conn2PublishArray = $this->getPublishFinalList($exclude, $eligible);
foreach ($conn2PublishArray as $conn2Publish) {
$conn2Publish->event($topic, $new_event);
}