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

Commit 4c23363

Browse files
committed
wip dashboard logger
1 parent 5997dd4 commit 4c23363

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

resources/views/dashboard.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@
207207
'subscribed',
208208
'client-message',
209209
'api-message',
210+
'replicator-subscribed',
211+
'replicator-unsubscribed',
210212
].forEach(channelName => this.subscribeToChannel(channelName))
211213
},
212214

src/Dashboard/DashboardLogger.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@
99
class DashboardLogger
1010
{
1111
const LOG_CHANNEL_PREFIX = 'private-websockets-dashboard-';
12+
1213
const TYPE_DISCONNECTION = 'disconnection';
14+
1315
const TYPE_CONNECTION = 'connection';
16+
1417
const TYPE_VACATED = 'vacated';
18+
1519
const TYPE_OCCUPIED = 'occupied';
20+
1621
const TYPE_SUBSCRIBED = 'subscribed';
22+
1723
const TYPE_CLIENT_MESSAGE = 'client-message';
24+
1825
const TYPE_API_MESSAGE = 'api-message';
1926

27+
const TYPE_REPLICATOR_SUBSCRIBED = 'replicator-subscribed';
28+
29+
const TYPE_REPLICATOR_UNSUBSCRIBED = 'replicator-unsubscribed';
30+
2031
public static function connection(ConnectionInterface $connection)
2132
{
2233
/** @var \GuzzleHttp\Psr7\Request $request */
@@ -74,6 +85,20 @@ public static function apiMessage($appId, string $channel, string $event, string
7485
]);
7586
}
7687

88+
public static function replicatorSubscribed(string $appId, string $channel, string $serverId)
89+
{
90+
static::log($appId, static::TYPE_REPLICATOR_SUBSCRIBED, [
91+
'details' => "Server ID: {$serverId} on Channel: {$channel}",
92+
]);
93+
}
94+
95+
public static function replicatorUnsubscribed(string $appId, string $channel, string $serverId)
96+
{
97+
static::log($appId, static::TYPE_REPLICATOR_UNSUBSCRIBED, [
98+
'details' => "Server ID: {$serverId} on Channel: {$channel}",
99+
]);
100+
}
101+
77102
public static function log($appId, string $type, array $attributes = [])
78103
{
79104
$channelName = static::LOG_CHANNEL_PREFIX.$type;

src/HttpApi/Controllers/FetchChannelsController.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Http\Request;
99
use Illuminate\Support\Collection;
1010
use Illuminate\Support\Str;
11+
use stdClass;
1112
use Symfony\Component\HttpKernel\Exception\HttpException;
1213

1314
class FetchChannelsController extends Controller
@@ -54,15 +55,18 @@ public function __invoke(Request $request)
5455
return $this->replicator
5556
->channelMemberCounts($request->appId, $channelNames)
5657
->then(function (array $counts) use ($channels, $attributes) {
57-
return [
58-
'channels' => $channels->map(function (PresenceChannel $channel) use ($counts, $attributes) {
59-
$info = new \stdClass;
60-
if (in_array('user_count', $attributes)) {
61-
$info->user_count = $counts[$channel->getChannelName()];
62-
}
58+
$channels = $channels->map(function (PresenceChannel $channel) use ($counts, $attributes) {
59+
$info = new stdClass;
60+
61+
if (in_array('user_count', $attributes)) {
62+
$info->user_count = $counts[$channel->getChannelName()];
63+
}
6364

64-
return $info;
65-
})->toArray() ?: new \stdClass,
65+
return $info;
66+
})->toArray();
67+
68+
return [
69+
'channels' => $channels ?: new stdClass,
6670
];
6771
});
6872
}

src/PubSub/Drivers/RedisClient.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BeyondCode\LaravelWebSockets\PubSub\Drivers;
44

5+
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
56
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
67
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
78
use Clue\React\Redis\Client;
@@ -139,6 +140,8 @@ public function subscribe(string $appId, string $channel): bool
139140
$this->subscribedChannels["$appId:$channel"]++;
140141
}
141142

143+
DashboardLogger::replicatorSubscribed($appId, $channel, $this->serverId);
144+
142145
return true;
143146
}
144147

@@ -161,9 +164,12 @@ public function unsubscribe(string $appId, string $channel): bool
161164
// If we no longer have subscriptions to that channel, unsubscribe
162165
if ($this->subscribedChannels["$appId:$channel"] < 1) {
163166
$this->subscribeClient->__call('unsubscribe', ["$appId:$channel"]);
167+
164168
unset($this->subscribedChannels["$appId:$channel"]);
165169
}
166170

171+
DashboardLogger::replicatorUnsubscribed($appId, $channel, $this->serverId);
172+
167173
return true;
168174
}
169175

0 commit comments

Comments
 (0)