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

View File

@ -111,7 +111,7 @@ class Handler implements MessageComponentInterface
$channel = $this->handleChannelSubscriptions($message, $connection);
if (! $channel->hasConnection($connection) && (
if (! $channel->hasConnection($connection) && !(
$message['event'] !== 'pusher:unsubscribe'
&& $message['event'] !== 'pusher.unsubscribe'
)) {
@ -126,7 +126,7 @@ class Handler implements MessageComponentInterface
$this->authenticateConnection($connection, $channel, $message);
\Log::channel('websocket')->info('['.$connection->socketId.']@'.$channel->getName().' | ' . json_encode($message));
\Log::channel('websocket')->info('[' . $connection->socketId . ']@' . $channel->getName() . ' | ' . json_encode($message));
if (strpos($message['event'], 'pusher') !== false) {
return $connection->send(json_encode([
@ -374,13 +374,13 @@ class Handler implements MessageComponentInterface
);
}
protected function handleChannelSubscriptions($message, $connection) : ?Channel
protected function handleChannelSubscriptions($message, $connection): ?Channel
{
$channel = $this->get_connection_channel($connection, $message);
$channel_name = optional($channel)->getName();
$socket_id = $connection->socketId;
if(! $channel_name || ! $channel) {
if (! $channel_name || ! $channel) {
return null;
}
@ -408,7 +408,7 @@ class Handler implements MessageComponentInterface
);
if (! $channel->hasConnection($connection)) {
try{
try {
$channel->subscribe($connection, (object) $message);
} catch (\Throwable $e) {
return null;