Skip to content
This repository has been archived by the owner on Mar 6, 2019. It is now read-only.

Commit

Permalink
Response fix
Browse files Browse the repository at this point in the history
  • Loading branch information
CupOfTea696 committed May 5, 2015
1 parent f206281 commit 03f8a4d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Server/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function onUnSubscribe(Connection $connection, $topic)
*
* @param string $message
* @return void
* @throws \CupOfTea\TwoStream\Exception\InvalidRecipientException
*/
public function push($message){
$message = json_decode($message, true);
Expand Down Expand Up @@ -166,16 +167,18 @@ protected function handle(Connection $connection, $request)
* @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->getStatusCode() == 404 || !$content = $response->getContent())
return;

$content = (array) json_decode($content, true);
$recipient = array_get($content, 'recipient', config('twostream.request.recipient'));
$data = array_get($content, 'data', count($content) ? $content : $content[0]);
$topic->broadcast($data);
$json = json_decode($content, true);
if(json_last_error() == JSON_ERROR_NONE)
$content = (array) $json;
$recipient = array_get($content, 'recipient', config('twostream.response.recipient'));
$data = array_get($content, 'data', $content);

if ($recipient == 'all') {
$topic->broadcast($data);
Expand Down

0 comments on commit 03f8a4d

Please sign in to comment.