Skip to content

Added Cluster Support #11

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

Merged
merged 1 commit into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ApiSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ public static function getVersion(string $version = ''): string
* @param string $appId
* @return string
*/
public static function createUrl(string $appId): string
public static function createUrl(string $appId, string $cluster = null): string
{
$query = [
'client' => 'api-clients/pusher (https://php-api-clients.org/clients/pusher)',
'protocol' => 7,
'version' => ApiSettings::getVersion(),
];

return 'wss://ws.pusherapp.com/app/' .
$host = ($cluster) ? "ws-{$cluster}.pusher.com" : 'ws.pusherapp.com';

return 'wss://'.$host.'/app/' .
$appId .
'?' . http_build_query($query)
;
Expand Down
4 changes: 2 additions & 2 deletions src/AsyncClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function __construct(Subject $client)
* @throws \InvalidArgumentException
* @return AsyncClient
*/
public static function create(LoopInterface $loop, string $app, Resolver $resolver = null): AsyncClient
public static function create(LoopInterface $loop, string $app, Resolver $resolver = null, $cluster = null): AsyncClient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line exceeds 120 characters; contains 124 characters

{
try {
Scheduler::setDefaultFactory(function () use ($loop) {
Expand All @@ -93,7 +93,7 @@ public static function create(LoopInterface $loop, string $app, Resolver $resolv
}

return new self(
WebSocket::createFactory(ApiSettings::createUrl($app), false, [], $loop, $resolver)
WebSocket::createFactory(ApiSettings::createUrl($app, $cluster), false, [], $loop, $resolver)
);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/ApiSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ public function testCreateUrl()
$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();

self::assertSame($expectedUrl, ApiSettings::createUrl('barBaz'));

$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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line exceeds 120 characters; contains 195 characters


self::assertSame($expectedUrl, ApiSettings::createUrl('barBaz','ap1'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No space found after comma in function call

}
}