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

Commit a2dd552

Browse files
committed
Added missing logs
1 parent 2839d4c commit a2dd552

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

resources/views/dashboard.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ class="rounded-full px-3 py-1 inline-block text-sm"
420420
return 'bg-green-500 text-white';
421421
}
422422
423-
if (['replicator-subscribed', 'replicator-joined'].includes(log.type)) {
423+
if (['replicator-subscribed'].includes(log.type)) {
424424
return 'bg-green-700 text-white';
425425
}
426426
427-
if (['disconnection', 'occupied', 'replicator-unsubscribed', 'replicator-left'].includes(log.type)) {
427+
if (['disconnection', 'replicator-unsubscribed'].includes(log.type)) {
428428
return 'bg-red-700 text-white';
429429
}
430430

src/ChannelManagers/RedisChannelManager.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BeyondCode\LaravelWebSockets\ChannelManagers;
44

55
use BeyondCode\LaravelWebSockets\Channels\Channel;
6+
use BeyondCode\LaravelWebSockets\DashboardLogger;
67
use BeyondCode\LaravelWebSockets\Helpers;
78
use BeyondCode\LaravelWebSockets\Server\MockableConnection;
89
use Carbon\Carbon;
@@ -286,6 +287,13 @@ public function broadcastAcrossServers($appId, ?string $socketId, string $channe
286287
$payload->socketId = $socketId;
287288
$payload->serverId = $serverId ?: $this->getServerId();
288289

290+
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATION_MESSAGE_PUBLISHED, [
291+
'fromServerId' => $serverId,
292+
'fromSocketId' => $socketId,
293+
'channel' => $channel,
294+
'payload' => $payload,
295+
]);
296+
289297
return $this->publishClient
290298
->publish($this->getRedisKey($appId, $channel), json_encode($payload))
291299
->then(function () use ($appId, $socketId, $channel, $payload, $serverId) {
@@ -464,6 +472,14 @@ public function onMessage(string $redisChannel, string $payload)
464472
$socketId = $payload->socketId ?? null;
465473
$serverId = $payload->serverId ?? null;
466474

475+
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_MESSAGE_RECEIVED, [
476+
'fromServerId' => $serverId,
477+
'fromSocketId' => $socketId,
478+
'receiverServerId' => $this->getServerId(),
479+
'channel' => $channel,
480+
'payload' => $payload,
481+
]);
482+
467483
unset($payload->socketId);
468484
unset($payload->serverId);
469485
unset($payload->appId);
@@ -693,9 +709,14 @@ public function removeUserData($appId, string $channel = null, string $key): Pro
693709
*/
694710
public function subscribeToTopic($appId, string $channel = null): PromiseInterface
695711
{
696-
return $this->subscribeClient->subscribe(
697-
$this->getRedisKey($appId, $channel)
698-
);
712+
$topic = $this->getRedisKey($appId, $channel);
713+
714+
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_SUBSCRIBED, [
715+
'serverId' => $this->getServerId(),
716+
'pubsubTopic' => $topic,
717+
]);
718+
719+
return $this->subscribeClient->subscribe($topic);
699720
}
700721

701722
/**
@@ -707,9 +728,14 @@ public function subscribeToTopic($appId, string $channel = null): PromiseInterfa
707728
*/
708729
public function unsubscribeFromTopic($appId, string $channel = null): PromiseInterface
709730
{
710-
return $this->subscribeClient->unsubscribe(
711-
$this->getRedisKey($appId, $channel)
712-
);
731+
$topic = $this->getRedisKey($appId, $channel);
732+
733+
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_UNSUBSCRIBED, [
734+
'serverId' => $this->getServerId(),
735+
'pubsubTopic' => $topic,
736+
]);
737+
738+
return $this->subscribeClient->unsubscribe($topic);
713739
}
714740

715741
/**

src/DashboardLogger.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ class DashboardLogger
1212

1313
const TYPE_CONNECTED = 'connected';
1414

15-
const TYPE_OCCUPIED = 'occupied';
16-
1715
const TYPE_SUBSCRIBED = 'subscribed';
1816

1917
const TYPE_WS_MESSAGE = 'ws-message';
@@ -24,10 +22,6 @@ class DashboardLogger
2422

2523
const TYPE_REPLICATOR_UNSUBSCRIBED = 'replicator-unsubscribed';
2624

27-
const TYPE_REPLICATOR_JOINED_CHANNEL = 'replicator-joined';
28-
29-
const TYPE_REPLICATOR_LEFT_CHANNEL = 'replicator-left';
30-
3125
const TYPE_REPLICATOR_MESSAGE_PUBLISHED = 'replicator-message-published';
3226

3327
const TYPE_REPLICATOR_MESSAGE_RECEIVED = 'replicator-message-received';
@@ -40,14 +34,11 @@ class DashboardLogger
4034
public static $channels = [
4135
self::TYPE_DISCONNECTED,
4236
self::TYPE_CONNECTED,
43-
self::TYPE_OCCUPIED,
4437
self::TYPE_SUBSCRIBED,
4538
self::TYPE_WS_MESSAGE,
4639
self::TYPE_API_MESSAGE,
4740
self::TYPE_REPLICATOR_SUBSCRIBED,
4841
self::TYPE_REPLICATOR_UNSUBSCRIBED,
49-
self::TYPE_REPLICATOR_JOINED_CHANNEL,
50-
self::TYPE_REPLICATOR_LEFT_CHANNEL,
5142
self::TYPE_REPLICATOR_MESSAGE_PUBLISHED,
5243
self::TYPE_REPLICATOR_MESSAGE_RECEIVED,
5344
];
@@ -84,7 +75,7 @@ public static function log($appId, string $type, array $details = [])
8475

8576
if ($channel) {
8677
$channel->broadcastLocally(
87-
$appId, (object) $payload, true
78+
$appId, (object) $payload
8879
);
8980
}
9081

0 commit comments

Comments
 (0)