Merge branch 'master' of github.com:beyondcode/laravel-websockets

This commit is contained in:
freek 2018-11-22 08:49:58 +01:00
commit 5593b96dd2
3 changed files with 15 additions and 7 deletions

View File

@ -55,8 +55,8 @@ class Channel
public function broadcastToOthers(ConnectionInterface $connection, $payload)
{
Collection::make($this->connections)->reject(function ($connection) use ($connection) {
return $connection->socketId === $connection->socketId;
Collection::make($this->connections)->reject(function ($existingConnection) use ($connection) {
return $existingConnection->socketId === $connection->socketId;
})->each->send(json_encode($payload));
}
}

View File

@ -16,7 +16,7 @@ class PresenceChannel extends Channel
$this->saveConnection($connection);
$channelData = json_decode($payload->channel_data);
$this->subscriptions[$channelData->user_id] = $channelData;
$this->subscriptions[$connection->socketId] = $channelData;
// Send the success event
$connection->send(json_encode([
@ -36,14 +36,22 @@ class PresenceChannel extends Channel
{
parent::unsubscribe($connection);
//TODO: send member_removed message back to client, and broadcast to everyone on channel
$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_removed',
'channel' => $this->channelId,
'data' => json_encode([
'user_id' => $this->subscriptions[$connection->socketId]->user_id
])
]);
unset($this->subscriptions[$connection->socketId]);
}
protected function getChannelData(): array
{
return [
'presence' => [
'ids' => array_keys($this->subscriptions),
'ids' => array_map(function($channelData) { return $channelData->user_id; }, $this->subscriptions),
'hash' => array_map(function($channelData) { return $channelData->user_info; }, $this->subscriptions),
'count' => count($this->subscriptions)
]

View File

@ -46,9 +46,9 @@ class EchoServer extends WebSocketController
]));
}
public function onMessage(ConnectionInterface $conn, MessageInterface $message)
public function onMessage(ConnectionInterface $connection, MessageInterface $message)
{
$message = RespondableMessageFactory::createForMessage($message, $conn, $this->channelManager);
$message = RespondableMessageFactory::createForMessage($message, $connection, $this->channelManager);
$message->respond();
}