Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending notification to a specific user #10

Open
miranos opened this issue Jul 12, 2018 · 3 comments
Open

Sending notification to a specific user #10

miranos opened this issue Jul 12, 2018 · 3 comments

Comments

@miranos
Copy link

miranos commented Jul 12, 2018

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 !

@alcalyn
Copy link
Member

alcalyn commented Jul 13, 2018

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

@miranos
Copy link
Author

miranos commented Jul 15, 2018

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 ?

@miranos
Copy link
Author

miranos commented Jul 15, 2018

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);
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants