Pusher : -> .

This commit is contained in:
Blax Software 2025-01-18 17:06:52 +01:00
parent 929f1794ee
commit 87bf0ae05e
12 changed files with 31 additions and 27 deletions

View File

@ -14,7 +14,7 @@ class WebSocketException extends Exception
public function getPayload() public function getPayload()
{ {
return [ return [
'event' => 'pusher:error', 'event' => 'pusher.error',
'data' => [ 'data' => [
'message' => $this->getMessage(), 'message' => $this->getMessage(),
'code' => $this->getCode(), 'code' => $this->getCode(),

View File

@ -36,7 +36,7 @@ class PusherChannelProtocolMessage extends PusherClientMessage
$this->channelManager $this->channelManager
->connectionPonged($connection) ->connectionPonged($connection)
->then(function () use ($connection) { ->then(function () use ($connection) {
$connection->send(json_encode(['event' => 'pusher:pong'])); $connection->send(json_encode(['event' => 'pusher.pong']));
ConnectionPonged::dispatch($connection->app->id, $connection->socketId); ConnectionPonged::dispatch($connection->app->id, $connection->socketId);
}); });

View File

@ -273,7 +273,7 @@ class WebSocketHandler implements MessageComponentInterface
protected function establishConnection(ConnectionInterface $connection) protected function establishConnection(ConnectionInterface $connection)
{ {
$connection->send(json_encode([ $connection->send(json_encode([
'event' => 'pusher:connection_established', 'event' => 'pusher.connection_established',
'data' => json_encode([ 'data' => json_encode([
'socket_id' => $connection->socketId, 'socket_id' => $connection->socketId,
'activity_timeout' => 30, 'activity_timeout' => 30,

View File

@ -258,6 +258,10 @@ class Controller
{ {
$event = explode('.', $message['event']); $event = explode('.', $message['event']);
if (strpos($event[0], 'pusher.') > -1) {
$event = explode('.', $event[0]);
}
if (strpos($event[0], 'pusher:') > -1) { if (strpos($event[0], 'pusher:') > -1) {
$event = explode(':', $event[0]); $event = explode(':', $event[0]);
} }

View File

@ -321,7 +321,7 @@ class Handler implements MessageComponentInterface
protected function establishConnection(ConnectionInterface $connection) protected function establishConnection(ConnectionInterface $connection)
{ {
$connection->send(json_encode([ $connection->send(json_encode([
'event' => 'pusher:connection_established', 'event' => 'pusher.connection_established',
'data' => json_encode([ 'data' => json_encode([
'socket_id' => $connection->socketId, 'socket_id' => $connection->socketId,
'activity_timeout' => 30, 'activity_timeout' => 30,

View File

@ -11,7 +11,7 @@ class ConnectionTest extends TestCase
$this->startServer(); $this->startServer();
$response = $this->await($this->joinWebSocketServer(['public-channel'], 'NonWorkingKey')); $response = $this->await($this->joinWebSocketServer(['public-channel'], 'NonWorkingKey'));
$this->assertSame('{"event":"pusher:error","data":{"message":"Could not find app key `NonWorkingKey`.","code":4001}}', (string) $response); $this->assertSame('{"event":"pusher.error","data":{"message":"Could not find app key `NonWorkingKey`.","code":4001}}', (string) $response);
} }
public function test_unconnected_app_cannot_store_statistics() public function test_unconnected_app_cannot_store_statistics()
@ -19,7 +19,7 @@ class ConnectionTest extends TestCase
$this->startServer(); $this->startServer();
$response = $this->await($this->joinWebSocketServer(['public-channel'], 'NonWorkingKey')); $response = $this->await($this->joinWebSocketServer(['public-channel'], 'NonWorkingKey'));
$this->assertSame('{"event":"pusher:error","data":{"message":"Could not find app key `NonWorkingKey`.","code":4001}}', (string) $response); $this->assertSame('{"event":"pusher.error","data":{"message":"Could not find app key `NonWorkingKey`.","code":4001}}', (string) $response);
$count = $this->await($this->statisticsCollector->getStatistics()); $count = $this->await($this->statisticsCollector->getStatistics());
$this->assertCount(0, $count); $this->assertCount(0, $count);
@ -30,7 +30,7 @@ class ConnectionTest extends TestCase
$this->startServer(); $this->startServer();
$response = $this->await($this->joinWebSocketServer(['public-channel'], 'TestOrigin')); $response = $this->await($this->joinWebSocketServer(['public-channel'], 'TestOrigin'));
$this->assertSame('{"event":"pusher:error","data":{"message":"The origin is not allowed for `TestOrigin`.","code":4009}}', (string) $response); $this->assertSame('{"event":"pusher.error","data":{"message":"The origin is not allowed for `TestOrigin`.","code":4009}}', (string) $response);
} }
public function test_origin_validation_should_fail_for_wrong_origin() public function test_origin_validation_should_fail_for_wrong_origin()
@ -38,7 +38,7 @@ class ConnectionTest extends TestCase
$this->startServer(); $this->startServer();
$response = $this->await($this->joinWebSocketServer(['public-channel'], 'TestOrigin', ['Origin' => 'https://google.ro'])); $response = $this->await($this->joinWebSocketServer(['public-channel'], 'TestOrigin', ['Origin' => 'https://google.ro']));
$this->assertSame('{"event":"pusher:error","data":{"message":"The origin is not allowed for `TestOrigin`.","code":4009}}', (string) $response); $this->assertSame('{"event":"pusher.error","data":{"message":"The origin is not allowed for `TestOrigin`.","code":4009}}', (string) $response);
} }
public function test_origin_validation_should_pass_for_the_right_origin() public function test_origin_validation_should_pass_for_the_right_origin()
@ -47,7 +47,7 @@ class ConnectionTest extends TestCase
$this->pusherServer->onOpen($connection); $this->pusherServer->onOpen($connection);
$connection->assertSentEvent('pusher:connection_established'); $connection->assertSentEvent('pusher.connection_established');
} }
public function test_close_connection() public function test_close_connection()
@ -87,7 +87,7 @@ class ConnectionTest extends TestCase
$this->pusherServer->onError($connection, new UnknownAppKey('NonWorkingKey')); $this->pusherServer->onError($connection, new UnknownAppKey('NonWorkingKey'));
$connection->assertSentEvent('pusher:error', [ $connection->assertSentEvent('pusher.error', [
'data' => [ 'data' => [
'message' => 'Could not find app key `NonWorkingKey`.', 'message' => 'Could not find app key `NonWorkingKey`.',
'code' => 4001, 'code' => 4001,
@ -105,14 +105,14 @@ class ConnectionTest extends TestCase
$failedConnection = $this->newActiveConnection(['test-channel']); $failedConnection = $this->newActiveConnection(['test-channel']);
$failedConnection $failedConnection
->assertSentEvent('pusher:error', ['data' => ['message' => 'Over capacity', 'code' => 4100]]) ->assertSentEvent('pusher.error', ['data' => ['message' => 'Over capacity', 'code' => 4100]])
->assertClosed(); ->assertClosed();
} }
public function test_close_all_new_connections_after_stating_the_server_does_not_accept_new_connections() public function test_close_all_new_connections_after_stating_the_server_does_not_accept_new_connections()
{ {
$this->newActiveConnection(['test-channel']) $this->newActiveConnection(['test-channel'])
->assertSentEvent('pusher:connection_established') ->assertSentEvent('pusher.connection_established')
->assertSentEvent('pusher_internal:subscription_succeeded'); ->assertSentEvent('pusher_internal:subscription_succeeded');
$this->channelManager->declineNewConnections(); $this->channelManager->declineNewConnections();

View File

@ -32,7 +32,7 @@ class AuthTest extends TestCase
$this->pusherServer->onOpen($connection); $this->pusherServer->onOpen($connection);
$message = new SignedMessage([ $message = new SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => 'private-channel', 'channel' => 'private-channel',
], ],
@ -68,7 +68,7 @@ class AuthTest extends TestCase
]); ]);
$message = new SignedMessage([ $message = new SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => 'presence-channel', 'channel' => 'presence-channel',
'channel_data' => $user, 'channel_data' => $user,

View File

@ -8,10 +8,10 @@ class PingTest extends TestCase
{ {
$connection = $this->newActiveConnection(['public-channel']); $connection = $this->newActiveConnection(['public-channel']);
$message = new Mocks\Message(['event' => 'pusher:ping']); $message = new Mocks\Message(['event' => 'pusher.ping']);
$this->pusherServer->onMessage($connection, $message); $this->pusherServer->onMessage($connection, $message);
$connection->assertSentEvent('pusher:pong'); $connection->assertSentEvent('pusher.pong');
} }
} }

View File

@ -18,7 +18,7 @@ class PresenceChannelTest extends TestCase
$connection = $this->newConnection(); $connection = $this->newConnection();
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'auth' => 'invalid', 'auth' => 'invalid',
'channel' => 'presence-channel', 'channel' => 'presence-channel',
@ -45,7 +45,7 @@ class PresenceChannelTest extends TestCase
$encodedUser = json_encode($user); $encodedUser = json_encode($user);
$message = new Mocks\SignedMessage([ $message = new Mocks\SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => 'presence-channel', 'channel' => 'presence-channel',
'channel_data' => $encodedUser, 'channel_data' => $encodedUser,
@ -173,7 +173,7 @@ class PresenceChannelTest extends TestCase
}); });
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:unsubscribe', 'event' => 'pusher.unsubscribe',
'data' => [ 'data' => [
'channel' => 'presence-channel', 'channel' => 'presence-channel',
], ],

View File

@ -18,7 +18,7 @@ class PrivateChannelTest extends TestCase
$connection = $this->newConnection(); $connection = $this->newConnection();
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'auth' => 'invalid', 'auth' => 'invalid',
'channel' => 'private-channel', 'channel' => 'private-channel',
@ -36,7 +36,7 @@ class PrivateChannelTest extends TestCase
$this->pusherServer->onOpen($connection); $this->pusherServer->onOpen($connection);
$message = new Mocks\SignedMessage([ $message = new Mocks\SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => 'private-channel', 'channel' => 'private-channel',
], ],
@ -66,7 +66,7 @@ class PrivateChannelTest extends TestCase
}); });
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:unsubscribe', 'event' => 'pusher.unsubscribe',
'data' => [ 'data' => [
'channel' => 'private-channel', 'channel' => 'private-channel',
], ],

View File

@ -21,7 +21,7 @@ class PublicChannelTest extends TestCase
}); });
$connection->assertSentEvent( $connection->assertSentEvent(
'pusher:connection_established', 'pusher.connection_established',
[ [
'data' => json_encode([ 'data' => json_encode([
'socket_id' => $connection->socketId, 'socket_id' => $connection->socketId,
@ -47,7 +47,7 @@ class PublicChannelTest extends TestCase
}); });
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:unsubscribe', 'event' => 'pusher.unsubscribe',
'data' => [ 'data' => [
'channel' => 'public-channel', 'channel' => 'public-channel',
], ],

View File

@ -427,7 +427,7 @@ abstract class TestCase extends Orchestra
foreach ($channelsToJoin as $channel) { foreach ($channelsToJoin as $channel) {
$message = new Mocks\Message([ $message = new Mocks\Message([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => $channel, 'channel' => $channel,
], ],
@ -462,7 +462,7 @@ abstract class TestCase extends Orchestra
$encodedUser = json_encode($user); $encodedUser = json_encode($user);
$message = new Mocks\SignedMessage([ $message = new Mocks\SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => $channel, 'channel' => $channel,
'channel_data' => $encodedUser, 'channel_data' => $encodedUser,
@ -489,7 +489,7 @@ abstract class TestCase extends Orchestra
$this->pusherServer->onOpen($connection); $this->pusherServer->onOpen($connection);
$message = new Mocks\SignedMessage([ $message = new Mocks\SignedMessage([
'event' => 'pusher:subscribe', 'event' => 'pusher.subscribe',
'data' => [ 'data' => [
'channel' => $channel, 'channel' => $channel,
], ],