From ce01a2047562a7896df76ab409d1d873d7dd657b Mon Sep 17 00:00:00 2001 From: simonbuehler Date: Fri, 15 Jan 2021 14:33:11 +0100 Subject: [PATCH 1/2] add custom_handlers config entry --- config/websockets.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/config/websockets.php b/config/websockets.php index b4d2c64481..c879b06759 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -278,6 +278,22 @@ 'fetch_users' => \BeyondCode\LaravelWebSockets\API\FetchUsers::class, ], + + /* + |-------------------------------------------------------------------------- + | Custom Route Handlers + |-------------------------------------------------------------------------- + | + | Here you can specify custom route handlers along with the http method + | that will take over the incoming/outgoing websocket connections + | + | 'custom_handlers' => [ + | + | '/apps/{appId}/my_route' => ['get' , App\MyCustomRouteHandler::class], + | + | ], + | + */ /* |-------------------------------------------------------------------------- From 90103d50a31a715b085e44c2ab222a14118005f9 Mon Sep 17 00:00:00 2001 From: simonbuehler Date: Fri, 15 Jan 2021 14:36:55 +0100 Subject: [PATCH 2/2] add custom routes --- src/Server/Router.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Server/Router.php b/src/Server/Router.php index bda9878bdd..36b576e3b0 100644 --- a/src/Server/Router.php +++ b/src/Server/Router.php @@ -50,6 +50,13 @@ public function routes() $this->get('/apps/{appId}/channels/{channelName}', config('websockets.handlers.fetch_channel')); $this->get('/apps/{appId}/channels/{channelName}/users', config('websockets.handlers.fetch_users')); $this->get('/health', config('websockets.handlers.health')); + + $custom_handlers = config('websockets.custom_handlers'); + if (is_array($custom_handlers)) { + foreach ($custom_handlers as $handler => $implementation) { + $this->{$implementation[0]}($handler, $implementation[1]); + } + } } /**