Repository navigation
Migrate from ably/ably-php to ably/pubsub-server #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,9 @@ | |
|
|
||
| namespace Ably\LaravelBroadcaster; | ||
|
|
||
| use Ably\AblyRest; | ||
| use Ably\Exceptions\AblyException; | ||
| use Ably\Models\Message as AblyMessage; | ||
| use Ably\PubSub\Exceptions\AblyException; | ||
| use Ably\PubSub\Models\Message as AblyMessage; | ||
| use Ably\PubSub\PubSubHttpClient; | ||
| use Illuminate\Broadcasting\Broadcasters\Broadcaster; | ||
| use Illuminate\Broadcasting\BroadcastException; | ||
| use Illuminate\Support\Facades\Cache; | ||
|
|
@@ -17,9 +17,9 @@ class AblyBroadcaster extends Broadcaster | |
| const LIB_VERSION = '1.0.8'; | ||
|
|
||
| /** | ||
| * The AblyRest SDK instance. | ||
| * The Ably Pub/Sub HTTP (REST) client, created with \Ably\PubSub\Server::createHttpClient(). | ||
| * | ||
| * @var \Ably\AblyRest | ||
| * @var \Ably\PubSub\PubSubHttpClient | ||
| */ | ||
| protected $ably; | ||
|
|
||
|
|
@@ -51,12 +51,23 @@ class AblyBroadcaster extends Broadcaster | |
| /** | ||
| * Create a new broadcaster instance. | ||
| * | ||
| * @param \Ably\AblyRest $ably | ||
| * @param \Ably\PubSub\PubSubHttpClient $ably Build it with \Ably\PubSub\Server::createHttpClient() | ||
| * @param array $config | ||
| * @return void | ||
| * | ||
| * @throws \InvalidArgumentException if $ably is not a \Ably\PubSub\PubSubHttpClient | ||
| */ | ||
| public function __construct(AblyRest $ably, $config) | ||
| public function __construct($ably, $config) | ||
| { | ||
| if (! $ably instanceof PubSubHttpClient) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reject Pub/Sub clients that lack the server agent. If a caller passes
|
||
| throw new \InvalidArgumentException(sprintf( | ||
| 'AblyBroadcaster expects an %s created with Ably\PubSub\Server::createHttpClient(), %s given. ' | ||
| .'See "Upgrading to 1.1" in the ably/laravel-broadcaster README.', | ||
| PubSubHttpClient::class, | ||
| get_debug_type($ably) | ||
| )); | ||
| } | ||
|
|
||
| $this->ably = $ably; | ||
|
|
||
| if (array_key_exists('sync_server_time', $config) && $config['sync_server_time']) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?php | ||
|
|
||
| namespace Ably\LaravelBroadcaster; | ||
|
|
||
| use Ably\PubSub\PubSubHttpClient; | ||
| use Ably\PubSub\Server; | ||
|
|
||
| /** | ||
| * Builds the Ably REST client used by the broadcaster from the `ably` | ||
| * connection array in config/broadcasting.php. | ||
| * | ||
| * @internal Not part of the package API; use the `ably` broadcast driver, | ||
| * or \Ably\PubSub\Server::createHttpClient() directly. | ||
| */ | ||
| final class AblyClientFactory | ||
| { | ||
| private function __construct() | ||
| { | ||
| } | ||
|
|
||
| /** | ||
| * Creates a client declaring the server side (Ably-Agent: … ably-pubsub-server). | ||
| */ | ||
| public static function make(array $config): PubSubHttpClient | ||
| { | ||
| return Server::createHttpClient(self::clientOptions($config)); | ||
| } | ||
|
|
||
| /** | ||
| * The client options array derived from the broadcasting config. | ||
| */ | ||
| public static function clientOptions(array $config): array | ||
| { | ||
| // Only our own registered identifier. A user-supplied `agents` value is | ||
| // overwritten, exactly as 1.x ignored it (1.x had no `agents` option). | ||
| $config['agents'] = ['laravel-broadcaster' => AblyBroadcaster::LIB_VERSION]; | ||
|
|
||
| return $config; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Account for the request timeout in queue-job guidance.
If a host accepts a connection but does not respond, the SDK can spend its default 10-second request timeout on each attempt. With three fallback retries, a publish can take about 40 seconds, not 16 seconds. State both timeout cases so operators do not set queue-job timeouts from the lower estimate. (raw.githubusercontent.com)