Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Console/StartWebSocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function handle()
->configureMessageLogger()
->configureConnectionLogger()
->registerEchoRoutes()
->registerCustomRoutes()
->startWebSocketServer();
}

Expand Down Expand Up @@ -110,6 +111,13 @@ protected function registerEchoRoutes()
return $this;
}

protected function registerCustomRoutes()
{
WebSocketsRouter::customRoutes();

return $this;
}

protected function startWebSocketServer()
{
$this->info("Starting the WebSocket server on port {$this->option('port')}...");
Expand Down
12 changes: 11 additions & 1 deletion src/Server/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace BeyondCode\LaravelWebSockets\Server;

use Ratchet\WebSocket\WsServer;
use Illuminate\Support\Collection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Ratchet\WebSocket\MessageComponentInterface;
Expand All @@ -18,10 +19,12 @@ class Router
{
/** @var \Symfony\Component\Routing\RouteCollection */
protected $routes;
protected $customRoutes;

public function __construct()
{
$this->routes = new RouteCollection;
$this->customRoutes = new Collection();
}

public function getRoutes(): RouteCollection
Expand All @@ -39,6 +42,13 @@ public function echo()
$this->get('/apps/{appId}/channels/{channelName}/users', FetchUsersController::class);
}

public function customRoutes()
{
$this->customRoutes->each(function ($action, $uri) {
$this->get($uri, $action);
});
}

public function get(string $uri, $action)
{
$this->addRoute('GET', $uri, $action);
Expand Down Expand Up @@ -70,7 +80,7 @@ public function webSocket(string $uri, $action)
throw InvalidWebSocketController::withController($action);
}

$this->get($uri, $action);
$this->customRoutes->put($uri, $action);
}

public function addRoute(string $method, string $uri, $action)
Expand Down