This commit is contained in:
Marcel Pociot 2018-11-22 11:29:12 +01:00
parent fbd26ee7ff
commit e7561d29dd
2 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,12 @@
<?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions;
class UnknownAppId extends PusherException
{
public function __construct(string $appId)
{
$this->message = "Could not find app key {$appId}";
$this->code = 4001;
}
}

View File

@ -3,6 +3,7 @@
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket; namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket;
use BeyondCode\LaravelWebsockets\LaravelEcho\Pusher\Exceptions\PusherException; use BeyondCode\LaravelWebsockets\LaravelEcho\Pusher\Exceptions\PusherException;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\UnknownAppId;
use Exception; use Exception;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface; use Ratchet\RFC6455\Messaging\MessageInterface;
@ -39,6 +40,8 @@ class PusherServer extends WebSocketController
$connection->appId = $queryParameters['appId']; $connection->appId = $queryParameters['appId'];
$this->verifyConnection($connection);
$connection->send(json_encode([ $connection->send(json_encode([
'event' => 'pusher:connection_established', 'event' => 'pusher:connection_established',
'data' => json_encode([ 'data' => json_encode([
@ -68,4 +71,12 @@ class PusherServer extends WebSocketController
)); ));
} }
} }
protected function verifyConnection(ConnectionInterface $connection)
{
// Todo: Lookup app-id for multi-tenancy support
if ($connection->appId !== config('broadcasting.connections.pusher.app_id')) {
throw new UnknownAppId($connection->appId);
}
}
} }