How does Ratchet (socketo.me) stream users subordinate to a specific topic?
I followed the directions on the socketo.me ratchet website which has been fine so far. I'm interested in broadcasting to those users who subscribed to it, not everyone.
This code below and also here on their website confuses me.
<?php
use Ratchet\ConnectionInterface as Conn;
/**
* When a user publishes to a topic all clients who have subscribed
* to that topic will receive the message/event from the publisher
*/
class BasicPubSub implements Ratchet\Wamp\WampServerInterface {
public function onPublish(Conn $conn, $topic, $event, array $exclude, array $eligible) {
$topic->broadcast($event);
}
public function onCall(Conn $conn, $id, $topic, array $params) {
$conn->callError($id, $topic, 'RPC not supported on this demo');
}
// No need to anything, since WampServer adds and removes subscribers to Topics automatically
public function onSubscribe(Conn $conn, $topic) {}
public function onUnSubscribe(Conn $conn, $topic) {}
public function onOpen(Conn $conn) {}
public function onClose(Conn $conn) {}
public function onError(Conn $conn, \Exception $e) {}
}
This information is below on their website. I interpret that it should be integrated with public function onPublish
.
Events triggered by this component:
onPublish (ConnectionInterface $ conn, Topic $ topic, string $ event) - User publishes data to topic $. You must return the Event Command to the Connections that subscribed to the topic $
WAMP:
(string $ sessionId) - unique identifier provided to the client
(array $ subscriptions) - collection of topics the client has subscribed to
Shouldn't they be some code like the lines of this
class BasicPubSub implements Ratchet\Wamp\WampServerInterface {
public function onPublish(Conn $conn, $topic, $event, $sessionid, array $subscriptions, array $exclude, array $eligible) {
$topic->broadcast($subscriptions);
}
/** rest of code here */
}
Clearly what $subscriptions
will be populated sql query
to get the threads that the user has subscribed to based on $sessionid
and $topic->broadcast($subscriptions);
will pass that thread to individual subscribers. I don't see how this is done in the tutorial, it is clear that my interpretation is different. I need help!!!
source to share
No one has answered this question yet
Check out similar questions: