Beispiel #1
12
 /**
  * {@inheritdoc}
  */
 function onCall(ConnectionInterface $conn, $id, $fn, array $params)
 {
     switch ($fn) {
         case 'setName':
             break;
         case 'createRoom':
             $topic = $this->escape($params[0]);
             $created = false;
             if (empty($topic)) {
                 return $conn->callError($id, 'createRoom', 'Room name can not be empty');
             }
             if (array_key_exists($topic, $this->roomLookup)) {
                 $roomId = $this->roomLookup[$topic];
             } else {
                 $created = true;
                 $roomId = uniqid('room-');
                 $this->broadcast(static::CTRL_ROOMS, array($roomId, $topic, 1));
             }
             if ($created) {
                 $this->rooms[$roomId] = new \SplObjectStorage();
                 $this->roomLookup[$topic] = $roomId;
                 return $conn->callResult($id, array('id' => $roomId, 'display' => $topic));
             } else {
                 return $conn->callError($id, 'createRoom', "Room '{$topic}' exists", array('id' => $roomId, 'display' => $topic));
             }
             break;
         default:
             return $conn->callError($id, '', 'Unknown call');
             break;
     }
 }
 /**
  * Dispatches an event for the called RPC
  *
  * @param \Ratchet\ConnectionInterface $conn
  * @param string $id
  * @param string|\Ratchet\Wamp\Topic $topic
  * @param array $params
  */
 public function onCall(Conn $conn, $id, $topic, array $params)
 {
     $topicName = self::getTopicName($topic);
     $eventPayload = ['connection' => $conn, 'id' => $id, 'connectionData' => $this->_connections[$conn->WAMP->sessionId]];
     $event = $this->dispatchEvent('Rachet.WampServer.Rpc', $this, array_merge($eventPayload, ['topicName' => $topicName, 'topic' => $topic, 'params' => $params, 'wampServer' => $this]));
     if ($event->isStopped()) {
         $conn->callError($id, $event->result['stop_reason']['error_uri'], $event->result['stop_reason']['desc'], $event->result['stop_reason']['details']);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') was blocked');
         $this->dispatchEvent('Rachet.WampServer.RpcBlocked', $this, array_merge($eventPayload, ['topicName' => $topicName, 'reason' => $event->result['stop_reason']]));
         return false;
     }
     $start = microtime(true);
     $deferred = new \React\Promise\Deferred();
     $deferred->promise()->then(function ($results) use($conn, $id, $topicName, $start, $eventPayload) {
         $end = microtime(true);
         $conn->callResult($id, $results);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') took <info>' . ($end - $start) . 's</info> and succeeded');
         $this->dispatchEvent('Rachet.WampServer.RpcSuccess', $this, array_merge($eventPayload, ['topicName' => $topicName, 'results' => $results]));
     }, function ($errorUri, $desc = '', $details = null) use($conn, $id, $topicName, $start, $eventPayload) {
         $end = microtime(true);
         $conn->callError($id, $errorUri, $desc, $details);
         $this->outVerbose('Rachet.WampServer.Rpc.' . $topicName . ' call (' . $id . ') took <info>' . ($end - $start) . 's</info> and failed');
         $this->dispatchEvent('Rachet.WampServer.RpcFailed', $this, array_merge($eventPayload, ['topicName' => $topicName, 'reason' => [$errorUri, $desc, $details]]));
     });
     $this->dispatchEvent('Rachet.WampServer.Rpc.' . $topicName, $this, array_merge($eventPayload, ['promise' => $deferred, 'topic' => $topic, 'params' => $params, 'wampServer' => $this]));
 }
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     switch ($topic->getId()) {
         case "synchronize":
             $conn->callResult($id, $this->playerData);
             break;
         default:
             $conn->callError($id, $topic, 'You are not allowed to make calls')->close();
     }
     // In this application if clients send data it's because the user hacked around in console
 }
Beispiel #4
3
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     $roomId = $topic->getId();
     if (!array_key_exists($roomId, $this->rooms)) {
         $this->rooms[$roomId] = new \SplObjectStorage();
     }
     return $conn->callResult($id, array('id' => $roomId, 'display' => $topic));
 }
Beispiel #5
1
 /**
  * @param ConnectionInterface $conn
  * @param string $id
  * @param \Ratchet\Wamp\Topic|string $topic
  * @param array $params
  */
 public function onCall(ConnectionInterface $conn, $id, $topic, array $params)
 {
     if (isset($this->command[$topic->getId()])) {
         /** @var CommandInterface $command */
         $command = $this->command[$topic->getId()];
         $result = $command->run($this->node, $params);
         $conn->callResult($id, $result);
     }
     $conn->callError($id, $topic, ['error' => 'Invalid call']);
 }