This commit is contained in:
Marcel Pociot 2018-11-20 12:33:40 +01:00
parent 59aad53091
commit a09356e40c
2 changed files with 12 additions and 7 deletions

View File

@ -3,8 +3,6 @@
namespace BeyondCode\LaravelWebSockets;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\Router as LaravelRouter;
use BeyondCode\LaravelWebSockets\Facades\WebSocketRouter;
class LaravelWebSocketsServiceProvider extends ServiceProvider
{
@ -13,10 +11,6 @@ class LaravelWebSocketsServiceProvider extends ServiceProvider
*/
public function boot()
{
LaravelRouter::macro('websocket', function($uri, $action) {
WebSocketRouter::addRoute($uri, $action);
});
$this->commands([
Console\StartWebSocketServer::class,
]);

View File

@ -17,12 +17,23 @@ class Router
$this->routes = new RouteCollection;
}
public function addRoute($uri, $action)
/**
* 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));
}