@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | $deferred = new Deferred(); |
| 43 | 43 | |
| 44 | 44 | $this->database->query('SELECT * FROM `'.$this->getTableName().'`') |
| 45 | - ->then(function (QueryResult $result) use ($deferred) { |
|
| 45 | + ->then(function(QueryResult $result) use ($deferred) { |
|
| 46 | 46 | $deferred->resolve($result->resultRows); |
| 47 | - }, function ($error) use ($deferred) { |
|
| 47 | + }, function($error) use ($deferred) { |
|
| 48 | 48 | $deferred->reject($error); |
| 49 | 49 | }); |
| 50 | 50 | |
@@ -62,9 +62,9 @@ discard block |
||
| 62 | 62 | $deferred = new Deferred(); |
| 63 | 63 | |
| 64 | 64 | $this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `id` = ?', [$appId]) |
| 65 | - ->then(function (QueryResult $result) use ($deferred) { |
|
| 65 | + ->then(function(QueryResult $result) use ($deferred) { |
|
| 66 | 66 | $deferred->resolve($this->convertIntoApp($result->resultRows[0])); |
| 67 | - }, function ($error) use ($deferred) { |
|
| 67 | + }, function($error) use ($deferred) { |
|
| 68 | 68 | $deferred->reject($error); |
| 69 | 69 | }); |
| 70 | 70 | |
@@ -82,9 +82,9 @@ discard block |
||
| 82 | 82 | $deferred = new Deferred(); |
| 83 | 83 | |
| 84 | 84 | $this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `key` = ?', [$appKey]) |
| 85 | - ->then(function (QueryResult $result) use ($deferred) { |
|
| 85 | + ->then(function(QueryResult $result) use ($deferred) { |
|
| 86 | 86 | $deferred->resolve($this->convertIntoApp($result->resultRows[0])); |
| 87 | - }, function ($error) use ($deferred) { |
|
| 87 | + }, function($error) use ($deferred) { |
|
| 88 | 88 | $deferred->reject($error); |
| 89 | 89 | }); |
| 90 | 90 | |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | $deferred = new Deferred(); |
| 103 | 103 | |
| 104 | 104 | $this->database->query('SELECT * from `'.$this->getTableName().'` WHERE `secret` = ?', [$appSecret]) |
| 105 | - ->then(function (QueryResult $result) use ($deferred) { |
|
| 105 | + ->then(function(QueryResult $result) use ($deferred) { |
|
| 106 | 106 | $deferred->resolve($this->convertIntoApp($result->resultRows[0])); |
| 107 | - }, function ($error) use ($deferred) { |
|
| 107 | + }, function($error) use ($deferred) { |
|
| 108 | 108 | $deferred->reject($error); |
| 109 | 109 | }); |
| 110 | 110 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | protected function convertIntoApp(?array $appAttributes): ?App |
| 121 | 121 | { |
| 122 | - if (! $appAttributes) { |
|
| 122 | + if (!$appAttributes) { |
|
| 123 | 123 | return null; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -160,9 +160,9 @@ discard block |
||
| 160 | 160 | $this->database->query( |
| 161 | 161 | 'INSERT INTO `'.$this->getTableName().'` (`id`, `key`, `secret`, `name`, `enable_client_messages`, `enable_statistics`, `allowed_origins`, `capacity`) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', |
| 162 | 162 | [$appData['id'], $appData['key'], $appData['secret'], $appData['name'], $appData['enable_client_messages'], $appData['enable_statistics'], $appData['allowed_origins'] ?? '', $appData['capacity'] ?? null]) |
| 163 | - ->then(function () use ($deferred) { |
|
| 163 | + ->then(function() use ($deferred) { |
|
| 164 | 164 | $deferred->resolve(); |
| 165 | - }, function ($error) use ($deferred) { |
|
| 165 | + }, function($error) use ($deferred) { |
|
| 166 | 166 | $deferred->reject($error); |
| 167 | 167 | }); |
| 168 | 168 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public function all(): PromiseInterface |
| 34 | 34 | { |
| 35 | 35 | return resolvePromise($this->apps |
| 36 | - ->map(function (array $appAttributes) { |
|
| 36 | + ->map(function(array $appAttributes) { |
|
| 37 | 37 | return $this->convertIntoApp($appAttributes); |
| 38 | 38 | }) |
| 39 | 39 | ->toArray()); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | protected function convertIntoApp(?array $appAttributes): ?App |
| 98 | 98 | { |
| 99 | - if (! $appAttributes) { |
|
| 99 | + if (!$appAttributes) { |
|
| 100 | 100 | return null; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function unsubscribe(ConnectionInterface $connection): PromiseInterface |
| 124 | 124 | { |
| 125 | - if (! $this->hasConnection($connection)) { |
|
| 125 | + if (!$this->hasConnection($connection)) { |
|
| 126 | 126 | return Helpers::createFulfilledPromise(false); |
| 127 | 127 | } |
| 128 | 128 | |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | public function broadcast($appId, stdClass $payload, bool $replicate = true): bool |
| 171 | 171 | { |
| 172 | 172 | collect($this->getConnections()) |
| 173 | - ->each(function ($connection) use ($payload) { |
|
| 173 | + ->each(function($connection) use ($payload) { |
|
| 174 | 174 | $connection->send(json_encode($payload)); |
| 175 | 175 | $this->channelManager->connectionPonged($connection); |
| 176 | 176 | }); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | return $this->broadcast($appId, $payload, false); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - collect($this->getConnections())->each(function (ConnectionInterface $connection) use ($socketId, $payload) { |
|
| 216 | + collect($this->getConnections())->each(function(ConnectionInterface $connection) use ($socketId, $payload) { |
|
| 217 | 217 | if ($connection->socketId !== $socketId) { |
| 218 | 218 | $connection->send(json_encode($payload)); |
| 219 | 219 | $this->channelManager->connectionPonged($connection); |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | $signature .= ":{$payload->channel_data}"; |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - if (! hash_equals( |
|
| 258 | + if (!hash_equals( |
|
| 259 | 259 | hash_hmac('sha256', $signature, $connection->app->secret), |
| 260 | 260 | Str::after($payload->auth, ':')) |
| 261 | 261 | ) { |
@@ -34,10 +34,10 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | $this->channelManager |
| 36 | 36 | ->userJoinedPresenceChannel($connection, $user, $this->getName(), $payload) |
| 37 | - ->then(function () use ($connection) { |
|
| 37 | + ->then(function() use ($connection) { |
|
| 38 | 38 | $this->channelManager |
| 39 | 39 | ->getChannelMembers($connection->app->id, $this->getName()) |
| 40 | - ->then(function ($users) use ($connection) { |
|
| 40 | + ->then(function($users) use ($connection) { |
|
| 41 | 41 | $hash = []; |
| 42 | 42 | |
| 43 | 43 | foreach ($users as $socketId => $user) { |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | 'channel' => $this->getName(), |
| 50 | 50 | 'data' => json_encode([ |
| 51 | 51 | 'presence' => [ |
| 52 | - 'ids' => collect($users)->map(function ($user) { |
|
| 52 | + 'ids' => collect($users)->map(function($user) { |
|
| 53 | 53 | return (string) $user->user_id; |
| 54 | 54 | })->values(), |
| 55 | 55 | 'hash' => $hash, |
@@ -59,14 +59,14 @@ discard block |
||
| 59 | 59 | ])); |
| 60 | 60 | }); |
| 61 | 61 | }) |
| 62 | - ->then(function () use ($connection, $user, $payload) { |
|
| 62 | + ->then(function() use ($connection, $user, $payload) { |
|
| 63 | 63 | // The `pusher_internal:member_added` event is triggered when a user joins a channel. |
| 64 | 64 | // It's quite possible that a user can have multiple connections to the same channel |
| 65 | 65 | // (for example by having multiple browser tabs open) |
| 66 | 66 | // and in this case the events will only be triggered when the first tab is opened. |
| 67 | 67 | $this->channelManager |
| 68 | 68 | ->getMemberSockets($user->user_id, $connection->app->id, $this->getName()) |
| 69 | - ->then(function ($sockets) use ($payload, $connection, $user) { |
|
| 69 | + ->then(function($sockets) use ($payload, $connection, $user) { |
|
| 70 | 70 | if (count($sockets) === 1) { |
| 71 | 71 | $memberAddedPayload = [ |
| 72 | 72 | 'event' => 'pusher_internal:member_added', |
@@ -110,24 +110,24 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | return $this->channelManager |
| 112 | 112 | ->getChannelMember($connection, $this->getName()) |
| 113 | - ->then(function ($user) { |
|
| 113 | + ->then(function($user) { |
|
| 114 | 114 | return @json_decode($user); |
| 115 | 115 | }) |
| 116 | - ->then(function ($user) use ($connection) { |
|
| 117 | - if (! $user) { |
|
| 116 | + ->then(function($user) use ($connection) { |
|
| 117 | + if (!$user) { |
|
| 118 | 118 | return Helpers::createFulfilledPromise(true); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | return $this->channelManager |
| 122 | 122 | ->userLeftPresenceChannel($connection, $user, $this->getName()) |
| 123 | - ->then(function () use ($connection, $user) { |
|
| 123 | + ->then(function() use ($connection, $user) { |
|
| 124 | 124 | // The `pusher_internal:member_removed` is triggered when a user leaves a channel. |
| 125 | 125 | // It's quite possible that a user can have multiple connections to the same channel |
| 126 | 126 | // (for example by having multiple browser tabs open) |
| 127 | 127 | // and in this case the events will only be triggered when the last one is closed. |
| 128 | 128 | return $this->channelManager |
| 129 | 129 | ->getMemberSockets($user->user_id, $connection->app->id, $this->getName()) |
| 130 | - ->then(function ($sockets) use ($connection, $user) { |
|
| 130 | + ->then(function($sockets) use ($connection, $user) { |
|
| 131 | 131 | if (count($sockets) === 0) { |
| 132 | 132 | $memberRemovedPayload = [ |
| 133 | 133 | 'event' => 'pusher_internal:member_removed', |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | }); |
| 153 | 153 | }); |
| 154 | 154 | }) |
| 155 | - ->then(function () use ($truth) { |
|
| 155 | + ->then(function() use ($truth) { |
|
| 156 | 156 | return $truth; |
| 157 | 157 | }); |
| 158 | 158 | } |
@@ -30,13 +30,13 @@ discard block |
||
| 30 | 30 | if ($this->seconds > 0) { |
| 31 | 31 | $this->redis |
| 32 | 32 | ->set($this->name, $this->owner, 'EX', $this->seconds, 'NX') |
| 33 | - ->then(function ($result) use ($promise) { |
|
| 33 | + ->then(function($result) use ($promise) { |
|
| 34 | 34 | $promise->resolve($result === true); |
| 35 | 35 | }); |
| 36 | 36 | } else { |
| 37 | 37 | $this->redis |
| 38 | 38 | ->setnx($this->name, $this->owner) |
| 39 | - ->then(function ($result) use ($promise) { |
|
| 39 | + ->then(function($result) use ($promise) { |
|
| 40 | 40 | $promise->resolve($result === 1); |
| 41 | 41 | }); |
| 42 | 42 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $promise = new Deferred(); |
| 50 | 50 | |
| 51 | 51 | $this->acquire() |
| 52 | - ->then(function ($result) use ($callback, $promise) { |
|
| 52 | + ->then(function($result) use ($callback, $promise) { |
|
| 53 | 53 | if ($result) { |
| 54 | 54 | try { |
| 55 | 55 | $callback(); |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | protected function registerEventLoop() |
| 83 | 83 | { |
| 84 | - $this->app->singleton(LoopInterface::class, function () { |
|
| 84 | + $this->app->singleton(LoopInterface::class, function() { |
|
| 85 | 85 | return Factory::create(); |
| 86 | 86 | }); |
| 87 | 87 | } |
@@ -93,14 +93,14 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | protected function registerAsyncRedisQueueDriver() |
| 95 | 95 | { |
| 96 | - Queue::extend('async-redis', function () { |
|
| 96 | + Queue::extend('async-redis', function() { |
|
| 97 | 97 | return new AsyncRedisConnector($this->app['redis']); |
| 98 | 98 | }); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | protected function registerSQLiteDatabase() |
| 102 | 102 | { |
| 103 | - $this->app->singleton(DatabaseInterface::class, function () { |
|
| 103 | + $this->app->singleton(DatabaseInterface::class, function() { |
|
| 104 | 104 | $factory = new SQLiteFactory($this->app->make(LoopInterface::class)); |
| 105 | 105 | |
| 106 | 106 | $database = $factory->openLazy( |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | |
| 125 | 125 | protected function registerMySqlDatabase() |
| 126 | 126 | { |
| 127 | - $this->app->singleton(ConnectionInterface::class, function () { |
|
| 127 | + $this->app->singleton(ConnectionInterface::class, function() { |
|
| 128 | 128 | $factory = new MySQLFactory($this->app->make(LoopInterface::class)); |
| 129 | 129 | |
| 130 | 130 | $connectionKey = 'database.connections.'.config('websockets.managers.mysql.connection'); |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | */ |
| 147 | 147 | protected function registerStatistics() |
| 148 | 148 | { |
| 149 | - $this->app->singleton(StatisticsStore::class, function ($app) { |
|
| 149 | + $this->app->singleton(StatisticsStore::class, function($app) { |
|
| 150 | 150 | $config = $app['config']['websockets']; |
| 151 | 151 | $class = $config['statistics']['store']; |
| 152 | 152 | |
| 153 | 153 | return new $class; |
| 154 | 154 | }); |
| 155 | 155 | |
| 156 | - $this->app->singleton(StatisticsCollector::class, function ($app) { |
|
| 156 | + $this->app->singleton(StatisticsCollector::class, function($app) { |
|
| 157 | 157 | $config = $app['config']['websockets']; |
| 158 | 158 | $replicationMode = $config['replication']['mode'] ?? 'local'; |
| 159 | 159 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | protected function registerRouter() |
| 200 | 200 | { |
| 201 | - $this->app->singleton('websockets.router', function () { |
|
| 201 | + $this->app->singleton('websockets.router', function() { |
|
| 202 | 202 | return new Router; |
| 203 | 203 | }); |
| 204 | 204 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | protected function registerManagers() |
| 212 | 212 | { |
| 213 | - $this->app->singleton(Contracts\AppManager::class, function ($app) { |
|
| 213 | + $this->app->singleton(Contracts\AppManager::class, function($app) { |
|
| 214 | 214 | $config = $app['config']['websockets']; |
| 215 | 215 | |
| 216 | 216 | return $this->app->make($config['managers']['app']); |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | 'prefix' => config('websockets.dashboard.path'), |
| 230 | 230 | 'as' => 'laravel-websockets.', |
| 231 | 231 | 'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]), |
| 232 | - ], function () { |
|
| 232 | + ], function() { |
|
| 233 | 233 | Route::get('/', ShowDashboard::class)->name('dashboard'); |
| 234 | 234 | Route::get('/apps', ShowApps::class)->name('apps'); |
| 235 | 235 | Route::post('/apps', StoreApp::class)->name('apps.store'); |
@@ -246,14 +246,14 @@ discard block |
||
| 246 | 246 | */ |
| 247 | 247 | protected function registerDashboardGate() |
| 248 | 248 | { |
| 249 | - Gate::define('viewWebSocketsDashboard', function ($user = null) { |
|
| 249 | + Gate::define('viewWebSocketsDashboard', function($user = null) { |
|
| 250 | 250 | return $this->app->environment('local'); |
| 251 | 251 | }); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | protected function registerWebSocketHandler() |
| 255 | 255 | { |
| 256 | - $this->app->singleton('websockets.handler', function () { |
|
| 256 | + $this->app->singleton('websockets.handler', function() { |
|
| 257 | 257 | return app(config('websockets.handlers.websocket')); |
| 258 | 258 | }); |
| 259 | 259 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('websockets_statistics_entries', function (Blueprint $table) { |
|
| 16 | + Schema::create('websockets_statistics_entries', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('app_id'); |
| 19 | 19 | $table->integer('peak_connections_count'); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('websockets_apps', function (Blueprint $table) { |
|
| 16 | + Schema::create('websockets_apps', function(Blueprint $table) { |
|
| 17 | 17 | $table->string('id')->index(); |
| 18 | 18 | $table->string('key'); |
| 19 | 19 | $table->string('secret'); |