Hello,
I use for two months ratchet websocket...with session provider and everything (I already have 10 topics). In this moment I use it just for notifications and some javascript live changes! and to count online users by session and cookie etc....
But now I wan't to develop a private chat like user to user.I checked again the documentation and I don't know how to combine this two functionalities.
I.
$numRecv = count($this->clients) - 1;
echo sprintf('Connection %d sending message "%s" to %d other connection%s' . "\n"
, $from->resourceId, $msg, $numRecv, $numRecv == 1 ? '' : 's');
foreach ($this->clients as $client) {
if ($from !== $client) {
// The sender is not the receiver, send to each client connected
$client->send($msg);
}
}
II.
$entryData = json_decode($entry, true);
// If the lookup topic object isn't set there is no one to publish to
if (!array_key_exists($entryData['category'], $this->subscribedTopics)) {
return;
}
$topic = $this->subscribedTopics[$entryData['category']];
// re-send the data to all the clients subscribed to that category
$topic->broadcast($entryData);
How do I combine I with II ? (when i use conn.send i get disconnected from the server with "undefined" message and need to refresh )
I was thinking to make foreach user a topic! and send the messages to that topic ! But if one user its a little smarter he will send in console
conn.subscribe('User2', function(topic, data) {
console.log(data);
});