I support default Channel
This commit is contained in:
parent
6031cdf9c5
commit
bc6abf6841
|
|
@ -19,4 +19,28 @@ class WebsocketService
|
||||||
// : ['data' => $d['data']]
|
// : ['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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ class Controller
|
||||||
|
|
||||||
public static function controll_message(
|
public static function controll_message(
|
||||||
ConnectionInterface $connection,
|
ConnectionInterface $connection,
|
||||||
PrivateChannel $channel,
|
PrivateChannel|Channel|PresenceChannel $channel,
|
||||||
array $message,
|
array $message,
|
||||||
LocalChannelManager|RedisChannelManager $channelManager
|
LocalChannelManager|RedisChannelManager $channelManager
|
||||||
) {
|
) {
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ class Handler implements MessageComponentInterface
|
||||||
|
|
||||||
// Cut short for ping pong
|
// Cut short for ping pong
|
||||||
if (strpos($message['event'], ':ping') !== false) {
|
if (strpos($message['event'], ':ping') !== false) {
|
||||||
|
$this->channelManager->connectionPonged($connection);
|
||||||
return gc_collect_cycles();
|
return gc_collect_cycles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -344,7 +345,7 @@ class Handler implements MessageComponentInterface
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_connection_channel(&$connection, &$message): ?PrivateChannel
|
protected function get_connection_channel(&$connection, &$message): ?Channel
|
||||||
{
|
{
|
||||||
// Put channel on its place
|
// Put channel on its place
|
||||||
if (! @$message['channel'] && $message['data'] && $message['data']['channel']) {
|
if (! @$message['channel'] && $message['data'] && $message['data']['channel']) {
|
||||||
|
|
@ -518,13 +519,11 @@ class Handler implements MessageComponentInterface
|
||||||
|
|
||||||
// Retrieve cached data
|
// Retrieve cached data
|
||||||
$sending = @cache()->get($pidcache_data);
|
$sending = @cache()->get($pidcache_data);
|
||||||
|
$bm = json_decode($sending, true);
|
||||||
|
|
||||||
|
|
||||||
// Send the data to client
|
// Send the data to client
|
||||||
if(@$message['broadcast']){
|
if (@$bm['broadcast']) {
|
||||||
|
|
||||||
$bm = json_decode($sending, true);
|
|
||||||
|
|
||||||
$this->broadcast(
|
$this->broadcast(
|
||||||
$connection->app->id,
|
$connection->app->id,
|
||||||
$bm['data'] ?? null,
|
$bm['data'] ?? null,
|
||||||
|
|
@ -557,23 +556,20 @@ class Handler implements MessageComponentInterface
|
||||||
|
|
||||||
$channel = $this->channelManager->findOrCreate($appId, $channel);
|
$channel = $this->channelManager->findOrCreate($appId, $channel);
|
||||||
|
|
||||||
foreach ($channel->getConnections() as $channel_conection) {
|
$p = [
|
||||||
if ($channel_conection !== $connection) {
|
|
||||||
$channel_conection->send(json_encode([
|
|
||||||
'event' => ($event ?? $event),
|
'event' => ($event ?? $event),
|
||||||
'data' => $payload,
|
'data' => $payload,
|
||||||
'channel' => $channel->getName(),
|
'channel' => $channel->getName(),
|
||||||
]));
|
];
|
||||||
|
|
||||||
|
foreach ($channel->getConnections() as $channel_conection) {
|
||||||
|
if ($channel_conection !== $connection) {
|
||||||
|
$channel_conection->send(json_encode($p));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($including_self) {
|
if ($including_self) {
|
||||||
$connection->send(json_encode([
|
$connection->send(json_encode($p));
|
||||||
'event' => ($event ?? $event),
|
|
||||||
'data' => $payload,
|
|
||||||
'channel' => $channel->getName(),
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue