IBF broadcasting socket
This commit is contained in:
parent
0f54c414a2
commit
cc78a9b4d5
|
|
@ -30,6 +30,8 @@ class BroadcastSocketServer
|
|||
|
||||
protected string $socketPath;
|
||||
|
||||
protected string $appId;
|
||||
|
||||
/**
|
||||
* Active client connections
|
||||
* @var ConnectionInterface[]
|
||||
|
|
@ -41,6 +43,7 @@ class BroadcastSocketServer
|
|||
$this->loop = $loop;
|
||||
$this->channelManager = $channelManager;
|
||||
$this->socketPath = config('websockets.broadcast_socket', '/tmp/laravel-websockets-broadcast.sock');
|
||||
$this->appId = config('websockets.apps.0.id', 'websocket');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -122,13 +125,26 @@ class BroadcastSocketServer
|
|||
$sockets = $payload['sockets'] ?? null; // Target specific sockets
|
||||
$excludeSockets = $payload['exclude_sockets'] ?? []; // Exclude specific sockets
|
||||
|
||||
Log::info('[BroadcastSocket] Received broadcast request', [
|
||||
'event' => $event,
|
||||
'channel' => $channel,
|
||||
'appId' => $this->appId,
|
||||
'target_sockets' => $sockets ? count($sockets) : 'all',
|
||||
]);
|
||||
|
||||
// Get channel instance and broadcast
|
||||
$channelInstance = $this->channelManager->find('websockets', $channel);
|
||||
$channelInstance = $this->channelManager->find($this->appId, $channel);
|
||||
|
||||
if ($channelInstance) {
|
||||
$connectionCount = count($channelInstance->getConnections());
|
||||
Log::info('[BroadcastSocket] Found channel with connections', [
|
||||
'channel' => $channel,
|
||||
'connections' => $connectionCount,
|
||||
]);
|
||||
$this->broadcastToChannel($channelInstance, $event, $data, $sockets, $excludeSockets);
|
||||
$connection->write(json_encode(['success' => true]) . "\n");
|
||||
} else {
|
||||
Log::info('[BroadcastSocket] Channel not found or no subscribers', ['channel' => $channel]);
|
||||
// Channel doesn't exist or no subscribers - still success
|
||||
$connection->write(json_encode(['success' => true, 'warning' => 'No channel subscribers']) . "\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,12 @@ class WebsocketService
|
|||
$innerChannel = $data['channel'] ?? $channel ?? 'websocket';
|
||||
$targetSockets = $data['sockets'] ?? null;
|
||||
|
||||
\Log::info('[WebsocketService] Sending via broadcast socket (app.whisp)', [
|
||||
'innerEvent' => $innerEvent,
|
||||
'innerChannel' => $innerChannel,
|
||||
'targetSockets' => $targetSockets ? count($targetSockets) : 'all',
|
||||
]);
|
||||
|
||||
if (!empty($targetSockets) && is_array($targetSockets)) {
|
||||
// Whisper to specific sockets
|
||||
$success = ws_whisper($innerEvent, $innerData, $targetSockets, $innerChannel);
|
||||
|
|
@ -45,6 +51,7 @@ class WebsocketService
|
|||
if ($success) {
|
||||
return (object)['success' => true, 'method' => 'broadcast_socket'];
|
||||
}
|
||||
\Log::warning('[WebsocketService] Broadcast socket failed, falling back to WebSocket');
|
||||
// Fall through to WebSocket client if broadcast socket fails
|
||||
} else {
|
||||
// Regular broadcast
|
||||
|
|
@ -54,6 +61,8 @@ class WebsocketService
|
|||
}
|
||||
// Fall through to WebSocket client if broadcast socket fails
|
||||
}
|
||||
} else {
|
||||
\Log::info('[WebsocketService] Broadcast socket not available, using WebSocket fallback');
|
||||
}
|
||||
|
||||
// Fallback: Create new WebSocket connection (slower, for when broadcast socket not available)
|
||||
|
|
|
|||
Loading…
Reference in New Issue