I have just made a chat hello world for the Ratchet WAMP + autobahn version 1.
full source code here if you want to see
The JavaScript client send chat message:
function click_send_btn() { var json_data = { "message": $.trim($("#input_message").val()) }; sess.publish("send_message", json_data, true); }
The PHP Ratchet server publish the message:
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"; }
I don't understand why publish with excludeme not working.
In the above 2 firefox, right firefox said: I am bar. The message should not display at himself, but it is.
doc ref: autobahn version 1 javascript publish with excludeme