This commit is contained in:
Marcel Pociot 2018-11-22 17:59:56 +01:00
parent fc622bc626
commit efb603ea95
4 changed files with 19 additions and 18 deletions

View File

@ -1,12 +0,0 @@
<?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

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

View File

@ -3,7 +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 BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\UnknownAppKey;
use Exception; use Exception;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface; use Ratchet\RFC6455\Messaging\MessageInterface;
@ -48,6 +48,7 @@ class PusherServer extends WebSocketController
$exception->getPayload() $exception->getPayload()
)); ));
} }
dump($exception);
} }
protected function verifyConnection(ConnectionInterface $connection) protected function verifyConnection(ConnectionInterface $connection)
@ -58,12 +59,12 @@ class PusherServer extends WebSocketController
$queryParameters = []; $queryParameters = [];
parse_str($request->getUri()->getQuery(), $queryParameters); parse_str($request->getUri()->getQuery(), $queryParameters);
$connection->appId = $queryParameters['appId'];
// Todo: Lookup app-id for multi-tenancy support // Todo: Lookup app-id for multi-tenancy support
if ($connection->appId !== config('broadcasting.connections.pusher.app_id')) { if ($queryParameters['appKey'] !== config('broadcasting.connections.pusher.key')) {
throw new UnknownAppId($connection->appId); throw new UnknownAppKey($queryParameters['appKey']);
} }
$connection->appId = config('broadcasting.connections.pusher.app_id');
} }
protected function establishConnection(ConnectionInterface $connection) protected function establishConnection(ConnectionInterface $connection)

View File

@ -66,7 +66,7 @@ class Router
public function echo() public function echo()
{ {
//TODO: add origin checker middleware //TODO: add origin checker middleware
$this->get('/app/{appId}', LaravelEcho\WebSocket\PusherServer::class); $this->get('/app/{appKey}', LaravelEcho\WebSocket\PusherServer::class);
// TODO: fleshen out http API // TODO: fleshen out http API
$this->get('/apps/{appId}/status', LaravelEcho\Http\Controllers\StatusController::class); $this->get('/apps/{appId}/status', LaravelEcho\Http\Controllers\StatusController::class);