Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

fix presence channel unsubscribe notification #416

Closed
Closed
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
25 changes: 18 additions & 7 deletions src/WebSockets/Channels/PresenceChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@ public function unsubscribe(ConnectionInterface $connection)
return;
}

$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_removed',
'channel' => $this->channelName,
'data' => json_encode([
'user_id' => $this->users[$connection->socketId]->user_id,
]),
]);
$last_connection = true;
foreach ($this->users as $socketId => $channelData) {
if ($socketId !== $connection->socketId && $channelData->user_id === $this->users[$connection->socketId]->user_id) {
$last_connection = false;
break;
}
}

//fire the event only if is the user last connection
if ($last_connection) {
$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_removed',
'channel' => $this->channelName,
'data' => json_encode([
'user_id' => $this->users[$connection->socketId]->user_id,
]),
]);
}

unset($this->users[$connection->socketId]);
}
Expand Down