@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | if ($request->has('info')) { |
24 | 24 | $attributes = explode(',', trim($request->info)); |
25 | 25 | |
26 | - if (in_array('user_count', $attributes) && ! Str::startsWith($request->filter_by_prefix, 'presence-')) { |
|
26 | + if (in_array('user_count', $attributes) && !Str::startsWith($request->filter_by_prefix, 'presence-')) { |
|
27 | 27 | throw new HttpException(400, 'Request must be limited to presence channels in order to fetch user_count'); |
28 | 28 | } |
29 | 29 | |
30 | - if (in_array('socket_count', $attributes) && $request->has('starts_with')) { |
|
31 | - if (! Str::startsWith($request->starts_with, ['presence-', 'private-'])) { |
|
30 | + if (in_array('socket_count', $attributes) && $request->has('starts_with')) { |
|
31 | + if (!Str::startsWith($request->starts_with, ['presence-', 'private-'])) { |
|
32 | 32 | throw new HttpException(400, 'Requests must be limited to presence and private channels in order to fetch channel data'); |
33 | 33 | } |
34 | 34 | } |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | if (in_array('socket_count', $attributes)) { |
38 | 38 | return $this->channelManager |
39 | 39 | ->getChannelSockets($request->appId) |
40 | - ->then(function ($channels) use ($request) { |
|
40 | + ->then(function($channels) use ($request) { |
|
41 | 41 | if (count($channels)) { |
42 | 42 | |
43 | 43 | if ($request->has('starts_with')) { |
44 | - $channels = $channels->filter(function ($channel, $channelName) use ($request) { |
|
44 | + $channels = $channels->filter(function($channel, $channelName) use ($request) { |
|
45 | 45 | return Str::startsWith($channelName, $request->starts_with); |
46 | 46 | }); |
47 | 47 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | |
51 | 51 | return $this->channelManager |
52 | 52 | ->getChannelsSocketsCount($request->appId, $channelNames) |
53 | - ->then(function ($counts) use ($channels) { |
|
53 | + ->then(function($counts) use ($channels) { |
|
54 | 54 | return [ |
55 | 55 | 'channels' => $counts ?: new stdClass, |
56 | 56 | ]; |
@@ -62,20 +62,20 @@ discard block |
||
62 | 62 | |
63 | 63 | return $this->channelManager |
64 | 64 | ->getGlobalChannels($request->appId) |
65 | - ->then(function ($channels) use ($request, $attributes) { |
|
66 | - $channels = collect($channels)->keyBy(function ($channel) { |
|
65 | + ->then(function($channels) use ($request, $attributes) { |
|
66 | + $channels = collect($channels)->keyBy(function($channel) { |
|
67 | 67 | return $channel instanceof Channel |
68 | 68 | ? $channel->getName() |
69 | 69 | : $channel; |
70 | 70 | }); |
71 | 71 | |
72 | 72 | if ($request->has('filter_by_prefix')) { |
73 | - $channels = $channels->filter(function ($channel, $channelName) use ($request) { |
|
73 | + $channels = $channels->filter(function($channel, $channelName) use ($request) { |
|
74 | 74 | return Str::startsWith($channelName, $request->filter_by_prefix); |
75 | 75 | }); |
76 | 76 | } |
77 | 77 | |
78 | - $channelNames = $channels->map(function ($channel) { |
|
78 | + $channelNames = $channels->map(function($channel) { |
|
79 | 79 | return $channel instanceof Channel |
80 | 80 | ? $channel->getName() |
81 | 81 | : $channel; |
@@ -83,8 +83,8 @@ discard block |
||
83 | 83 | |
84 | 84 | return $this->channelManager |
85 | 85 | ->getChannelsMembersCount($request->appId, $channelNames) |
86 | - ->then(function ($counts) use ($channels, $attributes) { |
|
87 | - $channels = $channels->map(function ($channel) use ($counts, $attributes) { |
|
86 | + ->then(function($counts) use ($channels, $attributes) { |
|
87 | + $channels = $channels->map(function($channel) use ($counts, $attributes) { |
|
88 | 88 | $info = new stdClass; |
89 | 89 | |
90 | 90 | $channelName = $channel instanceof Channel |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | return $info; |
99 | - })->sortBy(function ($content, $name) { |
|
99 | + })->sortBy(function($content, $name) { |
|
100 | 100 | return $name; |
101 | 101 | })->all(); |
102 | 102 |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function findOrCreate($appId, string $channel) |
111 | 111 | { |
112 | - if (! $channelInstance = $this->find($appId, $channel)) { |
|
112 | + if (!$channelInstance = $this->find($appId, $channel)) { |
|
113 | 113 | $class = $this->getChannelClassName($channel); |
114 | 114 | |
115 | 115 | $this->channels[$appId][$channel] = new $class($channel); |
@@ -127,11 +127,11 @@ discard block |
||
127 | 127 | public function getLocalConnections(): PromiseInterface |
128 | 128 | { |
129 | 129 | $connections = collect($this->channels) |
130 | - ->map(function ($channelsWithConnections, $appId) { |
|
130 | + ->map(function($channelsWithConnections, $appId) { |
|
131 | 131 | return collect($channelsWithConnections)->values(); |
132 | 132 | }) |
133 | 133 | ->values()->collapse() |
134 | - ->map(function ($channel) { |
|
134 | + ->map(function($channel) { |
|
135 | 135 | return collect($channel->getConnections()); |
136 | 136 | }) |
137 | 137 | ->values()->collapse() |
@@ -188,28 +188,28 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function unsubscribeFromAllChannels(ConnectionInterface $connection): PromiseInterface |
190 | 190 | { |
191 | - if (! isset($connection->app)) { |
|
191 | + if (!isset($connection->app)) { |
|
192 | 192 | return Helpers::createFulfilledPromise(false); |
193 | 193 | } |
194 | 194 | |
195 | 195 | $this->getLocalChannels($connection->app->id) |
196 | - ->then(function ($channels) use ($connection) { |
|
196 | + ->then(function($channels) use ($connection) { |
|
197 | 197 | collect($channels) |
198 | - ->each(function (Channel $channel) use ($connection) { |
|
198 | + ->each(function(Channel $channel) use ($connection) { |
|
199 | 199 | $channel->unsubscribe($connection); |
200 | 200 | }); |
201 | 201 | |
202 | 202 | collect($channels) |
203 | - ->reject(function ($channel) { |
|
203 | + ->reject(function($channel) { |
|
204 | 204 | return $channel->hasConnections(); |
205 | 205 | }) |
206 | - ->each(function (Channel $channel, string $channelName) use ($connection) { |
|
206 | + ->each(function(Channel $channel, string $channelName) use ($connection) { |
|
207 | 207 | unset($this->channels[$connection->app->id][$channelName]); |
208 | 208 | }); |
209 | 209 | }); |
210 | 210 | |
211 | 211 | $this->getLocalChannels($connection->app->id) |
212 | - ->then(function ($channels) use ($connection) { |
|
212 | + ->then(function($channels) use ($connection) { |
|
213 | 213 | if (count($channels) === 0) { |
214 | 214 | unset($this->channels[$connection->app->id]); |
215 | 215 | } |
@@ -287,13 +287,13 @@ discard block |
||
287 | 287 | public function getLocalConnectionsCount($appId, string $channelName = null): PromiseInterface |
288 | 288 | { |
289 | 289 | return $this->getLocalChannels($appId) |
290 | - ->then(function ($channels) use ($channelName) { |
|
291 | - return collect($channels)->when(! is_null($channelName), function ($collection) use ($channelName) { |
|
292 | - return $collection->filter(function (Channel $channel) use ($channelName) { |
|
290 | + ->then(function($channels) use ($channelName) { |
|
291 | + return collect($channels)->when(!is_null($channelName), function($collection) use ($channelName) { |
|
292 | + return $collection->filter(function(Channel $channel) use ($channelName) { |
|
293 | 293 | return $channel->getName() === $channelName; |
294 | 294 | }); |
295 | 295 | }) |
296 | - ->flatMap(function (Channel $channel) { |
|
296 | + ->flatMap(function(Channel $channel) { |
|
297 | 297 | return collect($channel->getConnections())->pluck('socketId'); |
298 | 298 | }) |
299 | 299 | ->unique()->count(); |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | { |
416 | 416 | $members = $this->users["{$appId}:{$channel}"] ?? []; |
417 | 417 | |
418 | - $members = collect($members)->map(function ($user) { |
|
418 | + $members = collect($members)->map(function($user) { |
|
419 | 419 | return json_decode($user); |
420 | 420 | })->unique('user_id')->toArray(); |
421 | 421 | |
@@ -446,7 +446,7 @@ discard block |
||
446 | 446 | public function getChannelsSocketsCount($appId, array $channelNames): PromiseInterface |
447 | 447 | { |
448 | 448 | $results = collect($channelNames) |
449 | - ->reduce(function ($results, $channel) use ($appId) { |
|
449 | + ->reduce(function($results, $channel) use ($appId) { |
|
450 | 450 | $results[$channel] = isset($this->channelSockets[$appId][$channel]) |
451 | 451 | ? count($this->channelSockets[$appId][$channel]) |
452 | 452 | : 0; |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | public function getChannelsMembersCount($appId, array $channelNames): PromiseInterface |
468 | 468 | { |
469 | 469 | $results = collect($channelNames) |
470 | - ->reduce(function ($results, $channel) use ($appId) { |
|
470 | + ->reduce(function($results, $channel) use ($appId) { |
|
471 | 471 | $results[$channel] = isset($this->users["{$appId}:{$channel}"]) |
472 | 472 | ? count($this->users["{$appId}:{$channel}"]) |
473 | 473 | : 0; |
@@ -513,11 +513,11 @@ discard block |
||
513 | 513 | { |
514 | 514 | $lock = $this->lock(); |
515 | 515 | try { |
516 | - if (! $lock->acquire()) { |
|
516 | + if (!$lock->acquire()) { |
|
517 | 517 | return Helpers::createFulfilledPromise(false); |
518 | 518 | } |
519 | 519 | |
520 | - $this->getLocalConnections()->then(function ($connections) { |
|
520 | + $this->getLocalConnections()->then(function($connections) { |
|
521 | 521 | foreach ($connections as $connection) { |
522 | 522 | $differenceInSeconds = $connection->lastPongedAt->diffInSeconds(Carbon::now()); |
523 | 523 | |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | public function pongConnectionInChannels(ConnectionInterface $connection): PromiseInterface |
543 | 543 | { |
544 | 544 | return $this->getLocalChannels($connection->app->id) |
545 | - ->then(function ($channels) use ($connection) { |
|
545 | + ->then(function($channels) use ($connection) { |
|
546 | 546 | foreach ($channels as $channel) { |
547 | 547 | if ($conn = $channel->getConnection($connection->socketId)) { |
548 | 548 | $conn->lastPongedAt = Carbon::now(); |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | public function updateConnectionInChannels($connection): PromiseInterface |
564 | 564 | { |
565 | 565 | return $this->getLocalChannels($connection->app->id) |
566 | - ->then(function ($channels) use ($connection) { |
|
566 | + ->then(function($channels) use ($connection) { |
|
567 | 567 | foreach ($channels as $channel) { |
568 | 568 | if ($channel->hasConnection($connection)) { |
569 | 569 | $channel->saveConnection($connection); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | protected function registerAsyncRedisQueueDriver() |
71 | 71 | { |
72 | - Queue::extend('async-redis', function () { |
|
72 | + Queue::extend('async-redis', function() { |
|
73 | 73 | return new AsyncRedisConnector($this->app['redis']); |
74 | 74 | }); |
75 | 75 | } |
@@ -81,14 +81,14 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function registerStatistics() |
83 | 83 | { |
84 | - $this->app->singleton(StatisticsStore::class, function ($app) { |
|
84 | + $this->app->singleton(StatisticsStore::class, function($app) { |
|
85 | 85 | $config = $app['config']['websockets']; |
86 | 86 | $class = $config['statistics']['store']; |
87 | 87 | |
88 | 88 | return new $class; |
89 | 89 | }); |
90 | 90 | |
91 | - $this->app->singleton(StatisticsCollector::class, function ($app) { |
|
91 | + $this->app->singleton(StatisticsCollector::class, function($app) { |
|
92 | 92 | $config = $app['config']['websockets']; |
93 | 93 | $replicationMode = $config['replication']['mode'] ?? 'local'; |
94 | 94 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | protected function registerRouter() |
135 | 135 | { |
136 | - $this->app->singleton('websockets.router', function () { |
|
136 | + $this->app->singleton('websockets.router', function() { |
|
137 | 137 | return new Router; |
138 | 138 | }); |
139 | 139 | } |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | */ |
146 | 146 | protected function registerManagers() |
147 | 147 | { |
148 | - $this->app->singleton(Contracts\AppManager::class, function ($app) { |
|
148 | + $this->app->singleton(Contracts\AppManager::class, function($app) { |
|
149 | 149 | $config = $app['config']['websockets']; |
150 | 150 | |
151 | 151 | return $this->app->make($config['managers']['app']); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | 'prefix' => config('websockets.dashboard.path'), |
165 | 165 | 'as' => 'laravel-websockets.', |
166 | 166 | 'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]), |
167 | - ], function () { |
|
167 | + ], function() { |
|
168 | 168 | Route::get('/', ShowDashboard::class)->name('dashboard'); |
169 | 169 | Route::get('/api/{appId}/channels', ShowChannels::class)->name('channels'); |
170 | 170 | Route::get('/api/{appId}/statistics', ShowStatistics::class)->name('statistics'); |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | */ |
181 | 181 | protected function registerDashboardGate() |
182 | 182 | { |
183 | - Gate::define('viewWebSocketsDashboard', function ($user = null) { |
|
183 | + Gate::define('viewWebSocketsDashboard', function($user = null) { |
|
184 | 184 | return $this->app->environment('local'); |
185 | 185 | }); |
186 | 186 | } |