Beispiel #1
0
 /**
  * Send Response
  *
  * @param \Illuminate\Http\Response $response
  * @param \Ratchet\ConnectionInterface $conntection
  * @param \Ratchet\Wamp\Topic $topic
  * @return void
  * @throws \CupOfTea\TwoStream\Exception\InvalidRecipientException
  */
 protected function send($response, Connection $connection, $topic)
 {
     if ($response == 404) {
         return;
     }
     $recipient = array_get($response, 'recipient', config('twostream.response.recipient'));
     $data = array_get($response, 'data', $response);
     if ($recipient == 'all') {
         $topic->broadcast($data);
     } elseif ($recipient == 'except') {
         foreach ($topic->getIterator() as $client) {
             if ($client->session != $connection->session) {
                 $client->event($topic->getId(), $data);
             }
         }
     } else {
         if ($recipient == 'requestee') {
             $recipient = $connection->session;
         }
         foreach ((array) $recipient as $recipient) {
             // TODO: if translateUserToSessionId ||
             if (WsSession::isValidId($recipient)) {
                 foreach ($topic->getIterator() as $client) {
                     if ($client->session == $recipient) {
                         $client->event($topic->getId(), $data);
                     }
                 }
             } else {
                 throw new InvalidRecipientException($recipient);
             }
         }
     }
 }