Apply fixes from StyleCI (#3)

This commit is contained in:
Marcel Pociot 2018-12-04 22:22:33 +01:00 committed by GitHub
parent b3e5df4835
commit 9ce2cc3ff7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
69 changed files with 294 additions and 334 deletions

View File

@ -64,7 +64,7 @@ return [
* When the clean-command is executed, all recorded statistics older than
* the number of days specified here will be deleted.
*/
'delete_statistics_older_than_days' => 60
'delete_statistics_older_than_days' => 60,
],
/*
@ -89,6 +89,6 @@ return [
/*
* Passphrase for your local_cert file.
*/
'passphrase' => null
'passphrase' => null,
],
];

View File

@ -29,12 +29,12 @@ class App
return app(AppProvider::class)->findById($appId);
}
public static function findByKey(string $appKey): ?App
public static function findByKey(string $appKey): ?self
{
return app(AppProvider::class)->findByKey($appKey);
}
public static function findBySecret(string $appSecret): ?App
public static function findBySecret(string $appSecret): ?self
{
return app(AppProvider::class)->findBySecret($appSecret);
}

View File

@ -71,7 +71,6 @@ class ConfigAppProvider implements AppProvider
->enableClientMessages($appAttributes['enable_client_messages'])
->enableStatistics($appAttributes['enable_statistics']);
return $app;
}
}

View File

@ -8,7 +8,6 @@ use Illuminate\Database\Eloquent\Builder;
class CleanStatistics extends Command
{
protected $signature = 'websockets:clean
{appId? : (optional) The app id that will be cleaned.}';

View File

@ -2,22 +2,20 @@
namespace BeyondCode\LaravelWebSockets\Console;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use React\Socket\Connector;
use Clue\React\Buzz\Browser;
use Illuminate\Console\Command;
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
use React\EventLoop\Factory as LoopFactory;
use React\Socket\Connector;
use BeyondCode\LaravelWebSockets\Statistics\DnsResolver;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Facades\WebSocketsRouter;
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
use BeyondCode\LaravelWebSockets\Server\WebSocketServerFactory;
use BeyondCode\LaravelWebSockets\Server\Logger\ConnectionLogger;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
class StartWebSocketServer extends Command
{
@ -49,7 +47,7 @@ class StartWebSocketServer extends Command
protected function configureStatisticsLogger()
{
$connector = new Connector($this->loop, [
'dns' => new DnsResolver()
'dns' => new DnsResolver(),
]);
$browser = new Browser($this->loop, $connector);
@ -111,7 +109,7 @@ class StartWebSocketServer extends Command
$routes = WebSocketsRouter::getRoutes();
/** 🛰 Start the server 🛰 */
/* 🛰 Start the server 🛰 */
(new WebSocketServerFactory())
->setLoop($this->loop)
->useRoutes($routes)

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\Dashboard;
use stdClass;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use stdClass;
class DashboardLogger
{
@ -85,9 +85,8 @@ class DashboardLogger
'channel' => $channelName,
'data' => [
'type' => $type,
'time' => strftime("%H:%M:%S")
'time' => strftime('%H:%M:%S'),
] + $attributes,
]);
}
}

View File

@ -30,7 +30,7 @@ class DashboardApiController
'api_message_count' => [
'x' => $statisticData->pluck('timestamp'),
'y' => $statisticData->pluck('api_message_count'),
]
],
];
}
}

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use Pusher\Pusher;
use Illuminate\Http\Request;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use Illuminate\Broadcasting\Broadcasters\PusherBroadcaster;
class SendMessage

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\Facades;
use Illuminate\Support\Facades\Facade;
use BeyondCode\LaravelWebSockets\Statistics\Logger\FakeStatisticsLogger;
use BeyondCode\LaravelWebSockets\Statistics\Logger\StatisticsLogger as StatisticsLoggerInterface;
use Illuminate\Support\Facades\Facade;
/** @see \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger */
class StatisticsLogger extends Facade

View File

@ -2,10 +2,6 @@
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Events\ExceptionThrown;
use BeyondCode\LaravelWebSockets\QueryParameters;
use Exception;
use Illuminate\Http\Request;
use GuzzleHttp\Psr7\Response;
@ -14,6 +10,8 @@ use Illuminate\Http\JsonResponse;
use GuzzleHttp\Psr7\ServerRequest;
use Ratchet\Http\HttpServerInterface;
use Psr\Http\Message\RequestInterface;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\QueryParameters;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
@ -50,24 +48,24 @@ abstract class Controller implements HttpServerInterface
$connection->close();
}
function onMessage(ConnectionInterface $from, $msg)
public function onMessage(ConnectionInterface $from, $msg)
{
}
function onClose(ConnectionInterface $connection)
public function onClose(ConnectionInterface $connection)
{
}
function onError(ConnectionInterface $connection, Exception $exception)
public function onError(ConnectionInterface $connection, Exception $exception)
{
if (! $exception instanceof HttpException) {
return;
}
$response = new Response($exception->getStatusCode(), [
'Content-Type' => 'application/json'
'Content-Type' => 'application/json',
], json_encode([
'error' => $exception->getMessage()
'error' => $exception->getMessage(),
]));
$connection->send(\GuzzleHttp\Psr7\str($response));
@ -86,7 +84,6 @@ abstract class Controller implements HttpServerInterface
protected function ensureValidSignature(Request $request)
{
$signature =
"{$request->getMethod()}\n/{$request->path()}\n".
"auth_key={$request->get('auth_key')}".

View File

@ -2,7 +2,6 @@
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\HttpException;

View File

@ -2,7 +2,6 @@
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\PresenceChannel;
@ -26,7 +25,7 @@ class FetchChannelsController extends Controller
return [
'user_count' => count($channel->getUsers()),
];
})->toArray()
})->toArray(),
];
}
}

View File

@ -2,7 +2,6 @@
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Symfony\Component\HttpKernel\Exception\HttpException;
@ -25,7 +24,7 @@ class FetchUsersController extends Controller
return [
'users' => Collection::make($channel->getUsers())->map(function ($user) {
return ['id' => $user->user_id];
})->values()
})->values(),
];
}
}

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\HttpApi\Controllers;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use Illuminate\Http\Request;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
class TriggerEventController extends Controller
{

View File

@ -9,9 +9,9 @@ class ConnectionLogger extends Logger implements ConnectionInterface
/** @var \Ratchet\ConnectionInterface */
protected $connection;
public static function decorate(ConnectionInterface $app): ConnectionLogger
public static function decorate(ConnectionInterface $app): self
{
$logger = app(ConnectionLogger::class);
$logger = app(self::class);
return $logger->setConnection($app);
}
@ -54,11 +54,13 @@ class ConnectionLogger extends Logger implements ConnectionInterface
return $this->connection->$name;
}
public function __isset($name) {
public function __isset($name)
{
return isset($this->connection->$name);
}
public function __unset($name) {
public function __unset($name)
{
unset($this->connection->$name);
}
}

View File

@ -11,9 +11,9 @@ class HttpLogger extends Logger implements MessageComponentInterface
/** @var \Ratchet\Http\HttpServerInterface */
protected $app;
public static function decorate(MessageComponentInterface $app): HttpLogger
public static function decorate(MessageComponentInterface $app): self
{
$logger = app(HttpLogger::class);
$logger = app(self::class);
return $logger->setApp($app);
}
@ -54,5 +54,4 @@ class HttpLogger extends Logger implements MessageComponentInterface
$this->app->onError($connection, $exception);
}
}

View File

@ -2,20 +2,20 @@
namespace BeyondCode\LaravelWebSockets\Server\Logger;
use BeyondCode\LaravelWebSockets\QueryParameters;
use Exception;
use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\QueryParameters;
class WebsocketsLogger extends Logger implements MessageComponentInterface
{
/** @var \Ratchet\Http\HttpServerInterface */
protected $app;
public static function decorate(MessageComponentInterface $app): WebsocketsLogger
public static function decorate(MessageComponentInterface $app): self
{
$logger = app(WebsocketsLogger::class);
$logger = app(self::class);
return $logger->setApp($app);
}
@ -68,5 +68,4 @@ class WebsocketsLogger extends Logger implements MessageComponentInterface
$this->app->onError(ConnectionLogger::decorate($connection), $exception);
}
}

View File

@ -5,8 +5,8 @@ namespace BeyondCode\LaravelWebSockets\Server;
use Ratchet\ConnectionInterface;
use Ratchet\Http\CloseResponseTrait;
use Ratchet\Http\HttpServerInterface;
use Ratchet\MessageComponentInterface;
use Psr\Http\Message\RequestInterface;
use Ratchet\MessageComponentInterface;
class OriginCheck implements HttpServerInterface
{
@ -33,17 +33,17 @@ class OriginCheck implements HttpServerInterface
return $this->_component->onOpen($connection, $request);
}
function onMessage(ConnectionInterface $from, $msg)
public function onMessage(ConnectionInterface $from, $msg)
{
return $this->_component->onMessage($from, $msg);
}
function onClose(ConnectionInterface $connection)
public function onClose(ConnectionInterface $connection)
{
return $this->_component->onClose($connection);
}
function onError(ConnectionInterface $connection, \Exception $e)
public function onError(ConnectionInterface $connection, \Exception $e)
{
return $this->_component->onError($connection, $e);
}

View File

@ -2,17 +2,17 @@
namespace BeyondCode\LaravelWebSockets\Server;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\TriggerEventController;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
use Ratchet\WebSocket\MessageComponentInterface;
use Ratchet\WebSocket\WsServer;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
use BeyondCode\LaravelWebSockets\Server\Logger\WebsocketsLogger;
use BeyondCode\LaravelWebSockets\Exceptions\InvalidWebSocketController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\TriggerEventController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController;
class Router
{

View File

@ -2,17 +2,17 @@
namespace BeyondCode\LaravelWebSockets\Server;
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
use Ratchet\Http\Router;
use React\Socket\SecureServer;
use React\Socket\Server;
use Ratchet\Server\IoServer;
use React\Socket\SecureServer;
use React\EventLoop\LoopInterface;
use React\EventLoop\Factory as LoopFactory;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Console\Output\OutputInterface;
use BeyondCode\LaravelWebSockets\Server\Logger\HttpLogger;
class WebSocketServerFactory
{

View File

@ -2,11 +2,11 @@
namespace BeyondCode\LaravelWebsockets\Statistics\Events;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
class StatisticsUpdated implements ShouldBroadcast
{

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Http\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Events\StatisticsUpdated;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use Illuminate\Http\Request;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use BeyondCode\LaravelWebSockets\Statistics\Events\StatisticsUpdated;
class WebSocketStatisticsEntriesController
{

View File

@ -2,41 +2,31 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Logger;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use GuzzleHttp\Client;
use Ratchet\ConnectionInterface;
class FakeStatisticsLogger implements StatisticsLogger
{
public function webSocketMessage(ConnectionInterface $connection)
{
}
public function apiMessage($appId)
{
}
public function connection(ConnectionInterface $connection)
{
}
public function disconnection(ConnectionInterface $connection)
{
}
protected function initializeStatistics($id)
{
}
public function save()
{
}
}

View File

@ -2,13 +2,13 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Logger;
use Clue\React\Buzz\Browser;
use Ratchet\ConnectionInterface;
use function GuzzleHttp\Psr7\stream_for;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Statistic;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Clue\React\Buzz\Browser;
use function GuzzleHttp\Psr7\stream_for;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
class HttpStatisticsLogger implements StatisticsLogger
{
@ -68,13 +68,12 @@ class HttpStatisticsLogger implements StatisticsLogger
public function save()
{
foreach ($this->statistics as $appId => $statistic) {
if (! $statistic->isEnabled()) {
continue;
}
$postData = array_merge($statistic->toArray(), [
'secret' => App::findById($appId)->secret
'secret' => App::findById($appId)->secret,
]);
$this

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebSockets\Statistics\Rules;
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use Illuminate\Contracts\Validation\Rule;
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
class AppId implements Rule
{
@ -17,4 +17,5 @@ class AppId implements Rule
public function message()
{
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppProvider returns an app for this id.';
}}
}
}

View File

@ -2,11 +2,10 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Channels;
use stdClass;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
use Illuminate\Support\Collection;
use Ratchet\ConnectionInterface;
use stdClass;
class Channel
{
@ -53,7 +52,7 @@ class Channel
$connection->send(json_encode([
'event' => 'pusher_internal:subscription_succeeded',
'channel' => $this->channelName
'channel' => $this->channelName,
]));
}
@ -108,7 +107,7 @@ class Channel
{
return [
'occupied' => count($this->subscribedConnections) > 0,
'subscription_count' => count($this->subscribedConnections)
'subscription_count' => count($this->subscribedConnections),
];
}
}

View File

@ -60,12 +60,12 @@ class ChannelManager
return;
}
/**
/*
* Remove the connection from all channels.
*/
collect(array_get($this->channels, $connection->app->id, []))->each->unsubscribe($connection);
/**
/*
* Unset all channels that have no connections so we don't leak memory.
*/
collect(array_get($this->channels, $connection->app->id, []))
@ -76,6 +76,6 @@ class ChannelManager
if (count(array_get($this->channels, $connection->app->id, [])) === 0) {
unset($this->channels[$connection->app->id]);
};
}
}
}

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Channels;
use Ratchet\ConnectionInterface;
use stdClass;
use Ratchet\ConnectionInterface;
class PresenceChannel extends Channel
{
@ -30,13 +30,13 @@ class PresenceChannel extends Channel
$connection->send(json_encode([
'event' => 'pusher_internal:subscription_succeeded',
'channel' => $this->channelName,
'data' => json_encode($this->getChannelData())
'data' => json_encode($this->getChannelData()),
]));
$this->broadcastToOthers($connection, [
'event' => 'pusher_internal:member_added',
'channel' => $this->channelName,
'data' => json_encode($channelData)
'data' => json_encode($channelData),
]);
}
@ -52,8 +52,8 @@ class PresenceChannel extends Channel
'event' => 'pusher_internal:member_removed',
'channel' => $this->channelName,
'data' => json_encode([
'user_id' => $this->users[$connection->socketId]->user_id
])
'user_id' => $this->users[$connection->socketId]->user_id,
]),
]);
unset($this->users[$connection->socketId]);

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Channels;
use Ratchet\ConnectionInterface;
use stdClass;
use Ratchet\ConnectionInterface;
class PrivateChannel extends Channel
{

View File

@ -12,8 +12,8 @@ class WebSocketException extends Exception
'event' => 'pusher:error',
'data' => [
'message' => $this->getMessage(),
'code' => $this->getCode()
]
'code' => $this->getCode(),
],
];
}
}

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Ratchet\ConnectionInterface;
use stdClass;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
class PusherChannelProtocolMessage implements PusherMessage
{

View File

@ -2,11 +2,10 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Events\ClientMessageSent;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Ratchet\ConnectionInterface;
use stdClass;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
class PusherClientMessage implements PusherMessage
{

View File

@ -1,4 +1,5 @@
<?php
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
interface PusherMessage

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\WebSockets\Messages;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
class PusherMessageFactory
{

View File

@ -2,18 +2,18 @@
namespace BeyondCode\LaravelWebSockets\WebSockets;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\WebSocketException;
use BeyondCode\LaravelWebSockets\WebSockets\Messages\PusherMessageFactory;
use BeyondCode\LaravelWebSockets\QueryParameters;
use Exception;
use Ratchet\ConnectionInterface;
use Ratchet\RFC6455\Messaging\MessageInterface;
use BeyondCode\LaravelWebSockets\Apps\App;
use Ratchet\RFC6455\Messaging\MessageInterface;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\QueryParameters;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Dashboard\DashboardLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
use Ratchet\WebSocket\MessageComponentInterface;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\WebSocketException;
use BeyondCode\LaravelWebSockets\WebSockets\Messages\PusherMessageFactory;
class WebSocketHandler implements MessageComponentInterface
{
@ -75,7 +75,7 @@ class WebSocketHandler implements MessageComponentInterface
protected function generateSocketId(ConnectionInterface $connection)
{
$socketId = sprintf("%d.%d", random_int(1, 1000000000), random_int(1, 1000000000));
$socketId = sprintf('%d.%d', random_int(1, 1000000000), random_int(1, 1000000000));
$connection->socketId = $socketId;
@ -89,7 +89,7 @@ class WebSocketHandler implements MessageComponentInterface
'data' => json_encode([
'socket_id' => $connection->socketId,
'activity_timeout' => 30,
])
]),
]));
DashboardLogger::connection($connection);

View File

@ -2,21 +2,19 @@
namespace BeyondCode\LaravelWebSockets;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard;
use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics;
use BeyondCode\LaravelWebSockets\Server\Router;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Route;
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use Illuminate\Support\ServiceProvider;
use BeyondCode\LaravelWebSockets\Server\Router;
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use Illuminate\Support\Str;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\ShowDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
use BeyondCode\LaravelWebSockets\Dashboard\Http\Middleware\Authorize as AuthorizeDashboard;
use BeyondCode\LaravelWebSockets\Statistics\Http\Middleware\Authorize as AuthorizeStatistics;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
class WebSocketsServiceProvider extends ServiceProvider
{

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
class ChannelTest extends TestCase
{
@ -15,7 +15,7 @@ class ChannelTest extends TestCase
$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'channel' => 'basic-channel'
'channel' => 'basic-channel',
],
]));
@ -24,7 +24,7 @@ class ChannelTest extends TestCase
$this->pusherServer->onMessage($connection, $message);
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'basic-channel'
'channel' => 'basic-channel',
]);
}
@ -40,7 +40,7 @@ class ChannelTest extends TestCase
$message = new Message(json_encode([
'event' => 'pusher:unsubscribe',
'data' => [
'channel' => 'test-channel'
'channel' => 'test-channel',
],
]));
@ -108,7 +108,7 @@ class ChannelTest extends TestCase
$channel->broadcast([
'event' => 'broadcasted-event',
'channel' => 'test-channel'
'channel' => 'test-channel',
]);
$connection1->assertSentEvent('broadcasted-event');
@ -125,7 +125,7 @@ class ChannelTest extends TestCase
$channel->broadcastToOthers($connection1, [
'event' => 'broadcasted-event',
'channel' => 'test-channel'
'channel' => 'test-channel',
]);
$connection1->assertNotSentEvent('broadcasted-event');

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
class PresenceChannelTest extends TestCase
@ -19,7 +19,7 @@ class PresenceChannelTest extends TestCase
'event' => 'pusher:subscribe',
'data' => [
'auth' => 'invalid',
'channel' => 'presence-channel'
'channel' => 'presence-channel',
],
]));
@ -38,8 +38,8 @@ class PresenceChannelTest extends TestCase
$channelData = [
'user_id' => 1,
'user_info' => [
'name' => 'Marcel'
]
'name' => 'Marcel',
],
];
$signature = "{$connection->socketId}:presence-channel:".json_encode($channelData);
@ -49,7 +49,7 @@ class PresenceChannelTest extends TestCase
'data' => [
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
'channel' => 'presence-channel',
'channel_data' => json_encode($channelData)
'channel_data' => json_encode($channelData),
],
]));

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebsockets\Tests\Channels;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\InvalidSignature;
class PrivateChannelTest extends TestCase
@ -19,7 +19,7 @@ class PrivateChannelTest extends TestCase
'event' => 'pusher:subscribe',
'data' => [
'auth' => 'invalid',
'channel' => 'private-channel'
'channel' => 'private-channel',
],
]));
@ -43,14 +43,14 @@ class PrivateChannelTest extends TestCase
'event' => 'pusher:subscribe',
'data' => [
'auth' => "{$connection->app->key}:{$hashedAppSecret}",
'channel' => 'private-channel'
'channel' => 'private-channel',
],
]));
$this->pusherServer->onMessage($connection, $message);
$connection->assertSentEvent('pusher_internal:subscription_succeeded', [
'channel' => 'private-channel'
'channel' => 'private-channel',
]);
}
}

View File

@ -3,8 +3,8 @@
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Exceptions\InvalidApp;
class AppTest extends TestCase
{

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
class ConfigAppProviderTest extends TestCase
{

View File

@ -3,14 +3,13 @@
namespace BeyondCode\LaravelWebSockets\Tests\Commands;
use Artisan;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use Carbon\Carbon;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use Illuminate\Support\Collection;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
class CleanStatisticsTest extends TestCase
{
public function setUp()
{
parent::setUp();
@ -20,7 +19,6 @@ class CleanStatisticsTest extends TestCase
$this->app['config']->set('websockets.statistics.delete_statistics_older_than_days', 31);
}
/** @test */
public function it_can_clean_the_statistics()
{

View File

@ -3,12 +3,11 @@
namespace BeyondCode\LaravelWebSockets\Tests;
use BeyondCode\LaravelWebSockets\Apps\App;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\WebSockets\Exceptions\UnknownAppKey;
class ConnectionTest extends TestCase
{
/** @test */
public function unknown_app_keys_can_not_connect()
{

View File

@ -2,16 +2,15 @@
namespace BeyondCode\LaravelWebSockets\Tests\HttpApi;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use Symfony\Component\HttpKernel\Exception\HttpException;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController;
class FetchChannelTest extends TestCase
{
/** @test */
public function invalid_signatures_can_not_access_the_api()
{
@ -74,7 +73,7 @@ class FetchChannelTest extends TestCase
$this->assertSame([
'occupied' => true,
'subscription_count' => 2
'subscription_count' => 2,
], json_decode($response->getContent(), true));
}
@ -113,8 +112,7 @@ class FetchChannelTest extends TestCase
$this->assertSame([
'occupied' => true,
'subscription_count' => 2
'subscription_count' => 2,
], json_decode($response->getContent(), true));
}
}

View File

@ -2,17 +2,15 @@
namespace BeyondCode\LaravelWebSockets\Tests\HttpApi;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use Symfony\Component\HttpKernel\Exception\HttpException;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelsController;
class FetchChannelsTest extends TestCase
{
/** @test */
public function invalid_signatures_can_not_access_the_api()
{
@ -77,10 +75,9 @@ class FetchChannelsTest extends TestCase
$this->assertSame([
'channels' => [
'presence-channel' => [
'user_count' => 3
]
]
'user_count' => 3,
],
],
], json_decode($response->getContent(), true));
}
}

View File

@ -2,17 +2,14 @@
namespace BeyondCode\LaravelWebSockets\Tests\HttpApi;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchChannelController;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use GuzzleHttp\Psr7\Request;
use Illuminate\Http\JsonResponse;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use Symfony\Component\HttpKernel\Exception\HttpException;
use BeyondCode\LaravelWebSockets\HttpApi\Controllers\FetchUsersController;
class FetchUsersTest extends TestCase
{
/** @test */
public function invalid_signatures_can_not_access_the_api()
{
@ -137,9 +134,9 @@ class FetchUsersTest extends TestCase
$this->assertSame([
'users' => [
[
'id' => 1
]
]
'id' => 1,
],
],
], json_decode($response->getContent(), true));
}
}

View File

@ -16,7 +16,7 @@ class PusherClientMessageTest extends TestCase
'event' => 'client-test',
'channel' => 'test-channel',
'data' => [
'client-event' => 'test'
'client-event' => 'test',
],
]));
@ -46,7 +46,7 @@ class PusherClientMessageTest extends TestCase
'event' => 'client-test',
'channel' => 'test-channel',
'data' => [
'client-event' => 'test'
'client-event' => 'test',
],
]));
@ -56,8 +56,8 @@ class PusherClientMessageTest extends TestCase
$connection2->assertSentEvent('client-test', [
'data' => [
'client-event' => 'test'
]
'client-event' => 'test',
],
]);
}
}

View File

@ -2,7 +2,6 @@
namespace BeyondCode\LaravelWebSockets\Tests\Mocks;
class Message extends \Ratchet\RFC6455\Messaging\Message
{
protected $payload;

View File

@ -2,9 +2,9 @@
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
use BeyondCode\LaravelWebSockets\Statistics\Http\Controllers\WebSocketStatisticsEntriesController;
class WebSocketsStatisticsControllerTest extends TestCase
{

View File

@ -2,8 +2,8 @@
namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Rules;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
use BeyondCode\LaravelWebSockets\Statistics\Rules\AppId;
class AppIdTest extends TestCase
{

View File

@ -2,16 +2,14 @@
namespace BeyondCode\LaravelWebSockets\Tests;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider;
use Illuminate\Support\Facades\Route;
use Ratchet\ConnectionInterface;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\Mocks\Connection;
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
use BeyondCode\LaravelWebSockets\WebSocketsServiceProvider;
use BeyondCode\LaravelWebSockets\WebSockets\WebSocketHandler;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
abstract class TestCase extends \Orchestra\Testbench\TestCase
{
@ -53,8 +51,6 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
include_once __DIR__.'/../database/migrations/create_websockets_statistics_entries_table.php.stub';
(new \CreateWebSocketsStatisticsEntriesTable())->up();
}
protected function getWebSocketConnection(string $url = '/?appKey=TestKey'): Connection
@ -78,7 +74,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$message = new Message(json_encode([
'event' => 'pusher:subscribe',
'data' => [
'channel' => $channel
'channel' => $channel,
],
]));
@ -97,8 +93,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
$channelData = [
'user_id' => 1,
'user_info' => [
'name' => 'Marcel'
]
'name' => 'Marcel',
],
];
$signature = "{$connection->socketId}:{$channel}:".json_encode($channelData);
@ -108,7 +104,7 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
'data' => [
'auth' => $connection->app->key.':'.hash_hmac('sha256', $signature, $connection->app->secret),
'channel' => $channel,
'channel_data' => json_encode($channelData)
'channel_data' => json_encode($channelData),
],
]));