Skip to content

Commit

Permalink
Drop pusher/pusher-php-server 4.x (#36528)
Browse files Browse the repository at this point in the history
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
GrahamCampbell and taylorotwell authored Mar 10, 2021
1 parent 1762bd9 commit e16f4b6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"phpunit/phpunit": "Required to use assertions and run tests (^9.4).",
"predis/predis": "Required to use the predis connector (^1.1.2).",
"psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0).",
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^5.0).",
"symfony/cache": "Required to PSR-6 cache bridge (^5.3).",
"symfony/filesystem": "Required to enable support for relative symbolic links (^5.3).",
"symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).",
Expand Down
41 changes: 7 additions & 34 deletions src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,46 +111,19 @@ public function broadcast(array $channels, $event, array $payload = [])
{
$socket = Arr::pull($payload, 'socket');

if ($this->pusherServerIsVersionFiveOrGreater()) {
$parameters = $socket !== null ? ['socket_id' => $socket] : [];

try {
$this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $parameters
);
} catch (ApiErrorException $e) {
throw new BroadcastException(
sprintf('Pusher error: %s.', $e->getMessage())
);
}
} else {
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);

if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
$parameters = $socket !== null ? ['socket_id' => $socket] : [];

try {
$this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $parameters
);
} catch (ApiErrorException $e) {
throw new BroadcastException(
! empty($response['body'])
? sprintf('Pusher error: %s.', $response['body'])
: 'Failed to connect to Pusher.'
sprintf('Pusher error: %s.', $e->getMessage())
);
}
}

/**
* Determine if the Pusher PHP server is version 5.0 or greater.
*
* @return bool
*/
protected function pusherServerIsVersionFiveOrGreater()
{
return class_exists(ApiErrorException::class);
}

/**
* Get the Pusher SDK instance.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Broadcasting/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
},
"suggest": {
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0)."
"pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^5.0)."
},
"config": {
"sort-packages": true
Expand Down

0 comments on commit e16f4b6

Please sign in to comment.