@@ -16,13 +16,13 @@ |
||
16 | 16 | */ |
17 | 17 | public function __invoke(Request $request, $appId) |
18 | 18 | { |
19 | - $processQuery = function ($query) use ($appId) { |
|
19 | + $processQuery = function($query) use ($appId) { |
|
20 | 20 | return $query->whereAppId($appId) |
21 | 21 | ->latest() |
22 | 22 | ->limit(120); |
23 | 23 | }; |
24 | 24 | |
25 | - $processCollection = function ($collection) { |
|
25 | + $processCollection = function($collection) { |
|
26 | 26 | return $collection->reverse(); |
27 | 27 | }; |
28 | 28 |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $this->requestBuffer = (string) $request->getBody(); |
81 | 81 | |
82 | - if (! $this->verifyContentLength()) { |
|
82 | + if (!$this->verifyContentLength()) { |
|
83 | 83 | return; |
84 | 84 | } |
85 | 85 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | { |
98 | 98 | $this->requestBuffer .= $msg; |
99 | 99 | |
100 | - if (! $this->verifyContentLength()) { |
|
100 | + if (!$this->verifyContentLength()) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | */ |
125 | 125 | public function onError(ConnectionInterface $connection, Exception $exception) |
126 | 126 | { |
127 | - if (! $exception instanceof HttpException) { |
|
127 | + if (!$exception instanceof HttpException) { |
|
128 | 128 | return; |
129 | 129 | } |
130 | 130 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | protected function findContentLength(array $headers): int |
147 | 147 | { |
148 | - return Collection::make($headers)->first(function ($values, $header) { |
|
148 | + return Collection::make($headers)->first(function($values, $header) { |
|
149 | 149 | return strtolower($header) === 'content-length'; |
150 | 150 | })[0] ?? 0; |
151 | 151 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | $this |
182 | 182 | ->ensureValidAppId($laravelRequest->appId) |
183 | - ->then(function ($app) use ($laravelRequest, $connection) { |
|
183 | + ->then(function($app) use ($laravelRequest, $connection) { |
|
184 | 184 | try { |
185 | 185 | $this->ensureValidSignature($app, $laravelRequest); |
186 | 186 | } catch (HttpException $exception) { |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | |
201 | 201 | // Allow for async IO in the controller action |
202 | 202 | if ($response instanceof PromiseInterface) { |
203 | - $response->then(function ($response) use ($connection) { |
|
203 | + $response->then(function($response) use ($connection) { |
|
204 | 204 | $this->sendAndClose($connection, $response); |
205 | 205 | }); |
206 | 206 | |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | $deferred = new Deferred(); |
243 | 243 | |
244 | 244 | App::findById($appId) |
245 | - ->then(function ($app) use ($appId, $deferred) { |
|
246 | - if (! $app) { |
|
245 | + ->then(function($app) use ($appId, $deferred) { |
|
246 | + if (!$app) { |
|
247 | 247 | throw new HttpException(401, "Unknown app id `{$appId}` provided."); |
248 | 248 | } |
249 | 249 | $deferred->resolve($app); |
@@ -58,7 +58,7 @@ |
||
58 | 58 | $deferred = new Deferred(); |
59 | 59 | |
60 | 60 | $this->ensureValidAppId($request->appId) |
61 | - ->then(function ($app) use ($request, $channelName, $deferred) { |
|
61 | + ->then(function($app) use ($request, $channelName, $deferred) { |
|
62 | 62 | if ($app->statisticsEnabled) { |
63 | 63 | StatisticsCollector::apiMessage($request->appId); |
64 | 64 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | { |
127 | 127 | $deferred = new Deferred(); |
128 | 128 | |
129 | - App::findById($this->appId)->then(function ($app) use ($deferred) { |
|
129 | + App::findById($this->appId)->then(function($app) use ($deferred) { |
|
130 | 130 | $deferred->resolve($app->statisticsEnabled); |
131 | 131 | }); |
132 | 132 |
@@ -90,10 +90,10 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function save() |
92 | 92 | { |
93 | - $this->getStatistics()->then(function ($statistics) { |
|
93 | + $this->getStatistics()->then(function($statistics) { |
|
94 | 94 | foreach ($statistics as $appId => $statistic) { |
95 | - $statistic->isEnabled()->then(function ($isEnabled) use ($appId, $statistic) { |
|
96 | - if (! $isEnabled) { |
|
95 | + $statistic->isEnabled()->then(function($isEnabled) use ($appId, $statistic) { |
|
96 | + if (!$isEnabled) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $this->channelManager |
109 | 109 | ->getGlobalConnectionsCount($appId) |
110 | - ->then(function ($connections) use ($statistic) { |
|
110 | + ->then(function($connections) use ($statistic) { |
|
111 | 111 | $statistic->reset( |
112 | 112 | is_null($connections) ? 0 : $connections |
113 | 113 | ); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | protected function findOrMake($appId): Statistic |
172 | 172 | { |
173 | - if (! isset($this->statistics[$appId])) { |
|
173 | + if (!isset($this->statistics[$appId])) { |
|
174 | 174 | $this->statistics[$appId] = Statistic::new($appId); |
175 | 175 | } |
176 | 176 |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function handle() |
74 | 74 | { |
75 | - $this->laravel->singleton(LoopInterface::class, function () { |
|
75 | + $this->laravel->singleton(LoopInterface::class, function() { |
|
76 | 76 | return $this->loop; |
77 | 77 | }); |
78 | 78 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | protected function configureManagers() |
115 | 115 | { |
116 | - $this->laravel->singleton(ChannelManager::class, function ($app) { |
|
116 | + $this->laravel->singleton(ChannelManager::class, function($app) { |
|
117 | 117 | $config = $app['config']['websockets']; |
118 | 118 | $mode = $config['replication']['mode'] ?? 'local'; |
119 | 119 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | */ |
132 | 132 | protected function configureStatistics() |
133 | 133 | { |
134 | - if (! $this->option('disable-statistics')) { |
|
134 | + if (!$this->option('disable-statistics')) { |
|
135 | 135 | $intervalInSeconds = $this->option('statistics-interval') ?: config('websockets.statistics.interval_in_seconds', 3600); |
136 | 136 | |
137 | - $this->loop->addPeriodicTimer($intervalInSeconds, function () { |
|
137 | + $this->loop->addPeriodicTimer($intervalInSeconds, function() { |
|
138 | 138 | $this->line('Saving statistics...', null, OutputInterface::VERBOSITY_VERBOSE); |
139 | 139 | |
140 | 140 | StatisticsCollectorFacade::save(); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | { |
152 | 152 | $this->lastRestart = $this->getLastRestart(); |
153 | 153 | |
154 | - $this->loop->addPeriodicTimer(10, function () { |
|
154 | + $this->loop->addPeriodicTimer(10, function() { |
|
155 | 155 | if ($this->getLastRestart() !== $this->lastRestart) { |
156 | 156 | $this->triggerSoftShutdown(); |
157 | 157 | } |
@@ -180,17 +180,17 @@ discard block |
||
180 | 180 | // to receive new connections, close the current connections, |
181 | 181 | // then stopping the loop. |
182 | 182 | |
183 | - if (! extension_loaded('pcntl')) { |
|
183 | + if (!extension_loaded('pcntl')) { |
|
184 | 184 | return; |
185 | 185 | } |
186 | 186 | |
187 | - $this->loop->addSignal(SIGTERM, function () { |
|
187 | + $this->loop->addSignal(SIGTERM, function() { |
|
188 | 188 | $this->line('Closing existing connections...'); |
189 | 189 | |
190 | 190 | $this->triggerSoftShutdown(); |
191 | 191 | }); |
192 | 192 | |
193 | - $this->loop->addSignal(SIGINT, function () { |
|
193 | + $this->loop->addSignal(SIGINT, function() { |
|
194 | 194 | $this->line('Closing existing connections...'); |
195 | 195 | |
196 | 196 | $this->triggerSoftShutdown(); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | */ |
206 | 206 | protected function configurePongTracker() |
207 | 207 | { |
208 | - $this->loop->addPeriodicTimer(10, function () { |
|
208 | + $this->loop->addPeriodicTimer(10, function() { |
|
209 | 209 | $this->laravel |
210 | 210 | ->make(ChannelManager::class) |
211 | 211 | ->removeObsoleteConnections(); |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | protected function configureHttpLogger() |
221 | 221 | { |
222 | - $this->laravel->singleton(HttpLogger::class, function ($app) { |
|
222 | + $this->laravel->singleton(HttpLogger::class, function($app) { |
|
223 | 223 | return (new HttpLogger($this->output)) |
224 | 224 | ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false)) |
225 | 225 | ->verbose($this->output->isVerbose()); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | */ |
234 | 234 | protected function configureMessageLogger() |
235 | 235 | { |
236 | - $this->laravel->singleton(WebSocketsLogger::class, function ($app) { |
|
236 | + $this->laravel->singleton(WebSocketsLogger::class, function($app) { |
|
237 | 237 | return (new WebSocketsLogger($this->output)) |
238 | 238 | ->enable($this->option('debug') ?: ($app['config']['app']['debug'] ?? false)) |
239 | 239 | ->verbose($this->output->isVerbose()); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | */ |
248 | 248 | protected function configureConnectionLogger() |
249 | 249 | { |
250 | - $this->laravel->bind(ConnectionLogger::class, function ($app) { |
|
250 | + $this->laravel->bind(ConnectionLogger::class, function($app) { |
|
251 | 251 | return (new ConnectionLogger($this->output)) |
252 | 252 | ->enable($app['config']['app']['debug'] ?? false) |
253 | 253 | ->verbose($this->output->isVerbose()); |
@@ -319,16 +319,16 @@ discard block |
||
319 | 319 | // Get all local connections and close them. They will |
320 | 320 | // be automatically be unsubscribed from all channels. |
321 | 321 | $channelManager->getLocalConnections() |
322 | - ->then(function ($connections) { |
|
323 | - return all(collect($connections)->map(function ($connection) { |
|
322 | + ->then(function($connections) { |
|
323 | + return all(collect($connections)->map(function($connection) { |
|
324 | 324 | return app('websockets.handler') |
325 | 325 | ->onClose($connection) |
326 | - ->then(function () use ($connection) { |
|
326 | + ->then(function() use ($connection) { |
|
327 | 327 | $connection->close(); |
328 | 328 | }); |
329 | 329 | })->toArray()); |
330 | 330 | }) |
331 | - ->then(function () { |
|
331 | + ->then(function() { |
|
332 | 332 | $this->loop->stop(); |
333 | 333 | }); |
334 | 334 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | $this->publishClient = $factory->createLazyClient($connectionUri); |
74 | 74 | $this->subscribeClient = $factory->createLazyClient($connectionUri); |
75 | 75 | |
76 | - $this->subscribeClient->on('message', function ($channel, $payload) { |
|
76 | + $this->subscribeClient->on('message', function($channel, $payload) { |
|
77 | 77 | $this->onMessage($channel, $payload); |
78 | 78 | }); |
79 | 79 | } |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | public function unsubscribeFromAllChannels(ConnectionInterface $connection): PromiseInterface |
102 | 102 | { |
103 | 103 | return $this->getGlobalChannels($connection->app->id) |
104 | - ->then(function ($channels) use ($connection) { |
|
104 | + ->then(function($channels) use ($connection) { |
|
105 | 105 | $promises = []; |
106 | 106 | foreach ($channels as $channel) { |
107 | 107 | $promises[] = $this->unsubscribeFromChannel($connection, $channel, new stdClass); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | |
110 | 110 | return all($promises); |
111 | 111 | }) |
112 | - ->then(function () use ($connection) { |
|
112 | + ->then(function() use ($connection) { |
|
113 | 113 | return parent::unsubscribeFromAllChannels($connection); |
114 | 114 | }); |
115 | 115 | } |
@@ -125,16 +125,16 @@ discard block |
||
125 | 125 | public function subscribeToChannel(ConnectionInterface $connection, string $channelName, stdClass $payload): PromiseInterface |
126 | 126 | { |
127 | 127 | return $this->subscribeToTopic($connection->app->id, $channelName) |
128 | - ->then(function () use ($connection) { |
|
128 | + ->then(function() use ($connection) { |
|
129 | 129 | return $this->addConnectionToSet($connection, Carbon::now()); |
130 | 130 | }) |
131 | - ->then(function () use ($connection, $channelName) { |
|
131 | + ->then(function() use ($connection, $channelName) { |
|
132 | 132 | return $this->addChannelToSet($connection->app->id, $channelName); |
133 | 133 | }) |
134 | - ->then(function () use ($connection, $channelName) { |
|
134 | + ->then(function() use ($connection, $channelName) { |
|
135 | 135 | return $this->incrementSubscriptionsCount($connection->app->id, $channelName, 1); |
136 | 136 | }) |
137 | - ->then(function () use ($connection, $channelName, $payload) { |
|
137 | + ->then(function() use ($connection, $channelName, $payload) { |
|
138 | 138 | return parent::subscribeToChannel($connection, $channelName, $payload); |
139 | 139 | }); |
140 | 140 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | public function unsubscribeFromChannel(ConnectionInterface $connection, string $channelName, stdClass $payload): PromiseInterface |
151 | 151 | { |
152 | 152 | return $this->getGlobalConnectionsCount($connection->app->id, $channelName) |
153 | - ->then(function ($count) use ($connection, $channelName) { |
|
153 | + ->then(function($count) use ($connection, $channelName) { |
|
154 | 154 | if ($count === 0) { |
155 | 155 | // Make sure to not stay subscribed to the PubSub topic |
156 | 156 | // if there are no connections. |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | |
160 | 160 | return Helpers::createFulfilledPromise(null); |
161 | 161 | }) |
162 | - ->then(function () use ($connection, $channelName) { |
|
162 | + ->then(function() use ($connection, $channelName) { |
|
163 | 163 | return $this->decrementSubscriptionsCount($connection->app->id, $channelName) |
164 | - ->then(function ($count) use ($connection, $channelName) { |
|
164 | + ->then(function($count) use ($connection, $channelName) { |
|
165 | 165 | // If the total connections count gets to 0 after unsubscribe, |
166 | 166 | // try again to check & unsubscribe from the PubSub topic if needed. |
167 | 167 | if ($count < 1) { |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | } |
175 | 175 | }); |
176 | 176 | }) |
177 | - ->then(function () use ($connection) { |
|
177 | + ->then(function() use ($connection) { |
|
178 | 178 | return $this->removeConnectionFromSet($connection); |
179 | 179 | }) |
180 | - ->then(function () use ($connection, $channelName, $payload) { |
|
180 | + ->then(function() use ($connection, $channelName, $payload) { |
|
181 | 181 | return parent::unsubscribeFromChannel($connection, $channelName, $payload); |
182 | 182 | }); |
183 | 183 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | public function subscribeToApp($appId): PromiseInterface |
193 | 193 | { |
194 | 194 | return $this->subscribeToTopic($appId) |
195 | - ->then(function () use ($appId) { |
|
195 | + ->then(function() use ($appId) { |
|
196 | 196 | return $this->incrementSubscriptionsCount($appId); |
197 | 197 | }); |
198 | 198 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | public function unsubscribeFromApp($appId): PromiseInterface |
208 | 208 | { |
209 | 209 | return $this->unsubscribeFromTopic($appId) |
210 | - ->then(function () use ($appId) { |
|
210 | + ->then(function() use ($appId) { |
|
211 | 211 | return $this->decrementSubscriptionsCount($appId); |
212 | 212 | }); |
213 | 213 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | { |
225 | 225 | return $this->publishClient |
226 | 226 | ->hget($this->getStatsRedisHash($appId, $channelName), 'connections') |
227 | - ->then(function ($count) { |
|
227 | + ->then(function($count) { |
|
228 | 228 | return is_null($count) ? 0 : (int) $count; |
229 | 229 | }); |
230 | 230 | } |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | return $this->publishClient |
249 | 249 | ->publish($this->getRedisTopicName($appId, $channel), json_encode($payload)) |
250 | - ->then(function () use ($appId, $socketId, $channel, $payload, $serverId) { |
|
250 | + ->then(function() use ($appId, $socketId, $channel, $payload, $serverId) { |
|
251 | 251 | return parent::broadcastAcrossServers($appId, $socketId, $channel, $payload, $serverId); |
252 | 252 | }); |
253 | 253 | } |
@@ -264,10 +264,10 @@ discard block |
||
264 | 264 | public function userJoinedPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel, stdClass $payload): PromiseInterface |
265 | 265 | { |
266 | 266 | return $this->storeUserData($connection->app->id, $channel, $connection->socketId, json_encode($user)) |
267 | - ->then(function () use ($connection, $channel, $user) { |
|
267 | + ->then(function() use ($connection, $channel, $user) { |
|
268 | 268 | return $this->addUserSocket($connection->app->id, $channel, $user, $connection->socketId); |
269 | 269 | }) |
270 | - ->then(function () use ($connection, $user, $channel, $payload) { |
|
270 | + ->then(function() use ($connection, $user, $channel, $payload) { |
|
271 | 271 | return parent::userJoinedPresenceChannel($connection, $user, $channel, $payload); |
272 | 272 | }); |
273 | 273 | } |
@@ -284,10 +284,10 @@ discard block |
||
284 | 284 | public function userLeftPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel): PromiseInterface |
285 | 285 | { |
286 | 286 | return $this->removeUserData($connection->app->id, $channel, $connection->socketId) |
287 | - ->then(function () use ($connection, $channel, $user) { |
|
287 | + ->then(function() use ($connection, $channel, $user) { |
|
288 | 288 | return $this->removeUserSocket($connection->app->id, $channel, $user, $connection->socketId); |
289 | 289 | }) |
290 | - ->then(function () use ($connection, $user, $channel) { |
|
290 | + ->then(function() use ($connection, $user, $channel) { |
|
291 | 291 | return parent::userLeftPresenceChannel($connection, $user, $channel); |
292 | 292 | }); |
293 | 293 | } |
@@ -303,8 +303,8 @@ discard block |
||
303 | 303 | { |
304 | 304 | return $this->publishClient |
305 | 305 | ->hgetall($this->getUsersRedisHash($appId, $channel)) |
306 | - ->then(function ($list) { |
|
307 | - return collect(Helpers::redisListToArray($list))->map(function ($user) { |
|
306 | + ->then(function($list) { |
|
307 | + return collect(Helpers::redisListToArray($list))->map(function($user) { |
|
308 | 308 | return json_decode($user); |
309 | 309 | })->unique('user_id')->toArray(); |
310 | 310 | }); |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | } |
343 | 343 | |
344 | 344 | return $this->publishClient->exec() |
345 | - ->then(function ($data) use ($channelNames) { |
|
345 | + ->then(function($data) use ($channelNames) { |
|
346 | 346 | return array_combine($channelNames, $data); |
347 | 347 | }); |
348 | 348 | } |
@@ -372,7 +372,7 @@ discard block |
||
372 | 372 | { |
373 | 373 | // This will update the score with the current timestamp. |
374 | 374 | return $this->addConnectionToSet($connection, Carbon::now()) |
375 | - ->then(function () use ($connection) { |
|
375 | + ->then(function() use ($connection) { |
|
376 | 376 | $payload = [ |
377 | 377 | 'socketId' => $connection->socketId, |
378 | 378 | 'appId' => $connection->app->id, |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | return $this->publishClient |
383 | 383 | ->publish($this->getPongRedisHash($connection->app->id), json_encode($payload)); |
384 | 384 | }) |
385 | - ->then(function () use ($connection) { |
|
385 | + ->then(function() use ($connection) { |
|
386 | 386 | return parent::connectionPonged($connection); |
387 | 387 | }); |
388 | 388 | } |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function removeObsoleteConnections(): PromiseInterface |
396 | 396 | { |
397 | - return $this->lock()->get(function () { |
|
397 | + return $this->lock()->get(function() { |
|
398 | 398 | return $this->getConnectionsFromSet(0, now()->subMinutes(2)->format('U')) |
399 | - ->then(function ($connections) { |
|
399 | + ->then(function($connections) { |
|
400 | 400 | $promises = []; |
401 | 401 | foreach ($connections as $socketId => $appId) { |
402 | 402 | $connection = $this->fakeConnectionForApp($appId, $socketId); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | |
407 | 407 | return all($promises); |
408 | 408 | }); |
409 | - })->then(function () { |
|
409 | + })->then(function() { |
|
410 | 410 | return parent::removeObsoleteConnections(); |
411 | 411 | }); |
412 | 412 | } |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | |
435 | 435 | $payload->channel = Str::after($redisChannel, "{$payload->appId}:"); |
436 | 436 | |
437 | - if (! $channel = $this->find($payload->appId, $payload->channel)) { |
|
437 | + if (!$channel = $this->find($payload->appId, $payload->channel)) { |
|
438 | 438 | return; |
439 | 439 | } |
440 | 440 | |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | |
460 | 460 | public function find($appId, string $channel) |
461 | 461 | { |
462 | - if (! $channelInstance = parent::find($appId, $channel)) { |
|
462 | + if (!$channelInstance = parent::find($appId, $channel)) { |
|
463 | 463 | $class = $this->getChannelClassName($channel); |
464 | 464 | $this->channels[$appId][$channel] = new $class($channel); |
465 | 465 | } |
@@ -602,8 +602,8 @@ discard block |
||
602 | 602 | |
603 | 603 | return $this->publishClient |
604 | 604 | ->zrangebyscore($this->getSocketsRedisHash(), $start, $stop) |
605 | - ->then(function ($list) { |
|
606 | - return collect($list)->mapWithKeys(function ($appWithSocket) { |
|
605 | + ->then(function($list) { |
|
606 | + return collect($list)->mapWithKeys(function($appWithSocket) { |
|
607 | 607 | [$appId, $socketId] = explode(':', $appWithSocket); |
608 | 608 | |
609 | 609 | return [$socketId => $appId]; |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function findOrCreate($appId, string $channel) |
105 | 105 | { |
106 | - if (! $channelInstance = $this->find($appId, $channel)) { |
|
106 | + if (!$channelInstance = $this->find($appId, $channel)) { |
|
107 | 107 | $class = $this->getChannelClassName($channel); |
108 | 108 | |
109 | 109 | $this->channels[$appId][$channel] = new $class($channel); |
@@ -121,11 +121,11 @@ discard block |
||
121 | 121 | public function getLocalConnections(): PromiseInterface |
122 | 122 | { |
123 | 123 | $connections = collect($this->channels) |
124 | - ->map(function ($channelsWithConnections, $appId) { |
|
124 | + ->map(function($channelsWithConnections, $appId) { |
|
125 | 125 | return collect($channelsWithConnections)->values(); |
126 | 126 | }) |
127 | 127 | ->values()->collapse() |
128 | - ->map(function ($channel) { |
|
128 | + ->map(function($channel) { |
|
129 | 129 | return collect($channel->getConnections()); |
130 | 130 | }) |
131 | 131 | ->values()->collapse() |
@@ -168,28 +168,28 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function unsubscribeFromAllChannels(ConnectionInterface $connection): PromiseInterface |
170 | 170 | { |
171 | - if (! isset($connection->app)) { |
|
171 | + if (!isset($connection->app)) { |
|
172 | 172 | return Helpers::createFulfilledPromise(false); |
173 | 173 | } |
174 | 174 | |
175 | 175 | $this->getLocalChannels($connection->app->id) |
176 | - ->then(function ($channels) use ($connection) { |
|
176 | + ->then(function($channels) use ($connection) { |
|
177 | 177 | collect($channels) |
178 | - ->each(function (Channel $channel) use ($connection) { |
|
178 | + ->each(function(Channel $channel) use ($connection) { |
|
179 | 179 | $channel->unsubscribe($connection); |
180 | 180 | }); |
181 | 181 | |
182 | 182 | collect($channels) |
183 | - ->reject(function ($channel) { |
|
183 | + ->reject(function($channel) { |
|
184 | 184 | return $channel->hasConnections(); |
185 | 185 | }) |
186 | - ->each(function (Channel $channel, string $channelName) use ($connection) { |
|
186 | + ->each(function(Channel $channel, string $channelName) use ($connection) { |
|
187 | 187 | unset($this->channels[$connection->app->id][$channelName]); |
188 | 188 | }); |
189 | 189 | }); |
190 | 190 | |
191 | 191 | $this->getLocalChannels($connection->app->id) |
192 | - ->then(function ($channels) use ($connection) { |
|
192 | + ->then(function($channels) use ($connection) { |
|
193 | 193 | if (count($channels) === 0) { |
194 | 194 | unset($this->channels[$connection->app->id]); |
195 | 195 | } |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | public function getLocalConnectionsCount($appId, string $channelName = null): PromiseInterface |
266 | 266 | { |
267 | 267 | return $this->getLocalChannels($appId) |
268 | - ->then(function ($channels) use ($channelName) { |
|
269 | - return collect($channels)->when(! is_null($channelName), function ($collection) use ($channelName) { |
|
270 | - return $collection->filter(function (Channel $channel) use ($channelName) { |
|
268 | + ->then(function($channels) use ($channelName) { |
|
269 | + return collect($channels)->when(!is_null($channelName), function($collection) use ($channelName) { |
|
270 | + return $collection->filter(function(Channel $channel) use ($channelName) { |
|
271 | 271 | return $channel->getName() === $channelName; |
272 | 272 | }); |
273 | 273 | }) |
274 | - ->flatMap(function (Channel $channel) { |
|
274 | + ->flatMap(function(Channel $channel) { |
|
275 | 275 | return collect($channel->getConnections())->pluck('socketId'); |
276 | 276 | }) |
277 | 277 | ->unique()->count(); |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | { |
364 | 364 | $members = $this->users["{$appId}:{$channel}"] ?? []; |
365 | 365 | |
366 | - $members = collect($members)->map(function ($user) { |
|
366 | + $members = collect($members)->map(function($user) { |
|
367 | 367 | return json_decode($user); |
368 | 368 | })->unique('user_id')->toArray(); |
369 | 369 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | public function getChannelsMembersCount($appId, array $channelNames): PromiseInterface |
395 | 395 | { |
396 | 396 | $results = collect($channelNames) |
397 | - ->reduce(function ($results, $channel) use ($appId) { |
|
397 | + ->reduce(function($results, $channel) use ($appId) { |
|
398 | 398 | $results[$channel] = isset($this->users["{$appId}:{$channel}"]) |
399 | 399 | ? count($this->users["{$appId}:{$channel}"]) |
400 | 400 | : 0; |
@@ -438,9 +438,9 @@ discard block |
||
438 | 438 | */ |
439 | 439 | public function removeObsoleteConnections(): PromiseInterface |
440 | 440 | { |
441 | - return $this->lock()->get(function () { |
|
441 | + return $this->lock()->get(function() { |
|
442 | 442 | return $this->getLocalConnections() |
443 | - ->then(function ($connections) { |
|
443 | + ->then(function($connections) { |
|
444 | 444 | $promises = []; |
445 | 445 | |
446 | 446 | foreach ($connections as $connection) { |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | } |
453 | 453 | |
454 | 454 | return all($promises); |
455 | - })->then(function () { |
|
455 | + })->then(function() { |
|
456 | 456 | $this->lock()->release(); |
457 | 457 | }); |
458 | 458 | }); |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function pongConnectionInChannels(ConnectionInterface $connection): PromiseInterface |
468 | 468 | { |
469 | 469 | return $this->getLocalChannels($connection->app->id) |
470 | - ->then(function ($channels) use ($connection) { |
|
470 | + ->then(function($channels) use ($connection) { |
|
471 | 471 | foreach ($channels as $channel) { |
472 | 472 | if ($conn = $channel->getConnection($connection->socketId)) { |
473 | 473 | $conn->lastPongedAt = Carbon::now(); |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | public function updateConnectionInChannels($connection): PromiseInterface |
489 | 489 | { |
490 | 490 | return $this->getLocalChannels($connection->app->id) |
491 | - ->then(function ($channels) use ($connection) { |
|
491 | + ->then(function($channels) use ($connection) { |
|
492 | 492 | foreach ($channels as $channel) { |
493 | 493 | if ($channel->hasConnection($connection)) { |
494 | 494 | $channel->saveConnection($connection); |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function onOpen(ConnectionInterface $connection) |
48 | 48 | { |
49 | - if (! $this->connectionCanBeMade($connection)) { |
|
49 | + if (!$this->connectionCanBeMade($connection)) { |
|
50 | 50 | return $connection->close(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $this->verifyAppKey($connection) |
54 | - ->then(function () use ($connection) { |
|
54 | + ->then(function() use ($connection) { |
|
55 | 55 | try { |
56 | 56 | $this->verifyOrigin($connection) |
57 | 57 | ->limitConcurrentConnections($connection) |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } catch (WebSocketException $exception) { |
81 | 81 | $this->onError($connection, $exception); |
82 | 82 | } |
83 | - }, function ($exception) use ($connection) { |
|
83 | + }, function($exception) use ($connection) { |
|
84 | 84 | $this->onError($connection, $exception); |
85 | 85 | }); |
86 | 86 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | */ |
95 | 95 | public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
96 | 96 | { |
97 | - if (! isset($connection->app)) { |
|
97 | + if (!isset($connection->app)) { |
|
98 | 98 | return; |
99 | 99 | } |
100 | 100 | |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | { |
124 | 124 | return $this->channelManager |
125 | 125 | ->unsubscribeFromAllChannels($connection) |
126 | - ->then(function (bool $unsubscribed) use ($connection) { |
|
126 | + ->then(function(bool $unsubscribed) use ($connection) { |
|
127 | 127 | if (isset($connection->app)) { |
128 | 128 | if ($connection->app->statisticsEnabled) { |
129 | 129 | StatisticsCollector::disconnection($connection->app->id); |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | |
135 | 135 | return Helpers::createFulfilledPromise(true); |
136 | 136 | }) |
137 | - ->then(function () use ($connection) { |
|
137 | + ->then(function() use ($connection) { |
|
138 | 138 | if (isset($connection->app)) { |
139 | 139 | DashboardLogger::log($connection->app->id, DashboardLogger::TYPE_DISCONNECTED, [ |
140 | 140 | 'socketId' => $connection->socketId, |
@@ -188,8 +188,8 @@ discard block |
||
188 | 188 | $appKey = $query->get('appKey'); |
189 | 189 | |
190 | 190 | App::findByKey($appKey) |
191 | - ->then(function ($app) use ($appKey, $connection, $deferred) { |
|
192 | - if (! $app) { |
|
191 | + ->then(function($app) use ($appKey, $connection, $deferred) { |
|
192 | + if (!$app) { |
|
193 | 193 | $deferred->reject(new Exceptions\UnknownAppKey($appKey)); |
194 | 194 | } |
195 | 195 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function verifyOrigin(ConnectionInterface $connection) |
211 | 211 | { |
212 | - if (! $connection->app->allowedOrigins) { |
|
212 | + if (!$connection->app->allowedOrigins) { |
|
213 | 213 | return $this; |
214 | 214 | } |
215 | 215 | |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | |
218 | 218 | $origin = parse_url($header, PHP_URL_HOST) ?: $header; |
219 | 219 | |
220 | - if (! $header || ! in_array($origin, $connection->app->allowedOrigins)) { |
|
220 | + if (!$header || !in_array($origin, $connection->app->allowedOrigins)) { |
|
221 | 221 | throw new Exceptions\OriginNotAllowed($connection->app->key); |
222 | 222 | } |
223 | 223 | |
@@ -232,10 +232,10 @@ discard block |
||
232 | 232 | */ |
233 | 233 | protected function limitConcurrentConnections(ConnectionInterface $connection) |
234 | 234 | { |
235 | - if (! is_null($capacity = $connection->app->capacity)) { |
|
235 | + if (!is_null($capacity = $connection->app->capacity)) { |
|
236 | 236 | $this->channelManager |
237 | 237 | ->getGlobalConnectionsCount($connection->app->id) |
238 | - ->then(function ($connectionsCount) use ($capacity, $connection) { |
|
238 | + ->then(function($connectionsCount) use ($capacity, $connection) { |
|
239 | 239 | if ($connectionsCount >= $capacity) { |
240 | 240 | $exception = new Exceptions\ConnectionsOverCapacity; |
241 | 241 |