From 3a0ba1d5949d2c71124bdb84162864d6d985055b Mon Sep 17 00:00:00 2001 From: freek Date: Mon, 26 Nov 2018 00:47:47 +0100 Subject: [PATCH] nitpicks --- src/LaravelEcho/Pusher/Dashboard.php | 57 ++++++++----------- .../Exceptions/InvalidConnectionException.php | 1 + .../Exceptions/InvalidSignatureException.php | 1 + src/WebSocketController.php | 1 - 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/src/LaravelEcho/Pusher/Dashboard.php b/src/LaravelEcho/Pusher/Dashboard.php index 8a325e0..c115864 100644 --- a/src/LaravelEcho/Pusher/Dashboard.php +++ b/src/LaravelEcho/Pusher/Dashboard.php @@ -9,19 +9,12 @@ use stdClass; class Dashboard { const LOG_CHANNEL_PREFIX = 'private-websockets-dashboard-'; - const TYPE_DISCONNECTION = 'disconnection'; - const TYPE_CONNECTION = 'connection'; - const TYPE_VACATED = 'vacated'; - const TYPE_OCCUPIED = 'occupied'; - const TYPE_SUBSCRIBED = 'subscribed'; - const TYPE_CLIENT_MESSAGE = 'client_message'; - const TYPE_API_MESSAGE = 'api_message'; public static function connection(ConnectionInterface $connection) @@ -29,61 +22,61 @@ class Dashboard /** @var \GuzzleHttp\Psr7\Request $request */ $request = $connection->httpRequest; - self::log($connection->client->appId, self::TYPE_CONNECTION, [ + static::log($connection->client->appId, static::TYPE_CONNECTION, [ 'details' => "Origin: {$request->getUri()->getScheme()}://{$request->getUri()->getHost()}", 'socketId' => $connection->socketId, ]); } - public static function disconnection(ConnectionInterface $connection) - { - self::log($connection->client->appId, self::TYPE_DISCONNECTION, [ - 'socketId' => $connection->socketId - ]); - } - - public static function vacated(ConnectionInterface $connection, string $channelId) - { - self::log($connection->client->appId, self::TYPE_VACATED, [ - 'details' => "Channel: {$channelId}" - ]); - } - public static function occupied(ConnectionInterface $connection, string $channelId) { - self::log($connection->client->appId, self::TYPE_OCCUPIED, [ - 'details' => "Channel: {$channelId}" + static::log($connection->client->appId, static::TYPE_OCCUPIED, [ + 'details' => "Channel: {$channelId}", ]); } public static function subscribed(ConnectionInterface $connection, string $channelId) { - self::log($connection->client->appId, self::TYPE_SUBSCRIBED, [ + static::log($connection->client->appId, static::TYPE_SUBSCRIBED, [ 'socketId' => $connection->socketId, - 'details' => "Channel: {$channelId}" + 'details' => "Channel: {$channelId}", ]); } public static function clientMessage(ConnectionInterface $connection, stdClass $payload) { - self::log($connection->client->appId, self::TYPE_CLIENT_MESSAGE, [ + static::log($connection->client->appId, static::TYPE_CLIENT_MESSAGE, [ 'details' => "Channel: {$payload->channel}, Event: {$payload->event}", 'socketId' => $connection->socketId, - 'data' => json_encode($payload) + 'data' => json_encode($payload), + ]); + } + + public static function disconnection(ConnectionInterface $connection) + { + static::log($connection->client->appId, static::TYPE_DISCONNECTION, [ + 'socketId' => $connection->socketId, + ]); + } + + public static function vacated(ConnectionInterface $connection, string $channelId) + { + static::log($connection->client->appId, static::TYPE_VACATED, [ + 'details' => "Channel: {$channelId}", ]); } public static function apiMessage($appId, string $channel, string $event, string $payload) { - self::log($appId, self::TYPE_API_MESSAGE, [ + static::log($appId, static::TYPE_API_MESSAGE, [ 'details' => "Channel: {$channel}, Event: {$event}", - 'data' => $payload + 'data' => $payload, ]); } public static function log($appId, string $type, array $attributes = []) { - $channelId = self::LOG_CHANNEL_PREFIX . $type; + $channelId = static::LOG_CHANNEL_PREFIX . $type; $channel = app(ChannelManager::class)->find($appId, $channelId); @@ -93,7 +86,7 @@ class Dashboard 'data' => [ 'type' => $type, 'time' => strftime("%H:%M:%S") - ] + $attributes + ] + $attributes, ]); } diff --git a/src/LaravelEcho/Pusher/Exceptions/InvalidConnectionException.php b/src/LaravelEcho/Pusher/Exceptions/InvalidConnectionException.php index 143270c..a996bc4 100644 --- a/src/LaravelEcho/Pusher/Exceptions/InvalidConnectionException.php +++ b/src/LaravelEcho/Pusher/Exceptions/InvalidConnectionException.php @@ -7,6 +7,7 @@ class InvalidConnectionException extends PusherException public function __construct() { $this->message = 'Invalid Connection'; + $this->code = 4009; } } \ No newline at end of file diff --git a/src/LaravelEcho/Pusher/Exceptions/InvalidSignatureException.php b/src/LaravelEcho/Pusher/Exceptions/InvalidSignatureException.php index 0962543..ad71243 100644 --- a/src/LaravelEcho/Pusher/Exceptions/InvalidSignatureException.php +++ b/src/LaravelEcho/Pusher/Exceptions/InvalidSignatureException.php @@ -7,6 +7,7 @@ class InvalidSignatureException extends PusherException public function __construct() { $this->message = 'Invalid Signature'; + $this->code = 4009; } } \ No newline at end of file diff --git a/src/WebSocketController.php b/src/WebSocketController.php index 0489e7b..aa2b6cd 100644 --- a/src/WebSocketController.php +++ b/src/WebSocketController.php @@ -17,7 +17,6 @@ class WebSocketController implements MessageComponentInterface { } - function onClose(ConnectionInterface $connection) { }