/**
  * Start transport provider
  *
  * @param \Thruway\Peer\AbstractPeer $peer
  * @param \React\EventLoop\LoopInterface $loop
  */
 public function startTransportProvider(AbstractPeer $peer, LoopInterface $loop)
 {
     Logger::info($this, "Starting Transport");
     $this->peer = $peer;
     $this->loop = $loop;
     $this->connector = new \Ratchet\Client\Factory($this->loop);
     $this->connector->__invoke($this->URL, ['wamp.2.json'])->then(function (WebSocket $conn) {
         Logger::info($this, "Pawl has connected");
         $transport = new PawlTransport($conn, $this->loop);
         $transport->setSerializer(new JsonSerializer());
         $transport->setTrusted($this->trusted);
         $this->peer->onOpen($transport);
         $conn->on('message', function ($msg) use($transport) {
             Logger::debug($this, "Received: {$msg}");
             try {
                 $this->peer->onMessage($transport, $transport->getSerializer()->deserialize($msg));
             } catch (DeserializationException $e) {
                 Logger::warning($this, "Deserialization exception occurred.");
             } catch (\Exception $e) {
                 Logger::warning($this, "Exception occurred during onMessage: " . $e->getMessage());
             }
         });
         $conn->on('close', function ($conn) {
             Logger::info($this, "Pawl has closed");
             $this->peer->onClose('close');
         });
         $conn->on('pong', function ($frame, $ws) use($transport) {
             $transport->onPong($frame, $ws);
         });
     }, function ($e) {
         $this->peer->onClose('unreachable');
         Logger::info($this, "Could not connect: {$e->getMessage()}");
         // $this->loop->stop();
     });
 }
 /**
  *
  */
 public function startTransportProvider(AbstractPeer $peer, LoopInterface $loop)
 {
     $this->manager->info("Starting Transport\n");
     $this->peer = $peer;
     $this->loop = $loop;
     $this->connector = new \Ratchet\Client\Factory($this->loop);
     $this->connector->__invoke($this->URL, ['wamp.2.json'])->then(function (WebSocket $conn) {
         $this->manager->info("Pawl has connected\n");
         $transport = new PawlTransport($conn, $this->loop);
         $transport->setSerializer(new JsonSerializer());
         $this->peer->onOpen($transport);
         $conn->on('message', function ($msg) use($transport) {
             $this->manager->info("Received: {$msg}\n");
             $this->peer->onMessage($transport, $transport->getSerializer()->deserialize($msg));
         });
         $conn->on('close', function ($conn) {
             $this->manager->info("Pawl has closed\n");
             $this->peer->onClose('close');
         });
         $conn->on('pong', function ($frame, $ws) use($transport) {
             $transport->onPong($frame, $ws);
         });
     }, function ($e) {
         $this->peer->onClose('unreachable');
         $this->manager->info("Could not connect: {$e->getMessage()}\n");
         // $this->loop->stop();
     });
 }
 /**
  * When a new connection is opened it will be passed to this method
  * @param  ConnectionInterface $conn The socket/connection that just connected to your application
  * @throws \Exception
  */
 function onOpen(ConnectionInterface $conn)
 {
     $this->manager->debug("RatchetTransportProvider::onOpen");
     $transport = new RatchetTransport($conn, $this->loop);
     // this will need to be a little more dynamic at some point
     $transport->setSerializer(new JsonSerializer());
     $this->transports->attach($conn, $transport);
     $this->peer->onOpen($transport);
     //        $session = new Session($conn);
     //
     //        $this->sessions->attach($conn, $session);
 }
 /**
  * Handle process on open new connection
  * 
  * @param \React\Stream\Stream $conn
  */
 public function handleConnection(Stream $conn)
 {
     //$this->getManager()->debug("Raw socket opened");
     $this->transport = new RawSocketTransport($conn, $this->loop, $this->peer);
     $this->transport->setSerializer(new JsonSerializer());
     $this->transport->setTrusted($this->trusted);
     $this->peer->onOpen($this->transport);
 }
 public function startTransportProvider(AbstractPeer $peer, LoopInterface $loop)
 {
     // the peer that is passed into here is the server that our internal client connects to
     $this->peer = $peer;
     // create a new transport for the router side to use
     $transport = new InternalClientTransport($this->internalClient, $loop);
     // create a new transport for the client side to use
     $clientTransport = new InternalClientTransport($this->peer, $loop);
     // give the transports each other because they are going to call directly into the
     // other side
     $transport->setFarPeerTransport($clientTransport);
     $clientTransport->setFarPeerTransport($transport);
     // connect the transport to the Router/Peer
     $this->peer->onOpen($transport);
     // open the client side
     $this->internalClient->onOpen($clientTransport);
     // tell the internal client to start up
     $this->internalClient->start();
 }
 /**
  * Handle process on open new connection
  *
  * @param \React\Socket\Connection $conn
  */
 public function handleConnection(Connection $conn)
 {
     Logger::debug($this, "Raw socket opened " . $conn->getRemoteAddress());
     $transport = new RawSocketTransport($conn, $this->loop, $this->peer);
     $this->transports->attach($conn, $transport);
     $transport->setSerializer(new JsonSerializer());
     $transport->setTrusted($this->trusted);
     $this->peer->onOpen($transport);
     $conn->on('data', [$this, "handleData"]);
     $conn->on('close', [$this, "handleClose"]);
 }