I presence subscription
This commit is contained in:
parent
32c628a936
commit
5284e7fd2f
|
|
@ -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(
|
||||||
|
|
|
||||||
|
|
@ -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'
|
||||||
)) {
|
)) {
|
||||||
|
|
@ -126,7 +126,7 @@ class Handler implements MessageComponentInterface
|
||||||
|
|
||||||
$this->authenticateConnection($connection, $channel, $message);
|
$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) {
|
if (strpos($message['event'], 'pusher') !== false) {
|
||||||
return $connection->send(json_encode([
|
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 = $this->get_connection_channel($connection, $message);
|
||||||
$channel_name = optional($channel)->getName();
|
$channel_name = optional($channel)->getName();
|
||||||
$socket_id = $connection->socketId;
|
$socket_id = $connection->socketId;
|
||||||
|
|
||||||
if(! $channel_name || ! $channel) {
|
if (! $channel_name || ! $channel) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,7 +408,7 @@ class Handler implements MessageComponentInterface
|
||||||
);
|
);
|
||||||
|
|
||||||
if (! $channel->hasConnection($connection)) {
|
if (! $channel->hasConnection($connection)) {
|
||||||
try{
|
try {
|
||||||
$channel->subscribe($connection, (object) $message);
|
$channel->subscribe($connection, (object) $message);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue