Merge pull request #457 from beyondcode/fix/allow-missing-user-info-on-presence-channels
[fix] Allow missing user_info on Presence channels
This commit is contained in:
commit
bce93adc00
|
|
@ -86,12 +86,17 @@ class PresenceChannel extends Channel
|
|||
return array_values($userIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the hash for the presence channel integrity.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getHash(): array
|
||||
{
|
||||
$hash = [];
|
||||
|
||||
foreach ($this->users as $socketId => $channelData) {
|
||||
$hash[$channelData->user_id] = $channelData->user_info;
|
||||
$hash[$channelData->user_id] = $channelData->user_info ?? [];
|
||||
}
|
||||
|
||||
return $hash;
|
||||
|
|
|
|||
|
|
@ -59,4 +59,33 @@ class PresenceChannelTest extends TestCase
|
|||
'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