Skip to content

Commit 7ef38c8

Browse files
committed
Merge branch 'leeovery/8.x' into 8.x
2 parents 53a9850 + 1a9dfb4 commit 7ef38c8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/Illuminate/Broadcasting/Broadcasters/AblyBroadcaster.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Illuminate\Broadcasting\Broadcasters;
44

55
use Ably\AblyRest;
6+
use Ably\Models\Message as AblyMessage;
67
use Illuminate\Support\Str;
78
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
89

@@ -121,10 +122,28 @@ public function generateAblySignature($channelName, $socketId, $userData = null)
121122
public function broadcast(array $channels, $event, array $payload = [])
122123
{
123124
foreach ($this->formatChannels($channels) as $channel) {
124-
$this->ably->channels->get($channel)->publish($event, $payload);
125+
$this->ably->channels->get($channel)->publish(
126+
$this->buildAblyMessage($event, $payload)
127+
);
125128
}
126129
}
127130

131+
/**
132+
* Build an Ably message object for broadcasting.
133+
*
134+
* @param string $event
135+
* @param array $payload
136+
* @return \Ably\Models\Message
137+
*/
138+
protected function buildAblyMessage($event, array $payload = [])
139+
{
140+
return tap(new AblyMessage, function ($message) use ($event, $payload) {
141+
$message->name = $event;
142+
$message->data = $payload;
143+
$message->connectionKey = data_get($payload, 'socket');
144+
});
145+
}
146+
128147
/**
129148
* Return true if the channel is protected by authentication.
130149
*

0 commit comments

Comments
 (0)