I have been following the directions on the website for socketo.me ratchet, Which has been perfectly fine so far. I am interested in broadcasting topics to users that only subscribed to it, and not everyone.
This code given below, and also here on their website is confusing 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 below on their website I am interpreting that it should be integrated with public function onPublish
.
Events triggered by this Component:
onPublish (ConnectionInterface $conn, Topic $topic, string $event) - The user publishes data to a $topic. You should in return an Event Command to Connections who have Subscribed to the $topic
WAMP:
(string $sessionId) - A unique ID given to the client
(array $subscriptions) - A collection of Topics the client has subscribed to
Shouldn't their be some code like along 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 $subscriptions
will be populated by an sql query
to retrieve the topics a user has subscribed to based on thier $sessionid
, and $topic->broadcast($subscriptions);
will broadcast the topic to individual users subscribed. I do not see where the tutorial is doing this, clearly my interpretation is different. I need Help!!!