This commit is contained in:
Marcel Pociot 2018-11-24 22:07:53 +01:00
parent 2b24f064be
commit a5c7437895
7 changed files with 15 additions and 16 deletions

View File

@ -35,8 +35,7 @@ class Channel
$signature .= ":{$payload->channel_data}"; $signature .= ":{$payload->channel_data}";
} }
// TODO Have app id specific secrets if (str_after($auth, ':') !== hash_hmac('sha256', $signature, $connection->client->appSecret)) {
if (str_after($auth, ':') !== hash_hmac('sha256', $signature, config('broadcasting.connections.pusher.secret'))) {
throw new InvalidSignatureException(); throw new InvalidSignatureException();
} }
} }

View File

@ -47,16 +47,16 @@ class ChannelManager
public function removeFromAllChannels(ConnectionInterface $connection) public function removeFromAllChannels(ConnectionInterface $connection)
{ {
collect($this->channels[$connection->appId])->each->unsubscribe($connection); collect($this->channels[$connection->client->appId])->each->unsubscribe($connection);
collect($this->channels[$connection->appId]) collect($this->channels[$connection->client->appId])
->reject->hasConnections() ->reject->hasConnections()
->each(function (Channel $channel, string $channelId) use ($connection) { ->each(function (Channel $channel, string $channelId) use ($connection) {
unset($this->channels[$connection->appId][$channelId]); unset($this->channels[$connection->client->appId][$channelId]);
}); });
if (count($this->channels[$connection->appId]) === 0) { if (count($this->channels[$connection->client->appId]) === 0) {
unset($this->channels[$connection->appId]); unset($this->channels[$connection->client->appId]);
}; };
} }
} }

View File

@ -51,14 +51,14 @@ class PusherMessage implements RespondableMessage
*/ */
protected function subscribe(ConnectionInterface $connection, stdClass $payload) protected function subscribe(ConnectionInterface $connection, stdClass $payload)
{ {
$channel = $this->channelManager->findOrCreate($connection->appId, $payload->channel); $channel = $this->channelManager->findOrCreate($connection->client->appId, $payload->channel);
$channel->subscribe($connection, $payload); $channel->subscribe($connection, $payload);
} }
public function unsubscribe(ConnectionInterface $connection, stdClass $payload) public function unsubscribe(ConnectionInterface $connection, stdClass $payload)
{ {
$channel = $this->channelManager->findOrCreate($connection->appId, $payload->channel); $channel = $this->channelManager->findOrCreate($connection->client->appId, $payload->channel);
$channel->unsubscribe($connection); $channel->unsubscribe($connection);
} }

View File

@ -29,7 +29,7 @@ class Message implements RespondableMessage
public function respond() public function respond()
{ {
if (starts_with($this->payload->event, 'client-')) { if (starts_with($this->payload->event, 'client-')) {
$channel = $this->channelManager->find($this->connection->appId, $this->payload->channel); $channel = $this->channelManager->find($this->connection->client->appId, $this->payload->channel);
optional($channel)->broadcast($this->payload); optional($channel)->broadcast($this->payload);
} }

View File

@ -64,7 +64,7 @@ class PusherServer extends WebSocketController
throw new UnknownAppKey($queryParameters['appKey']); throw new UnknownAppKey($queryParameters['appKey']);
} }
$connection->appId = $client->appId; $connection->client = $client;
} }
protected function establishConnection(ConnectionInterface $connection) protected function establishConnection(ConnectionInterface $connection)

View File

@ -29,14 +29,14 @@ class ConnectionLogger extends Logger implements ConnectionInterface
public function send($data) public function send($data)
{ {
$this->info("{$this->connection->appId}: connection id {$this->connection->socketId} sending message {$data}"); $this->info("{$this->connection->client->appId}: connection id {$this->connection->socketId} sending message {$data}");
$this->connection->send($data); $this->connection->send($data);
} }
public function close() public function close()
{ {
$this->warn("{$this->connection->appId}: connection id {$this->connection->socketId} closing."); $this->warn("{$this->connection->client->appId}: connection id {$this->connection->socketId} closing.");
$this->connection->close(); $this->connection->close();
} }

View File

@ -46,14 +46,14 @@ class MessageLogger extends Logger implements MessageComponentInterface
public function onMessage(ConnectionInterface $connection, MessageInterface $message) public function onMessage(ConnectionInterface $connection, MessageInterface $message)
{ {
$this->info("{$connection->appId}: connection id {$connection->socketId} received message: {$message->getPayload()}."); $this->info("{$connection->client->appId}: connection id {$connection->socketId} received message: {$message->getPayload()}.");
$this->app->onMessage(ConnectionLogger::decorate($connection), $message); $this->app->onMessage(ConnectionLogger::decorate($connection), $message);
} }
public function onClose(ConnectionInterface $connection) public function onClose(ConnectionInterface $connection)
{ {
$this->warn("{$connection->appId}: connection id {$connection->socketId} closed."); $this->warn("{$connection->client->appId}: connection id {$connection->socketId} closed.");
$this->app->onClose(ConnectionLogger::decorate($connection)); $this->app->onClose(ConnectionLogger::decorate($connection));
} }
@ -62,7 +62,7 @@ class MessageLogger extends Logger implements MessageComponentInterface
{ {
$exceptionClass = get_class($exception); $exceptionClass = get_class($exception);
$appId = $connection->appId ?? 'Unknown app id'; $appId = $connection->client->appId ?? 'Unknown app id';
$message = "{$appId}: exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`"; $message = "{$appId}: exception `{$exceptionClass}` thrown: `{$exception->getMessage()}`";