I presence subscription

This commit is contained in:
a6a2f5842 2025-09-18 15:56:13 +02:00
parent 32c628a936
commit 5284e7fd2f
2 changed files with 14 additions and 5 deletions

View File

@ -54,11 +54,16 @@ class OpenPresenceChannel extends Channel
*/ */
public function unsubscribe(ConnectionInterface $connection): PromiseInterface public function unsubscribe(ConnectionInterface $connection): PromiseInterface
{ {
\Log::channel('websocket')->info('Presence unsub');
$truth = parent::unsubscribe($connection); $truth = parent::unsubscribe($connection);
\Log::channel('websocket')->info('Presence unsub 1');
return $this->channelManager return $this->channelManager
->getLocalConnections() ->getLocalConnections()
->then(function ($connections) use ($connection) { ->then(function ($connections) use ($connection) {
\Log::channel('websocket')->info('Presence unsub 2 local conn');
$this->informPresence($connection, $connections, true); $this->informPresence($connection, $connections, true);
}) })
->then(function () use ($truth) { ->then(function () use ($truth) {
@ -78,13 +83,17 @@ class OpenPresenceChannel extends Channel
($isLeaving ? 'removed' : 'joined') => $connection->socketId, ($isLeaving ? 'removed' : 'joined') => $connection->socketId,
'total_count' => collect($connections) 'total_count' => collect($connections)
->filter(fn($conn) => ($conn->remoteAddress && $conn->remoteAddress != '127.0.0.1')) ->filter(fn($conn) => ($conn->remoteAddress && $conn->remoteAddress != '127.0.0.1'))
->filter(fn($conn) => $isLeaving ? $conn->socketId != $connection->socketId : true)
->count(), ->count(),
'sockets' => collect($connections) 'sockets' => collect($connections)
->filter(fn($conn) => ($conn->remoteAddress && $conn->remoteAddress != '127.0.0.1')) ->filter(fn($conn) => ($conn->remoteAddress && $conn->remoteAddress != '127.0.0.1'))
->filter(fn($conn) => $isLeaving ? $conn->socketId != $connection->socketId : true)
->pluck('socketId')->toArray(), ->pluck('socketId')->toArray(),
], ],
]; ];
if (!$isLeaving)
$connection->send(json_encode($memberAddedPayload));
if ($connection->remoteAddress && $connection->remoteAddress != '127.0.0.1') { if ($connection->remoteAddress && $connection->remoteAddress != '127.0.0.1') {
$this->broadcastToEveryoneExcept( $this->broadcastToEveryoneExcept(

View File

@ -111,7 +111,7 @@ class Handler implements MessageComponentInterface
$channel = $this->handleChannelSubscriptions($message, $connection); $channel = $this->handleChannelSubscriptions($message, $connection);
if (! $channel->hasConnection($connection) && ( if (! $channel->hasConnection($connection) && !(
$message['event'] !== 'pusher:unsubscribe' $message['event'] !== 'pusher:unsubscribe'
&& $message['event'] !== 'pusher.unsubscribe' && $message['event'] !== 'pusher.unsubscribe'
)) { )) {