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

Commit 30c6635

Browse files
committed
Passing the Socket ID to the broadcastAcrossServers()
1 parent 0f90f52 commit 30c6635

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

src/API/TriggerEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function __invoke(Request $request)
4545
);
4646
} else {
4747
$this->channelManager->broadcastAcrossServers(
48-
$request->appId, $channelName, (object) $payload
48+
$request->appId, $request->socket_id, $channelName, (object) $payload
4949
);
5050
}
5151

src/ChannelManagers/LocalChannelManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,13 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
259259
* Broadcast the message across multiple servers.
260260
*
261261
* @param string|int $appId
262+
* @param string|null $socketId
262263
* @param string $channel
263264
* @param stdClass $payload
265+
* @param string|null $serverId
264266
* @return bool
265267
*/
266-
public function broadcastAcrossServers($appId, string $channel, stdClass $payload)
268+
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null)
267269
{
268270
return true;
269271
}

src/ChannelManagers/RedisChannelManager.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,17 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
268268
* Broadcast the message across multiple servers.
269269
*
270270
* @param string|int $appId
271+
* @param string|null $socketId
271272
* @param string $channel
272273
* @param stdClass $payload
274+
* @param string|null $serverId
273275
* @return bool
274276
*/
275-
public function broadcastAcrossServers($appId, string $channel, stdClass $payload)
277+
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null)
276278
{
277279
$payload->appId = $appId;
278-
$payload->serverId = $this->getServerId();
280+
$payload->socketId = $socketId;
281+
$payload->serverId = $serverId ?: $this->getServerId();
279282

280283
$this->publishClient->publish($this->getRedisKey($appId, $channel), json_encode($payload));
281284

src/Channels/Channel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function broadcast($appId, stdClass $payload, bool $replicate = true): bo
130130
->each->send(json_encode($payload));
131131

132132
if ($replicate) {
133-
$this->channelManager->broadcastAcrossServers($appId, $this->getName(), $payload);
133+
$this->channelManager->broadcastAcrossServers($appId, null, $this->getName(), $payload);
134134
}
135135

136136
return true;
@@ -148,7 +148,7 @@ public function broadcast($appId, stdClass $payload, bool $replicate = true): bo
148148
public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId, $appId, bool $replicate = true)
149149
{
150150
if ($replicate) {
151-
$this->channelManager->broadcastAcrossServers($appId, $this->getName(), $payload);
151+
$this->channelManager->broadcastAcrossServers($appId, $socketId, $this->getName(), $payload);
152152
}
153153

154154
if (is_null($socketId)) {

src/Contracts/ChannelManager.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
131131
* Broadcast the message across multiple servers.
132132
*
133133
* @param string|int $appId
134+
* @param string|null $socketId
134135
* @param string $channel
135136
* @param stdClass $payload
137+
* @param string|null $serverId
136138
* @return bool
137139
*/
138-
public function broadcastAcrossServers($appId, string $channel, stdClass $payload);
140+
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null);
139141

140142
/**
141143
* Handle the user when it joined a presence channel.

src/DashboardLogger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static function log($appId, string $type, array $details = [])
9090
);
9191
} else {
9292
$channelManager->broadcastAcrossServers(
93-
$appId, $channelName, (object) $payload
93+
$appId, null, $channelName, (object) $payload
9494
);
9595
}
9696
}

0 commit comments

Comments
 (0)