This commit is contained in:
Marcel Pociot 2018-11-27 15:55:30 +01:00
parent 7270553c2a
commit 86d332a2c0
29 changed files with 76 additions and 53 deletions

View File

@ -36,6 +36,11 @@ return [
// //
], ],
/*
* The maximum request size that is allowed for an incoming websocket request.
*/
'maxRequestSize' => 256000,
/* /*
* Define the optional SSL context for your websocket connections. * Define the optional SSL context for your websocket connections.
* You can see all available options at: http://php.net/manual/en/context.ssl.php * You can see all available options at: http://php.net/manual/en/context.ssl.php

View File

@ -8,7 +8,7 @@ use BeyondCode\LaravelWebSockets\Events\ChannelVacated;
use BeyondCode\LaravelWebSockets\Events\ClientMessageSent; use BeyondCode\LaravelWebSockets\Events\ClientMessageSent;
use BeyondCode\LaravelWebSockets\Events\ConnectionEstablished; use BeyondCode\LaravelWebSockets\Events\ConnectionEstablished;
use BeyondCode\LaravelWebSockets\Events\SubscribedToChannel; use BeyondCode\LaravelWebSockets\Events\SubscribedToChannel;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Dashboard; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Dashboard;
use Illuminate\Events\Dispatcher; use Illuminate\Events\Dispatcher;
class EventSubscriber class EventSubscriber

View File

@ -2,7 +2,7 @@
namespace BeyondCode\LaravelWebSockets\Exceptions; namespace BeyondCode\LaravelWebSockets\Exceptions;
use BeyondCode\LaravelWebSockets\WebSocketController; use BeyondCode\LaravelWebSockets\Server\WebSocketController;
class InvalidWebSocketController extends \Exception class InvalidWebSocketController extends \Exception
{ {

View File

@ -4,7 +4,7 @@ namespace BeyondCode\LaravelWebSockets\Facades;
use Illuminate\Support\Facades\Facade; use Illuminate\Support\Facades\Facade;
/** @see \BeyondCode\LaravelWebSockets\Router */ /** @see \BeyondCode\LaravelWebSockets\Server\Router */
class WebSocketRouter extends Facade class WebSocketRouter extends Facade
{ {
protected static function getFacadeAccessor() protected static function getFacadeAccessor()

15
src/Server/HttpServer.php Normal file
View File

@ -0,0 +1,15 @@
<?php
namespace BeyondCode\LaravelWebsockets\Server;
use Ratchet\Http\HttpServerInterface;
class HttpServer extends \Ratchet\Http\HttpServer
{
public function __construct(HttpServerInterface $component, int $maxRequestSize = 4096)
{
parent::__construct($component);
$this->_reqParser->maxSize = $maxRequestSize;
}
}

View File

@ -1,8 +1,10 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets; namespace BeyondCode\LaravelWebSockets\Server;
use BeyondCode\LaravelWebSockets\LaravelEcho;
use BeyondCode\LaravelWebSockets\Server\Logger\MessageLogger; use BeyondCode\LaravelWebSockets\Server\Logger\MessageLogger;
use BeyondCode\LaravelWebSockets\Server\WebSocketController;
use Ratchet\WebSocket\WsServer; use Ratchet\WebSocket\WsServer;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
use Ratchet\Http\HttpServerInterface; use Ratchet\Http\HttpServerInterface;
@ -65,7 +67,7 @@ class Router
public function echo() public function echo()
{ {
$this->get('/app/{appKey}', LaravelEcho\WebSocket\PusherServer::class); $this->get('/app/{appKey}', LaravelEcho\Pusher\PusherServer::class);
$this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\FetchChannels::class); $this->get('/apps/{appId}/channels', LaravelEcho\Http\Controllers\FetchChannels::class);
$this->get('/apps/{appId}/channels/{channelName}', LaravelEcho\Http\Controllers\FetchChannel::class); $this->get('/apps/{appId}/channels/{channelName}', LaravelEcho\Http\Controllers\FetchChannel::class);

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets; namespace BeyondCode\LaravelWebSockets\Server;
use Exception; use Exception;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;

View File

@ -5,7 +5,6 @@ namespace BeyondCode\LaravelWebSockets\Server;
use Ratchet\Http\Router; use Ratchet\Http\Router;
use React\Socket\SecureServer; use React\Socket\SecureServer;
use React\Socket\Server; use React\Socket\Server;
use Ratchet\Http\HttpServer;
use Ratchet\Server\IoServer; use Ratchet\Server\IoServer;
use React\EventLoop\LoopInterface; use React\EventLoop\LoopInterface;
use React\EventLoop\Factory as LoopFactory; use React\EventLoop\Factory as LoopFactory;
@ -87,7 +86,7 @@ class WebSocketServer
$app = new OriginCheck($router, config('websockets.allowedOrigins', [])); $app = new OriginCheck($router, config('websockets.allowedOrigins', []));
$httpServer = new HttpServer($app); $httpServer = new HttpServer($app, config('websockets.maxRequestSize'));
return new IoServer($httpServer, $socket, $this->loop); return new IoServer($httpServer, $socket, $this->loop);
} }

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Controllers;
use BeyondCode\LaravelWebSockets\ClientProviders\Client; use BeyondCode\LaravelWebSockets\ClientProviders\Client;
use BeyondCode\LaravelWebSockets\Events\ExceptionThrown; use BeyondCode\LaravelWebSockets\Events\ExceptionThrown;
@ -15,11 +15,11 @@ use Ratchet\Http\HttpServerInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory; use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
abstract class EchoController implements HttpServerInterface abstract class EchoController implements HttpServerInterface
{ {
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager */
protected $channelManager; protected $channelManager;
public function __construct(ChannelManager $channelManager) public function __construct(ChannelManager $channelManager)

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;

View File

@ -1,10 +1,10 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\PresenceChannel; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\PresenceChannel;
class FetchChannels extends EchoController class FetchChannels extends EchoController
{ {

View File

@ -1,11 +1,11 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\PresenceChannel; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\PresenceChannel;
class FetchUsers extends EchoController class FetchUsers extends EchoController
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Http\Controllers; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Controllers;
use BeyondCode\LaravelWebSockets\Events\ApiMessageSent; use BeyondCode\LaravelWebSockets\Events\ApiMessageSent;
use Illuminate\Http\Request; use Illuminate\Http\Request;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Messages;
use BeyondCode\LaravelWebSockets\Events\ClientMessageSent; use BeyondCode\LaravelWebSockets\Events\ClientMessageSent;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use stdClass; use stdClass;
@ -15,7 +15,7 @@ class Message implements RespondableMessage
/** @var \Ratchet\ConnectionInterface */ /** @var \Ratchet\ConnectionInterface */
protected $connection; protected $connection;
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager */
protected $channelManager; protected $channelManager;
public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager) public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager)

View File

@ -1,5 +1,5 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Messages;
interface RespondableMessage interface RespondableMessage
{ {

View File

@ -1,9 +1,9 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Messages;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\PusherMessage; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\PusherMessage;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface; use Ratchet\RFC6455\Messaging\MessageInterface;

View File

@ -1,11 +1,11 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels;
use BeyondCode\LaravelWebSockets\Events\ChannelOccupied; use BeyondCode\LaravelWebSockets\Events\ChannelOccupied;
use BeyondCode\LaravelWebSockets\Events\ChannelVacated; use BeyondCode\LaravelWebSockets\Events\ChannelVacated;
use BeyondCode\LaravelWebSockets\Events\SubscribedToChannel; use BeyondCode\LaravelWebSockets\Events\SubscribedToChannel;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\InvalidSignature; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions\InvalidSignature;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use stdClass; use stdClass;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels;
use ReflectionClass; use ReflectionClass;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use stdClass; use stdClass;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use stdClass; use stdClass;

View File

@ -1,9 +1,9 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use stdClass; use stdClass;
class Dashboard class Dashboard

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions;
class InvalidConnection extends PusherException class InvalidConnection extends PusherException
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions;
class InvalidSignature extends PusherException class InvalidSignature extends PusherException
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions;
use Exception; use Exception;

View File

@ -1,6 +1,6 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions;
class UnknownAppKey extends PusherException class UnknownAppKey extends PusherException
{ {

View File

@ -1,21 +1,22 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher;
use BeyondCode\LaravelWebSockets\Events\ConnectionEstablished; use BeyondCode\LaravelWebSockets\Events\ConnectionEstablished;
use BeyondCode\LaravelWebSockets\WebSocketServer\Messages\RespondableMessageFactory;
use BeyondCode\LaravelWebSockets\QueryParameters; use BeyondCode\LaravelWebSockets\QueryParameters;
use Exception; use Exception;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface; use Ratchet\RFC6455\Messaging\MessageInterface;
use BeyondCode\LaravelWebSockets\WebSocketController; use BeyondCode\LaravelWebSockets\Server\WebSocketController;
use BeyondCode\LaravelWebSockets\ClientProviders\Client; use BeyondCode\LaravelWebSockets\ClientProviders\Client;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\PusherException; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions\PusherException;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\UnknownAppKey; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions\UnknownAppKey;
class PusherServer extends WebSocketController class PusherController extends WebSocketController
{ {
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager */
protected $channelManager; protected $channelManager;
public function __construct(ChannelManager $channelManager) public function __construct(ChannelManager $channelManager)

View File

@ -1,21 +1,21 @@
<?php <?php
namespace BeyondCode\LaravelWebSockets\LaravelEcho\Pusher; namespace BeyondCode\LaravelWebSockets\WebSocketServer\Pusher;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket\RespondableMessage; use BeyondCode\LaravelWebSockets\WebSocketServer\Messages\RespondableMessage;
use Ratchet\ConnectionInterface; use Ratchet\ConnectionInterface;
use stdClass; use stdClass;
class PusherMessage implements RespondableMessage class PusherMessage implements RespondableMessage
{ {
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\stdClass */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\stdClass */
protected $payload; protected $payload;
/** @var \React\Socket\ConnectionInterface */ /** @var \React\Socket\ConnectionInterface */
protected $connection; protected $connection;
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager */
protected $channelManager; protected $channelManager;
public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager) public function __construct(stdClass $payload, ConnectionInterface $connection, ChannelManager $channelManager)

View File

@ -7,12 +7,13 @@ use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboar
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard; use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize; use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize;
use BeyondCode\LaravelWebSockets\Server\Router;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider; use BeyondCode\LaravelWebSockets\ClientProviders\ClientProvider;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Channels\ChannelManager; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Channels\ChannelManager;
class WebSocketsServiceProvider extends ServiceProvider class WebSocketsServiceProvider extends ServiceProvider
{ {

View File

@ -3,21 +3,21 @@
namespace BeyondCode\LaravelWebSockets\Tests; namespace BeyondCode\LaravelWebSockets\Tests;
use BeyondCode\LaravelWebSockets\ClientProviders\Client; use BeyondCode\LaravelWebSockets\ClientProviders\Client;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\InvalidSignature; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions\InvalidSignature;
use BeyondCode\LaravelWebSockets\LaravelEcho\Pusher\Exceptions\UnknownAppKey; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\Exceptions\UnknownAppKey;
use BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket\PusherServer; use BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\PusherController;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message; use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
class ConnectionTest extends TestCase class ConnectionTest extends TestCase
{ {
/** @var \BeyondCode\LaravelWebSockets\LaravelEcho\WebSocket\PusherServer */ /** @var \BeyondCode\LaravelWebSockets\WebSocketServer\Pusher\PusherController */
protected $pusherServer; protected $pusherServer;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->pusherServer = app(PusherServer::class); $this->pusherServer = app(PusherController::class);
} }
/** @test */ /** @test */