diff --git a/config/websockets.php b/config/websockets.php index 681bb6bdc1..c44a7776cd 100644 --- a/config/websockets.php +++ b/config/websockets.php @@ -280,6 +280,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], + | + | ], + | + */ /* |-------------------------------------------------------------------------- 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]); + } + } } /**