diff --git a/src/Broadcasting/Broadcaster/ZmqBroadcaster.php b/src/Broadcasting/Broadcaster/ZmqBroadcaster.php index aa53121..bc99388 100644 --- a/src/Broadcasting/Broadcaster/ZmqBroadcaster.php +++ b/src/Broadcasting/Broadcaster/ZmqBroadcaster.php @@ -79,4 +79,22 @@ public function validAuthenticationResponse($request, $result) 'user_info' => $result, ]]); } + + /** + * Authenticate the incoming request for a given channel. + * Make this function available from external calls + * + * @param \Illuminate\Http\Request $request + * @param string $channel + * @return mixed + * + * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException + */ + public function verifyUserCanAccessChannel($request, $channelName) + { + return parent::verifyUserCanAccessChannel( + $request, + $channelName + ); + } } diff --git a/src/Connector/ZmqConnector.php b/src/Connector/ZmqConnector.php index 06c2b31..aa299f6 100644 --- a/src/Connector/ZmqConnector.php +++ b/src/Connector/ZmqConnector.php @@ -10,9 +10,15 @@ abstract class ZmqConnector { protected $connection; + /** + * @var \ZMQContext + */ + public $socket; + public function __construct($connection) { $this->connection = $connection; + $this->socket = $this->connect(); } /** @@ -20,6 +26,14 @@ public function __construct($connection) */ abstract public function connect(); + public function getSocket() + { + if(is_null($this->socket)) { + $this->socket = $this->connect(); + } + return $this->socket; + } + protected function dsn() { return \Config::get(sprintf('zmq.connections.%s.dsn', $this->connection), 'tcp://127.0.0.1:5555'); diff --git a/src/Connector/ZmqPublish.php b/src/Connector/ZmqPublish.php index 8005690..7ba355e 100644 --- a/src/Connector/ZmqPublish.php +++ b/src/Connector/ZmqPublish.php @@ -23,7 +23,7 @@ public function __construct($connection = 'publish') */ public function connect() { - $context = new \ZMQContext(); + $context = new \ZMQContext(1, true); $socket_method = \Config::get(sprintf('zmq.connections.%s.method', $this->connection), \ZMQ::SOCKET_PUB); $socket = $context->getSocket($socket_method); $socket->connect($this->dsn()); diff --git a/src/Zmq.php b/src/Zmq.php index 4f47353..652f613 100644 --- a/src/Zmq.php +++ b/src/Zmq.php @@ -33,12 +33,11 @@ public function __construct(array $connections = []) */ public function connection($connection = null) { - if (! $connection) { $connection = \Config::get('zmq.default'); } - return \App::make(sprintf('zmq.connection.%s', $connection))->connect(); + return \App::make(sprintf('zmq.connection.%s', $connection))->socket; } /**