Added missing logs

This commit is contained in:
Alex Renoki 2020-10-05 09:25:20 +03:00
parent 2839d4cbd8
commit a2dd552805
3 changed files with 35 additions and 18 deletions

View File

@ -420,11 +420,11 @@
return 'bg-green-500 text-white';
}
if (['replicator-subscribed', 'replicator-joined'].includes(log.type)) {
if (['replicator-subscribed'].includes(log.type)) {
return 'bg-green-700 text-white';
}
if (['disconnection', 'occupied', 'replicator-unsubscribed', 'replicator-left'].includes(log.type)) {
if (['disconnection', 'replicator-unsubscribed'].includes(log.type)) {
return 'bg-red-700 text-white';
}

View File

@ -3,6 +3,7 @@
namespace BeyondCode\LaravelWebSockets\ChannelManagers;
use BeyondCode\LaravelWebSockets\Channels\Channel;
use BeyondCode\LaravelWebSockets\DashboardLogger;
use BeyondCode\LaravelWebSockets\Helpers;
use BeyondCode\LaravelWebSockets\Server\MockableConnection;
use Carbon\Carbon;
@ -286,6 +287,13 @@ class RedisChannelManager extends LocalChannelManager
$payload->socketId = $socketId;
$payload->serverId = $serverId ?: $this->getServerId();
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATION_MESSAGE_PUBLISHED, [
'fromServerId' => $serverId,
'fromSocketId' => $socketId,
'channel' => $channel,
'payload' => $payload,
]);
return $this->publishClient
->publish($this->getRedisKey($appId, $channel), json_encode($payload))
->then(function () use ($appId, $socketId, $channel, $payload, $serverId) {
@ -464,6 +472,14 @@ class RedisChannelManager extends LocalChannelManager
$socketId = $payload->socketId ?? null;
$serverId = $payload->serverId ?? null;
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_MESSAGE_RECEIVED, [
'fromServerId' => $serverId,
'fromSocketId' => $socketId,
'receiverServerId' => $this->getServerId(),
'channel' => $channel,
'payload' => $payload,
]);
unset($payload->socketId);
unset($payload->serverId);
unset($payload->appId);
@ -693,9 +709,14 @@ class RedisChannelManager extends LocalChannelManager
*/
public function subscribeToTopic($appId, string $channel = null): PromiseInterface
{
return $this->subscribeClient->subscribe(
$this->getRedisKey($appId, $channel)
);
$topic = $this->getRedisKey($appId, $channel);
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_SUBSCRIBED, [
'serverId' => $this->getServerId(),
'pubsubTopic' => $topic,
]);
return $this->subscribeClient->subscribe($topic);
}
/**
@ -707,9 +728,14 @@ class RedisChannelManager extends LocalChannelManager
*/
public function unsubscribeFromTopic($appId, string $channel = null): PromiseInterface
{
return $this->subscribeClient->unsubscribe(
$this->getRedisKey($appId, $channel)
);
$topic = $this->getRedisKey($appId, $channel);
DashboardLogger::log($appId, DashboardLogger::TYPE_REPLICATOR_UNSUBSCRIBED, [
'serverId' => $this->getServerId(),
'pubsubTopic' => $topic,
]);
return $this->subscribeClient->unsubscribe($topic);
}
/**

View File

@ -12,8 +12,6 @@ class DashboardLogger
const TYPE_CONNECTED = 'connected';
const TYPE_OCCUPIED = 'occupied';
const TYPE_SUBSCRIBED = 'subscribed';
const TYPE_WS_MESSAGE = 'ws-message';
@ -24,10 +22,6 @@ class DashboardLogger
const TYPE_REPLICATOR_UNSUBSCRIBED = 'replicator-unsubscribed';
const TYPE_REPLICATOR_JOINED_CHANNEL = 'replicator-joined';
const TYPE_REPLICATOR_LEFT_CHANNEL = 'replicator-left';
const TYPE_REPLICATOR_MESSAGE_PUBLISHED = 'replicator-message-published';
const TYPE_REPLICATOR_MESSAGE_RECEIVED = 'replicator-message-received';
@ -40,14 +34,11 @@ class DashboardLogger
public static $channels = [
self::TYPE_DISCONNECTED,
self::TYPE_CONNECTED,
self::TYPE_OCCUPIED,
self::TYPE_SUBSCRIBED,
self::TYPE_WS_MESSAGE,
self::TYPE_API_MESSAGE,
self::TYPE_REPLICATOR_SUBSCRIBED,
self::TYPE_REPLICATOR_UNSUBSCRIBED,
self::TYPE_REPLICATOR_JOINED_CHANNEL,
self::TYPE_REPLICATOR_LEFT_CHANNEL,
self::TYPE_REPLICATOR_MESSAGE_PUBLISHED,
self::TYPE_REPLICATOR_MESSAGE_RECEIVED,
];
@ -84,7 +75,7 @@ class DashboardLogger
if ($channel) {
$channel->broadcastLocally(
$appId, (object) $payload, true
$appId, (object) $payload
);
}