wip dashboard logger
This commit is contained in:
parent
5997dd4df8
commit
4c23363c14
|
|
@ -207,6 +207,8 @@
|
||||||
'subscribed',
|
'subscribed',
|
||||||
'client-message',
|
'client-message',
|
||||||
'api-message',
|
'api-message',
|
||||||
|
'replicator-subscribed',
|
||||||
|
'replicator-unsubscribed',
|
||||||
].forEach(channelName => this.subscribeToChannel(channelName))
|
].forEach(channelName => this.subscribeToChannel(channelName))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,14 +9,25 @@ use stdClass;
|
||||||
class DashboardLogger
|
class DashboardLogger
|
||||||
{
|
{
|
||||||
const LOG_CHANNEL_PREFIX = 'private-websockets-dashboard-';
|
const LOG_CHANNEL_PREFIX = 'private-websockets-dashboard-';
|
||||||
|
|
||||||
const TYPE_DISCONNECTION = 'disconnection';
|
const TYPE_DISCONNECTION = 'disconnection';
|
||||||
|
|
||||||
const TYPE_CONNECTION = 'connection';
|
const TYPE_CONNECTION = 'connection';
|
||||||
|
|
||||||
const TYPE_VACATED = 'vacated';
|
const TYPE_VACATED = 'vacated';
|
||||||
|
|
||||||
const TYPE_OCCUPIED = 'occupied';
|
const TYPE_OCCUPIED = 'occupied';
|
||||||
|
|
||||||
const TYPE_SUBSCRIBED = 'subscribed';
|
const TYPE_SUBSCRIBED = 'subscribed';
|
||||||
|
|
||||||
const TYPE_CLIENT_MESSAGE = 'client-message';
|
const TYPE_CLIENT_MESSAGE = 'client-message';
|
||||||
|
|
||||||
const TYPE_API_MESSAGE = 'api-message';
|
const TYPE_API_MESSAGE = 'api-message';
|
||||||
|
|
||||||
|
const TYPE_REPLICATOR_SUBSCRIBED = 'replicator-subscribed';
|
||||||
|
|
||||||
|
const TYPE_REPLICATOR_UNSUBSCRIBED = 'replicator-unsubscribed';
|
||||||
|
|
||||||
public static function connection(ConnectionInterface $connection)
|
public static function connection(ConnectionInterface $connection)
|
||||||
{
|
{
|
||||||
/** @var \GuzzleHttp\Psr7\Request $request */
|
/** @var \GuzzleHttp\Psr7\Request $request */
|
||||||
|
|
@ -74,6 +85,20 @@ class DashboardLogger
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function replicatorSubscribed(string $appId, string $channel, string $serverId)
|
||||||
|
{
|
||||||
|
static::log($appId, static::TYPE_REPLICATOR_SUBSCRIBED, [
|
||||||
|
'details' => "Server ID: {$serverId} on Channel: {$channel}",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function replicatorUnsubscribed(string $appId, string $channel, string $serverId)
|
||||||
|
{
|
||||||
|
static::log($appId, static::TYPE_REPLICATOR_UNSUBSCRIBED, [
|
||||||
|
'details' => "Server ID: {$serverId} on Channel: {$channel}",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public static function log($appId, string $type, array $attributes = [])
|
public static function log($appId, string $type, array $attributes = [])
|
||||||
{
|
{
|
||||||
$channelName = static::LOG_CHANNEL_PREFIX.$type;
|
$channelName = static::LOG_CHANNEL_PREFIX.$type;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use stdClass;
|
||||||
use Symfony\Component\HttpKernel\Exception\HttpException;
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
||||||
|
|
||||||
class FetchChannelsController extends Controller
|
class FetchChannelsController extends Controller
|
||||||
|
|
@ -54,15 +55,18 @@ class FetchChannelsController extends Controller
|
||||||
return $this->replicator
|
return $this->replicator
|
||||||
->channelMemberCounts($request->appId, $channelNames)
|
->channelMemberCounts($request->appId, $channelNames)
|
||||||
->then(function (array $counts) use ($channels, $attributes) {
|
->then(function (array $counts) use ($channels, $attributes) {
|
||||||
return [
|
$channels = $channels->map(function (PresenceChannel $channel) use ($counts, $attributes) {
|
||||||
'channels' => $channels->map(function (PresenceChannel $channel) use ($counts, $attributes) {
|
$info = new stdClass;
|
||||||
$info = new \stdClass;
|
|
||||||
if (in_array('user_count', $attributes)) {
|
|
||||||
$info->user_count = $counts[$channel->getChannelName()];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $info;
|
if (in_array('user_count', $attributes)) {
|
||||||
})->toArray() ?: new \stdClass,
|
$info->user_count = $counts[$channel->getChannelName()];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $info;
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'channels' => $channels ?: new stdClass,
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\PubSub\Drivers;
|
namespace BeyondCode\LaravelWebSockets\PubSub\Drivers;
|
||||||
|
|
||||||
|
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
|
||||||
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
|
use BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface;
|
||||||
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
|
||||||
use Clue\React\Redis\Client;
|
use Clue\React\Redis\Client;
|
||||||
|
|
@ -139,6 +140,8 @@ class RedisClient implements ReplicationInterface
|
||||||
$this->subscribedChannels["$appId:$channel"]++;
|
$this->subscribedChannels["$appId:$channel"]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DashboardLogger::replicatorSubscribed($appId, $channel, $this->serverId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,9 +164,12 @@ class RedisClient implements ReplicationInterface
|
||||||
// If we no longer have subscriptions to that channel, unsubscribe
|
// If we no longer have subscriptions to that channel, unsubscribe
|
||||||
if ($this->subscribedChannels["$appId:$channel"] < 1) {
|
if ($this->subscribedChannels["$appId:$channel"] < 1) {
|
||||||
$this->subscribeClient->__call('unsubscribe', ["$appId:$channel"]);
|
$this->subscribeClient->__call('unsubscribe', ["$appId:$channel"]);
|
||||||
|
|
||||||
unset($this->subscribedChannels["$appId:$channel"]);
|
unset($this->subscribedChannels["$appId:$channel"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DashboardLogger::replicatorUnsubscribed($appId, $channel, $this->serverId);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue