routes = new RouteCollection; } /** * Add a new WebSocket route. * * @param $uri * @param $action */ public function websocket($uri, $action) { if (!is_subclass_of($action, WebSocketController::class)) { throw InvalidWebSocketController::withController($action); } $this->addRoute($uri, $action); } public function addRoute($uri, $action) { $this->routes->add($uri, $this->getRoute($uri, $action)); } protected function getRoute($uri, $action): Route { return new Route($uri, ['_controller' => $this->wrapController($action)], [], [], null, [], ['GET']); } /** * Wrap WebSocket controllers with Ratchets WsServer. */ protected function wrapController($controller) { if (is_subclass_of($controller, WebSocketController::class)) { return new WsServer(app($controller)); } return app($controller); } public function getRoutes(): RouteCollection { return $this->routes; } }