GeniusesOfSymfony / WebSocketBundle

:part_alternation_mark: Websocket server for Symfony applications (powered by Ratchet), includes a Autobahn.JS based JavaScript client
MIT License
609 stars 140 forks source link

ZMQ Pusher don't work with Secure interface #374

Closed stipic closed 5 years ago

stipic commented 5 years ago

Hi,

im using ZMQ pusher to push some data in my secured topic.

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

This is my topic handler secure method

public function secure(ConnectionInterface $connection = null, Topic $topic, WampRequest $request, $payload = null, $exclude = null, $eligible = null, $provider = null)
    {
        if(!$this->clientManipulator->getClient($connection) instanceof \App\Entity\User)
        {
            throw new FirewallRejectionException();
        }
    }

And when ZMQ push payload to topic program crash:

Argument 1 passed to Gos\Bundle\WebSocketBundle\Client\ClientManipulator::getClient() must implement interface Ratchet\ConnectionInterface, null gi  
  ven, called in xyz on line 55      

Line 55:

if(!$this->clientManipulator->getClient($connection) instanceof \App\Entity\User)

$this->clientManipulator is instanceof @gos_web_socket.websocket.client_manipulator

mbabker commented 5 years ago

Your issue is with the nullable $connection param. The ClientManipulator requires you pass a connection to it, but when pushing the connection isn't available.

You'll need to add a check in your secure() method to deal with a $connection === null scenario.

stipic commented 5 years ago

@mbabker thank you.