Allow missing user_info on presence channels
This commit is contained in:
parent
83830548fd
commit
8b15897f63
|
|
@ -86,12 +86,17 @@ class PresenceChannel extends Channel
|
||||||
return array_values($userIds);
|
return array_values($userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the hash for the presence channel integrity.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
protected function getHash(): array
|
protected function getHash(): array
|
||||||
{
|
{
|
||||||
$hash = [];
|
$hash = [];
|
||||||
|
|
||||||
foreach ($this->users as $socketId => $channelData) {
|
foreach ($this->users as $socketId => $channelData) {
|
||||||
$hash[$channelData->user_id] = $channelData->user_info;
|
$hash[$channelData->user_id] = $channelData->user_info ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $hash;
|
return $hash;
|
||||||
|
|
|
||||||
|
|
@ -59,4 +59,33 @@ class PresenceChannelTest extends TestCase
|
||||||
'channel' => 'presence-channel',
|
'channel' => 'presence-channel',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @test */
|
||||||
|
public function clients_with_no_user_info_can_join_presence_channels()
|
||||||
|
{
|
||||||
|
$connection = $this->getWebSocketConnection();
|
||||||
|
|
||||||
|
$this->pusherServer->onOpen($connection);
|
||||||
|
|
||||||
|
$channelData = [
|
||||||
|
'user_id' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
|
||||||
|
|
||||||
|
$message = new Message(json_encode([
|
||||||
|
'event' => 'pusher:subscribe',
|
||||||
|
'data' => [
|
||||||
|
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
|
||||||
|
'channel' => 'presence-channel',
|
||||||
|
'channel_data' => json_encode($channelData),
|
||||||
|
],
|
||||||
|
]));
|
||||||
|
|
||||||
|
$this->pusherServer->onMessage($connection, $message);
|
||||||
|
|
||||||
|
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
|
||||||
|
'channel' => 'presence-channel',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue