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

Commit

Permalink
Passing the Socket ID to the broadcastAcrossServers()
Browse files Browse the repository at this point in the history
  • Loading branch information
rennokki committed Sep 18, 2020
1 parent 0f90f52 commit 30c6635
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/API/TriggerEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __invoke(Request $request)
);
} else {
$this->channelManager->broadcastAcrossServers(
$request->appId, $channelName, (object) $payload
$request->appId, $request->socket_id, $channelName, (object) $payload
);
}

Expand Down
4 changes: 3 additions & 1 deletion src/ChannelManagers/LocalChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,13 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
* Broadcast the message across multiple servers.
*
* @param string|int $appId
* @param string|null $socketId
* @param string $channel
* @param stdClass $payload
* @param string|null $serverId
* @return bool
*/
public function broadcastAcrossServers($appId, string $channel, stdClass $payload)
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null)
{
return true;
}
Expand Down
7 changes: 5 additions & 2 deletions src/ChannelManagers/RedisChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,17 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
* Broadcast the message across multiple servers.
*
* @param string|int $appId
* @param string|null $socketId
* @param string $channel
* @param stdClass $payload
* @param string|null $serverId
* @return bool
*/
public function broadcastAcrossServers($appId, string $channel, stdClass $payload)
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null)
{
$payload->appId = $appId;
$payload->serverId = $this->getServerId();
$payload->socketId = $socketId;
$payload->serverId = $serverId ?: $this->getServerId();

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

Expand Down
4 changes: 2 additions & 2 deletions src/Channels/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function broadcast($appId, stdClass $payload, bool $replicate = true): bo
->each->send(json_encode($payload));

if ($replicate) {
$this->channelManager->broadcastAcrossServers($appId, $this->getName(), $payload);
$this->channelManager->broadcastAcrossServers($appId, null, $this->getName(), $payload);
}

return true;
Expand All @@ -148,7 +148,7 @@ public function broadcast($appId, stdClass $payload, bool $replicate = true): bo
public function broadcastToEveryoneExcept(stdClass $payload, ?string $socketId, $appId, bool $replicate = true)
{
if ($replicate) {
$this->channelManager->broadcastAcrossServers($appId, $this->getName(), $payload);
$this->channelManager->broadcastAcrossServers($appId, $socketId, $this->getName(), $payload);
}

if (is_null($socketId)) {
Expand Down
4 changes: 3 additions & 1 deletion src/Contracts/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ public function getGlobalConnectionsCount($appId, string $channelName = null): P
* Broadcast the message across multiple servers.
*
* @param string|int $appId
* @param string|null $socketId
* @param string $channel
* @param stdClass $payload
* @param string|null $serverId
* @return bool
*/
public function broadcastAcrossServers($appId, string $channel, stdClass $payload);
public function broadcastAcrossServers($appId, ?string $socketId, string $channel, stdClass $payload, string $serverId = null);

/**
* Handle the user when it joined a presence channel.
Expand Down
2 changes: 1 addition & 1 deletion src/DashboardLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public static function log($appId, string $type, array $details = [])
);
} else {
$channelManager->broadcastAcrossServers(
$appId, $channelName, (object) $payload
$appId, null, $channelName, (object) $payload
);
}
}
Expand Down

0 comments on commit 30c6635

Please sign in to comment.