From 726760d44845d00643cdfa833012e464ef2cb766 Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 26 Nov 2018 08:55:08 +0100 Subject: [PATCH 1/4] make verbose work --- src/ClientProviders/ConfigClientProvider.php | 2 -- src/Console/StartWebSocketServer.php | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/ClientProviders/ConfigClientProvider.php b/src/ClientProviders/ConfigClientProvider.php index 90241fc..26074a9 100644 --- a/src/ClientProviders/ConfigClientProvider.php +++ b/src/ClientProviders/ConfigClientProvider.php @@ -33,8 +33,6 @@ class ConfigClientProvider implements ClientProvider return $this->instanciate($clientAttributes); } - - protected function allClients(): Collection { return collect(config('websockets.clients')); diff --git a/src/Console/StartWebSocketServer.php b/src/Console/StartWebSocketServer.php index 43e7226..ac112be 100644 --- a/src/Console/StartWebSocketServer.php +++ b/src/Console/StartWebSocketServer.php @@ -30,8 +30,7 @@ class StartWebSocketServer extends Command app()->singleton(MessageLogger::class, function() { return (new MessageLogger($this->output)) ->enable(config('app.debug')) - //TODO: use real option - ->verbose($this->hasOption('vvv')); + ->verbose($this->output->isVerbose()); }); return $this; @@ -42,8 +41,7 @@ class StartWebSocketServer extends Command app()->bind(ConnectionLogger::class, function() { return (new ConnectionLogger($this->output)) ->enable(config('app.debug')) - //TODO: use real option - ->verbose($this->hasOption('vvv')); + ->verbose($this->output->isVerbose()); }); return $this; From f51ed94b77fd3d957e8f197308c3cc3cd09daa79 Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 26 Nov 2018 08:55:38 +0100 Subject: [PATCH 2/4] nitpick --- src/Exceptions/InvalidClient.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exceptions/InvalidClient.php b/src/Exceptions/InvalidClient.php index d81260d..092acd6 100644 --- a/src/Exceptions/InvalidClient.php +++ b/src/Exceptions/InvalidClient.php @@ -19,6 +19,6 @@ class InvalidClient extends Exception public static function valueIsRequired($name, int $appId) { - return new static("{$name} is required but was empty for app id {$appId}"); + return new static("{$name} is required but was empty for app id `{$appId}`."); } } \ No newline at end of file From eb82682e87508baa1bc755e199c8879cba8cb679 Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 26 Nov 2018 08:56:56 +0100 Subject: [PATCH 3/4] nitpicks --- src/Exceptions/InvalidClient.php | 1 - src/Http/Controllers/SendMessage.php | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/InvalidClient.php b/src/Exceptions/InvalidClient.php index 092acd6..d76c8ef 100644 --- a/src/Exceptions/InvalidClient.php +++ b/src/Exceptions/InvalidClient.php @@ -2,7 +2,6 @@ namespace BeyondCode\LaravelWebSockets\Exceptions; - use Exception; class InvalidClient extends Exception diff --git a/src/Http/Controllers/SendMessage.php b/src/Http/Controllers/SendMessage.php index fe13011..b8aaa0c 100644 --- a/src/Http/Controllers/SendMessage.php +++ b/src/Http/Controllers/SendMessage.php @@ -18,6 +18,10 @@ class SendMessage ); return (new PusherBroadcaster($pusher)) - ->broadcast([$request->channel], $request->event, json_decode($request->data, true)); + ->broadcast( + [$request->channel], + $request->event, + json_decode($request->data, true) + ); } -} \ No newline at end of file +} From ea44025e884d91a796e865b117ff8edf88e6f613 Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 26 Nov 2018 09:03:04 +0100 Subject: [PATCH 4/4] nitpicks --- src/Http/Controllers/ShowDashboard.php | 2 +- .../Http/Controllers/EchoController.php | 19 +++++++++++-------- .../Http/Controllers/TriggerEvent.php | 9 +++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/Http/Controllers/ShowDashboard.php b/src/Http/Controllers/ShowDashboard.php index cbc1d8d..f182708 100644 --- a/src/Http/Controllers/ShowDashboard.php +++ b/src/Http/Controllers/ShowDashboard.php @@ -10,7 +10,7 @@ class ShowDashboard public function __invoke(Request $request, ClientProvider $clients) { return view('websockets::dashboard', [ - 'clients' => $clients->all() + 'clients' => $clients->all(), ]); } } \ No newline at end of file diff --git a/src/LaravelEcho/Http/Controllers/EchoController.php b/src/LaravelEcho/Http/Controllers/EchoController.php index 4e5095b..f2606d5 100644 --- a/src/LaravelEcho/Http/Controllers/EchoController.php +++ b/src/LaravelEcho/Http/Controllers/EchoController.php @@ -40,8 +40,9 @@ abstract class EchoController implements HttpServerInterface $laravelRequest = Request::createFromBase((new HttpFoundationFactory)->createRequest($serverRequest)); - $this->verifyAppId($laravelRequest->appId); - $this->verifySignature($laravelRequest); + $this + ->ensureValidAppId($laravelRequest->appId) + ->ensureValidSignature($laravelRequest); $response = $this($laravelRequest); @@ -66,21 +67,21 @@ abstract class EchoController implements HttpServerInterface 'error' => $exception->getMessage() ])); - $connection->send(gPsr\str($response)); + $connection->send(Psr\str($response)); $connection->close(); } } - public function verifyAppId(string $appId) + public function ensureValidAppId(string $appId) { - if ($client = Client::findByAppId($appId)) { - return; + if (! $client = Client::findByAppId($appId)) { + throw new HttpException(401, "Unknown app id `{$appId}` provided."); } - throw new HttpException(401, "Unknown app id `{$appId}` provided."); + return true; } - protected function verifySignature(Request $request) + protected function ensureValidSignature(Request $request) { $bodyMd5 = md5($request->getContent()); @@ -96,6 +97,8 @@ abstract class EchoController implements HttpServerInterface if ($authSignature !== $request->get('auth_signature')) { throw new HttpException(401, 'Invalid auth signature provided.'); } + + return $this; } abstract public function __invoke(Request $request); diff --git a/src/LaravelEcho/Http/Controllers/TriggerEvent.php b/src/LaravelEcho/Http/Controllers/TriggerEvent.php index de0a016..7630ee1 100644 --- a/src/LaravelEcho/Http/Controllers/TriggerEvent.php +++ b/src/LaravelEcho/Http/Controllers/TriggerEvent.php @@ -9,10 +9,15 @@ class TriggerEvent extends EchoController { public function __invoke(Request $request) { - $this->verifySignature($request); + $this->ensureValidSignature($request); foreach ($request->json()->get('channels', []) as $channelId) { - Dashboard::apiMessage($request->appId, $channelId, $request->json()->get('name'), $request->json()->get('data')); + Dashboard::apiMessage( + $request->appId, + $channelId, + $request->json()->get('name'), + $request->json()->get('data') + ); $channel = $this->channelManager->find($request->appId, $channelId);