WebSocketBundle icon indicating copy to clipboard operation
WebSocketBundle copied to clipboard

push function not property explained

Open thehatami opened this issue 5 years ago • 2 comments

need more explaine about "push" function. i cant undrestant this line

$pusher->push(['my_data' => 'data'], 'user_notification', ['username' => 'user1']);

please review the readme.md

thehatami avatar Mar 02 '19 23:03 thehatami

['my_data' => 'data'] = Payload user_notification = name of your PubSub route ['username' => 'user1'] = params for your PubSub route (if needed)

example:

Let's say i have app_topic_chat PubSub route in my yaml file:

app_topic_chat:
    channel: 'conversation/{conversationId}'
    handler:
        callback: 'conversation.topic'
    requirements:
        conversationId:
            pattern: '\d+'

My push action for that topic will be something like this:

$this->_pusher->push($payload, 'app_topic_chat', ['conversationId' => 1]);

If you use let's say ZMQ pusher then your topic MUST implement PushableTopicInterface

use Gos\Bundle\WebSocketBundle\Topic\PushableTopicInterface;

And that interface will force you to add new method in your topic handler

public function onPush(Topic $topic, $request, $payload, $provider)
{
      $topic->broadcast(json_encode($payload));
}

stipic avatar Mar 03 '19 20:03 stipic

thank you stipic. but by all this, i cant send a message to specific user and only receive default broadcast like

Received message 936 has left foor/bar

how can i sent msg from my controller to pusher?

i try (like this)

$pusher->push(['data' => 'data'], 'user_notification', ['conversationId' => 939]);

and i get

Library error: connection closed unexpectedly - Potential login failure.

thehatami avatar Mar 11 '19 07:03 thehatami