diff --git a/composer.json b/composer.json index 7ac9810..6580e80 100644 --- a/composer.json +++ b/composer.json @@ -24,10 +24,10 @@ "require": { "php": "^7.1", "cboden/ratchet": "^0.4.1", - "illuminate/support": "5.6.*|5.7.*", "illuminate/console": "5.6.*|5.7.*", "illuminate/http": "5.6.*|5.7.*", - "illuminate/routing": "5.6.*|5.7.*" + "illuminate/routing": "5.6.*|5.7.*", + "illuminate/support": "5.6.*|5.7.*" }, "require-dev": { "larapack/dd": "^1.0", diff --git a/src/LaravelEcho/Http/Controllers/EchoController.php b/src/LaravelEcho/Http/Controllers/EchoController.php new file mode 100644 index 0000000..a63047d --- /dev/null +++ b/src/LaravelEcho/Http/Controllers/EchoController.php @@ -0,0 +1,60 @@ +send(JsonResponse::create($response)->send()); + $conn->close(); + } + + /** + * Triggered when a client sends data through the socket + * @param \Ratchet\ConnectionInterface $from The socket/connection that sent the message to your application + * @param string $msg The message received + * @throws \Exception + */ + function onMessage(ConnectionInterface $from, $msg) + { + // + } + + abstract public function __invoke($request); +} \ No newline at end of file diff --git a/src/LaravelEcho/Http/Controllers/StatusController.php b/src/LaravelEcho/Http/Controllers/StatusController.php new file mode 100644 index 0000000..1729705 --- /dev/null +++ b/src/LaravelEcho/Http/Controllers/StatusController.php @@ -0,0 +1,14 @@ + 10 + ]; + } +} \ No newline at end of file diff --git a/src/Router.php b/src/Router.php index 1d0f48c..83f8d63 100644 --- a/src/Router.php +++ b/src/Router.php @@ -4,6 +4,7 @@ namespace BeyondCode\LaravelWebSockets; use Ratchet\WebSocket\WsServer; use Symfony\Component\Routing\Route; +use Ratchet\Http\HttpServerInterface; use Symfony\Component\Routing\RouteCollection; use BeyondCode\LaravelWebSockets\Exceptions\InvalidWebSocketController; @@ -39,19 +40,33 @@ class Router protected function getRoute($uri, $action): Route { - return new Route($uri, ['_controller' => $this->wrapController($action)], [], [], null, [], ['GET']); + return new Route($uri, ['_controller' => $this->wrapAction($action)], [], [], null, [], ['GET']); + } + + /** + * Register the required Laravel Echo routes + */ + public function echo() + { + //$this->addRoute('/', EchoWebsocketServer::class); + $this->addRoute('/apps/{appId}/status', LaravelEcho\Http\Controllers\StatusController::class); + //$this->addRoute('/apps/{appId}/channels', 'ChannelController@index'); } /** * Wrap WebSocket controllers with Ratchets WsServer. + * If the action is not a WebSocketController, wrap it with our HttpServerInstance + * + * @param $action + * @return WsServer|HttpServerInterface */ - protected function wrapController($controller) + protected function wrapAction($action) { - if (is_subclass_of($controller, WebSocketController::class)) { - return new WsServer(app($controller)); + if (is_subclass_of($action, WebSocketController::class)) { + return new WsServer(app($action)); } - return app($controller); + return app($action); } public function getRoutes(): RouteCollection