Skip to content

Commit 02b0979

Browse files
authored
Merge pull request #11 from robsonvn/master
Added Cluster Support
2 parents 918d7e1 + db0a238 commit 02b0979

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/ApiSettings.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ public static function getVersion(string $version = ''): string
3333
* @param string $appId
3434
* @return string
3535
*/
36-
public static function createUrl(string $appId): string
36+
public static function createUrl(string $appId, string $cluster = null): string
3737
{
3838
$query = [
3939
'client' => 'api-clients/pusher (https://php-api-clients.org/clients/pusher)',
4040
'protocol' => 7,
4141
'version' => ApiSettings::getVersion(),
4242
];
4343

44-
return 'wss://ws.pusherapp.com/app/' .
44+
$host = ($cluster) ? "ws-{$cluster}.pusher.com" : 'ws.pusherapp.com';
45+
46+
return 'wss://'.$host.'/app/' .
4547
$appId .
4648
'?' . http_build_query($query)
4749
;

src/AsyncClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function __construct(Subject $client)
8383
* @throws \InvalidArgumentException
8484
* @return AsyncClient
8585
*/
86-
public static function create(LoopInterface $loop, string $app, Resolver $resolver = null): AsyncClient
86+
public static function create(LoopInterface $loop, string $app, Resolver $resolver = null, $cluster = null): AsyncClient
8787
{
8888
try {
8989
Scheduler::setDefaultFactory(function () use ($loop) {
@@ -93,7 +93,7 @@ public static function create(LoopInterface $loop, string $app, Resolver $resolv
9393
}
9494

9595
return new self(
96-
WebSocket::createFactory(ApiSettings::createUrl($app), false, [], $loop, $resolver)
96+
WebSocket::createFactory(ApiSettings::createUrl($app, $cluster), false, [], $loop, $resolver)
9797
);
9898
}
9999

tests/ApiSettingsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,9 @@ public function testCreateUrl()
4343
$expectedUrl = 'wss://ws.pusherapp.com/app/barBaz?client=api-clients%2Fpusher+%28https%3A%2F%2Fphp-api-clients.org%2Fclients%2Fpusher%29&protocol=7&version=' . ApiSettings::getVersion();
4444

4545
self::assertSame($expectedUrl, ApiSettings::createUrl('barBaz'));
46+
47+
$expectedUrl = 'wss://ws-ap1.pusher.com/app/barBaz?client=api-clients%2Fpusher+%28https%3A%2F%2Fphp-api-clients.org%2Fclients%2Fpusher%29&protocol=7&version=' . ApiSettings::getVersion();
48+
49+
self::assertSame($expectedUrl, ApiSettings::createUrl('barBaz','ap1'));
4650
}
4751
}

0 commit comments

Comments
 (0)