I support default Channel

This commit is contained in:
a6a2f5842 2025-09-14 15:00:27 +02:00
parent 6031cdf9c5
commit bc6abf6841
3 changed files with 60 additions and 40 deletions

View File

@ -19,4 +19,28 @@ class WebsocketService
// : ['data' => $d['data']]
// );
}
function getTenantable(string $socketId)
{
config(['cache.default' => 'file']);
return cache()->get('ws_socket_tenantable_' . $socketId);
}
public static function getChannelConnections(string $channelName)
{
config(['cache.default' => 'file']);
return cache()->get('ws_channel_connections_' . $channelName);
}
public static function getActiveChannels()
{
config(['cache.default' => 'file']);
return cache()->get('ws_active_channels');
}
public static function getConnection(string $socketId)
{
config(['cache.default' => 'file']);
return cache()->get('ws_connection_' . $socketId);
}
}

View File

@ -23,7 +23,7 @@ class Controller
public static function controll_message(
ConnectionInterface $connection,
PrivateChannel $channel,
PrivateChannel|Channel|PresenceChannel $channel,
array $message,
LocalChannelManager|RedisChannelManager $channelManager
) {

View File

@ -102,6 +102,7 @@ class Handler implements MessageComponentInterface
// Cut short for ping pong
if (strpos($message['event'], ':ping') !== false) {
$this->channelManager->connectionPonged($connection);
return gc_collect_cycles();
}
@ -344,7 +345,7 @@ class Handler implements MessageComponentInterface
return $this;
}
protected function get_connection_channel(&$connection, &$message): ?PrivateChannel
protected function get_connection_channel(&$connection, &$message): ?Channel
{
// Put channel on its place
if (! @$message['channel'] && $message['data'] && $message['data']['channel']) {
@ -518,13 +519,11 @@ class Handler implements MessageComponentInterface
// Retrieve cached data
$sending = @cache()->get($pidcache_data);
$bm = json_decode($sending, true);
// Send the data to client
if(@$message['broadcast']){
$bm = json_decode($sending, true);
if (@$bm['broadcast']) {
$this->broadcast(
$connection->app->id,
$bm['data'] ?? null,
@ -557,23 +556,20 @@ class Handler implements MessageComponentInterface
$channel = $this->channelManager->findOrCreate($appId, $channel);
foreach ($channel->getConnections() as $channel_conection) {
if ($channel_conection !== $connection) {
$channel_conection->send(json_encode([
$p = [
'event' => ($event ?? $event),
'data' => $payload,
'channel' => $channel->getName(),
]));
];
foreach ($channel->getConnections() as $channel_conection) {
if ($channel_conection !== $connection) {
$channel_conection->send(json_encode($p));
}
if ($including_self) {
$connection->send(json_encode([
'event' => ($event ?? $event),
'data' => $payload,
'channel' => $channel->getName(),
]));
$connection->send(json_encode($p));
}
}
}
}