eole-io/sandstone

Sending notification to a specific user

Opened this issue · 3 comments

Hi,

I sorry again to disturb you !

Is there a way to send notification to a specific user in order to inform him about a change occured in the database for example, or new entries by other users ? Or even from cronjob ?

Thank's in advance !

Hello,

I didn't need this for now, I usually create topic for any "group" of message, even if only one user listen to a topic.

But if you need to be sure that your user has a specific role "like admin" to be allowed to listen and receive messages from a topic, you can access to logged in user with $conn->user, I am using it here: https://github.com/eole-io/eole-api/blob/a5b15265109ff25298d3101eea01f7e89f27e523/src/Eole/Websocket/Topic/ChatTopic.php#L26-L33

But my bad, there is some missing doc about it

First thank's again for your answer !

But i need a pusher to send notification for a specific client and this depend on the user IP or session id if possible ?

Here is an example used on ratchet:

$json =  (json_decode($msg,true)); // {"userID":"#", "sendTo":"#", "message":"lorem"}
$msg = $json['message'];
$tosendid = $json['sendTo'];
foreach ($this->clients as $client) {
   if ($tosendid == $client->resourceId) {
                $client->send($msg);
   }
}