/**
  * @param bool $profile
  *
  * @throws \React\Socket\ConnectionException
  */
 public function launch($host, $port, $profile)
 {
     $this->logger->info('Starting web socket');
     //In order to avoid circular reference
     $this->topicManager->setWampApplication($this->wampApplication);
     $stack = new Builder();
     $server = new Server($this->loop);
     $server->listen($port, $host);
     if (true === $profile) {
         $memoryUsagePeriodicTimer = new PeriodicMemoryUsage($this->logger);
         $this->periodicRegistry->addPeriodic($memoryUsagePeriodicTimer);
     }
     /** @var PeriodicInterface $periodic */
     foreach ($this->periodicRegistry->getPeriodics() as $periodic) {
         $this->loop->addPeriodicTimer($periodic->getTimeout(), [$periodic, 'tick']);
         $this->logger->info(sprintf('Register periodic callback %s, executed each %s seconds', $periodic instanceof ProxyInterface ? get_parent_class($periodic) : get_class($periodic), $periodic->getTimeout()));
     }
     $allowedOrigins = array_merge(array('localhost', '127.0.0.1'), $this->originRegistry->getOrigins());
     $stack->push('Ratchet\\Server\\IoServer', $server, $this->loop)->push('Ratchet\\Http\\HttpServer');
     if ($this->originCheck) {
         $stack->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\OriginCheck', $allowedOrigins, $this->eventDispatcher);
     }
     $stack->push('Ratchet\\WebSocket\\WsServer')->push('Gos\\Bundle\\WebSocketBundle\\Server\\App\\Stack\\WampConnectionPeriodicTimer', $this->loop)->push('Ratchet\\Session\\SessionProvider', $this->sessionHandler)->push('Ratchet\\Wamp\\WampServer', $this->topicManager);
     $app = $stack->resolve($this->wampApplication);
     //Push Transport Layer
     foreach ($this->serverPusherHandlerRegistry->getPushers() as $handler) {
         try {
             $handler->handle($this->loop, $this->wampApplication);
         } catch (\Exception $e) {
             $this->logger->error($e->getMessage(), ['code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'push_handler_name' => $handler->getName()]);
         }
     }
     /* Server Event Loop to add other services in the same loop. */
     $event = new ServerEvent($this->loop, $server);
     $this->eventDispatcher->dispatch(Events::SERVER_LAUNCHED, $event);
     $this->logger->info(sprintf('Launching %s on %s PID: %s', $this->getName(), $host . ':' . $port, getmypid()));
     $app->run();
 }
 public function testGetSubProtocolsReturnsArray()
 {
     $this->assertInternalType('array', $this->mngr->getSubProtocols());
 }
 public function testGetSubProtocolsBubbles()
 {
     $subs = array('hello', 'world');
     $app = $this->getMock('Ratchet\\Tests\\Wamp\\Stub\\WsWampServerInterface');
     $app->expects($this->once())->method('getSubProtocols')->will($this->returnValue($subs));
     $mngr = new TopicManager($app);
     $this->assertEquals($subs, $mngr->getSubProtocols());
 }
 /**
  * @param WampRequest  $request
  * @param array|string $data
  * @param string       $provider
  */
 public function onPush(WampRequest $request, $data, $provider)
 {
     $topic = $this->topicManager->getTopic($request->getMatched());
     $this->dispatch(self::PUSH, null, $topic, $request, $data, null, null, $provider);
 }