Completed
Pull Request — master (#447)
by Alexandru
02:04
created

LocalChannelManager::userJoinedPresenceChannel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\ChannelManagers;
4
5
use BeyondCode\LaravelWebSockets\Channels\Channel;
6
use BeyondCode\LaravelWebSockets\Channels\PresenceChannel;
7
use BeyondCode\LaravelWebSockets\Channels\PrivateChannel;
8
use BeyondCode\LaravelWebSockets\Contracts\ChannelManager;
9
use Illuminate\Support\Str;
10
use Ratchet\ConnectionInterface;
11
use React\EventLoop\LoopInterface;
12
use React\Promise\FulfilledPromise;
13
use React\Promise\PromiseInterface;
14
use stdClass;
15
16
class LocalChannelManager implements ChannelManager
17
{
18
    /**
19
     * The list of stored channels.
20
     *
21
     * @var array
22
     */
23
    protected $channels = [];
24
25
    /**
26
     * The list of users that joined the presence channel.
27
     *
28
     * @var array
29
     */
30
    protected $users = [];
31
32
    /**
33
     * The list of users by socket and their attached id.
34
     *
35
     * @var array
36
     */
37
    protected $userSockets = [];
38
39
    /**
40
     * Wether the current instance accepts new connections.
41
     *
42
     * @var bool
43
     */
44
    protected $acceptsNewConnections = true;
45
46
    /**
47
     * Create a new channel manager instance.
48
     *
49
     * @param  LoopInterface  $loop
50
     * @param  string|null  $factoryClass
51
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
52
     */
53
    public function __construct(LoopInterface $loop, $factoryClass = null)
54
    {
55
        //
56
    }
57
58
    /**
59
     * Find the channel by app & name.
60
     *
61
     * @param  string|int  $appId
62
     * @param  string  $channel
63
     * @return null|BeyondCode\LaravelWebSockets\Channels\Channel
64
     */
65
    public function find($appId, string $channel)
66
    {
67
        return $this->channels[$appId][$channel] ?? null;
68
    }
69
70
    /**
71
     * Find a channel by app & name or create one.
72
     *
73
     * @param  string|int  $appId
74
     * @param  string  $channel
75
     * @return BeyondCode\LaravelWebSockets\Channels\Channel
76
     */
77
    public function findOrCreate($appId, string $channel)
78
    {
79
        if (! $channelInstance = $this->find($appId, $channel)) {
80
            $class = $this->getChannelClassName($channel);
81
82
            $this->channels[$appId][$channel] = new $class($channel);
83
        }
84
85
        return $this->channels[$appId][$channel];
86
    }
87
88
    /**
89
     * Get the local connections, regardless of the channel
90
     * they are connected to.
91
     *
92
     * @return \React\Promise\PromiseInterface
93
     */
94
    public function getLocalConnections(): PromiseInterface
95
    {
96
        $connections = collect($this->channels)
97
            ->map(function ($channelsWithConnections, $appId) {
0 ignored issues
show
Unused Code introduced by
The parameter $appId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
                return collect($channelsWithConnections)->values();
99
            })
100
            ->values()->collapse()
101
            ->map(function ($channel) {
102
                return collect($channel->getConnections());
103
            })
104
            ->values()->collapse()
105
            ->toArray();
106
107
        return new FulfilledPromise($connections);
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
108
    }
109
110
    /**
111
     * Get all channels for a specific app
112
     * for the current instance.
113
     *
114
     * @param  string|int  $appId
115
     * @return \React\Promise\PromiseInterface[array]
0 ignored issues
show
Documentation introduced by
The doc-type \React\Promise\PromiseInterface[array] could not be parsed: Expected "]" at position 2, but found "array". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
116
     */
117
    public function getLocalChannels($appId): PromiseInterface
118
    {
119
        return new FulfilledPromise(
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
120
            $this->channels[$appId] ?? []
121
        );
122
    }
123
124
    /**
125
     * Get all channels for a specific app
126
     * across multiple servers.
127
     *
128
     * @param  string|int  $appId
129
     * @return \React\Promise\PromiseInterface[array]
0 ignored issues
show
Documentation introduced by
The doc-type \React\Promise\PromiseInterface[array] could not be parsed: Expected "]" at position 2, but found "array". (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
130
     */
131
    public function getGlobalChannels($appId): PromiseInterface
132
    {
133
        return $this->getLocalChannels($appId);
134
    }
135
136
    /**
137
     * Remove connection from all channels.
138
     *
139
     * @param  \Ratchet\ConnectionInterface  $connection
140
     * @return void
141
     */
142
    public function unsubscribeFromAllChannels(ConnectionInterface $connection)
143
    {
144
        if (! isset($connection->app)) {
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
145
            return;
146
        }
147
148
        $this->getLocalChannels($connection->app->id)
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
149
            ->then(function ($channels) use ($connection) {
150
                collect($channels)->each->unsubscribe($connection);
151
152
                collect($channels)
153
                    ->reject->hasConnections()
154
                    ->each(function (Channel $channel, string $channelName) use ($connection) {
155
                        unset($this->channels[$connection->app->id][$channelName]);
156
                    });
157
            });
158
159
        $this->getLocalChannels($connection->app->id)
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
160
            ->then(function ($channels) use ($connection) {
161
                if (count($channels) === 0) {
162
                    unset($this->channels[$connection->app->id]);
163
                }
164
            });
165
    }
166
167
    /**
168
     * Subscribe the connection to a specific channel.
169
     *
170
     * @param  \Ratchet\ConnectionInterface  $connection
171
     * @param  string  $channelName
172
     * @param  stdClass  $payload
173
     * @return void
174
     */
175
    public function subscribeToChannel(ConnectionInterface $connection, string $channelName, stdClass $payload)
176
    {
177
        $channel = $this->findOrCreate($connection->app->id, $channelName);
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
178
179
        $channel->subscribe($connection, $payload);
180
    }
181
182
    /**
183
     * Unsubscribe the connection from the channel.
184
     *
185
     * @param  \Ratchet\ConnectionInterface  $connection
186
     * @param  string  $channelName
187
     * @param  stdClass  $payload
188
     * @return void
189
     */
190
    public function unsubscribeFromChannel(ConnectionInterface $connection, string $channelName, stdClass $payload)
191
    {
192
        $channel = $this->findOrCreate($connection->app->id, $channelName);
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
193
194
        $channel->unsubscribe($connection, $payload);
195
    }
196
197
    /**
198
     * Subscribe the connection to a specific channel.
199
     *
200
     * @param  string|int  $appId
201
     * @return void
202
     */
203
    public function subscribeToApp($appId)
204
    {
205
        //
206
    }
207
208
    /**
209
     * Unsubscribe the connection from the channel.
210
     *
211
     * @param  string|int  $appId
212
     * @return void
213
     */
214
    public function unsubscribeFromApp($appId)
215
    {
216
        //
217
    }
218
219
    /**
220
     * Get the connections count on the app
221
     * for the current server instance.
222
     *
223
     * @param  string|int  $appId
224
     * @param  string|null  $channelName
225
     * @return \React\Promise\PromiseInterface
226
     */
227
    public function getLocalConnectionsCount($appId, string $channelName = null): PromiseInterface
228
    {
229
        return $this->getLocalChannels($appId)
230
            ->then(function ($channels) use ($channelName) {
231
                return collect($channels)
232
                    ->when(! is_null($channelName), function ($collection) use ($channelName) {
233
                        return $collection->filter(function (Channel $channel) use ($channelName) {
234
                            return $channel->getName() === $channelName;
235
                        });
236
                    })
237
                    ->flatMap(function (Channel $channel) {
238
                        return collect($channel->getConnections())->pluck('socketId');
239
                    })
240
                    ->unique()
241
                    ->count();
242
            });
243
    }
244
245
    /**
246
     * Get the connections count
247
     * across multiple servers.
248
     *
249
     * @param  string|int  $appId
250
     * @param  string|null  $channelName
251
     * @return \React\Promise\PromiseInterface
252
     */
253
    public function getGlobalConnectionsCount($appId, string $channelName = null): PromiseInterface
254
    {
255
        return $this->getLocalConnectionsCount($appId, $channelName);
256
    }
257
258
    /**
259
     * Broadcast the message across multiple servers.
260
     *
261
     * @param  string|int  $appId
262
     * @param  string  $channel
263
     * @param  stdClass  $payload
264
     * @return bool
265
     */
266
    public function broadcastAcrossServers($appId, string $channel, stdClass $payload)
267
    {
268
        return true;
269
    }
270
271
    /**
272
     * Handle the user when it joined a presence channel.
273
     *
274
     * @param  \Ratchet\ConnectionInterface  $connection
275
     * @param  stdClass  $user
276
     * @param  string  $channel
277
     * @param  stdClass  $payload
278
     * @return void
279
     */
280
    public function userJoinedPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel, stdClass $payload)
281
    {
282
        $this->users["{$connection->app->id}:{$channel}"][$connection->socketId] = json_encode($user);
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
283
        $this->userSockets["{$connection->app->id}:{$channel}:{$user->user_id}"][] = $connection->socketId;
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
284
    }
285
286
    /**
287
     * Handle the user when it left a presence channel.
288
     *
289
     * @param  \Ratchet\ConnectionInterface  $connection
290
     * @param  stdClass  $user
291
     * @param  string  $channel
292
     * @param  stdClass  $payload
0 ignored issues
show
Bug introduced by
There is no parameter named $payload. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
293
     * @return void
294
     */
295
    public function userLeftPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel)
296
    {
297
        unset($this->users["{$connection->app->id}:{$channel}"][$connection->socketId]);
298
299
        $deletableSocketKey = array_search(
300
            $connection->socketId,
0 ignored issues
show
Bug introduced by
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
301
            $this->userSockets["{$connection->app->id}:{$channel}:{$user->user_id}"]
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
302
        );
303
304
        if ($deletableSocketKey !== false) {
305
            unset($this->userSockets["{$connection->app->id}:{$channel}:{$user->user_id}"][$deletableSocketKey]);
306
307
            if (count($this->userSockets["{$connection->app->id}:{$channel}:{$user->user_id}"]) === 0) {
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
308
                unset($this->userSockets["{$connection->app->id}:{$channel}:{$user->user_id}"]);
309
            }
310
        }
311
    }
312
313
    /**
314
     * Get the presence channel members.
315
     *
316
     * @param  string|int  $appId
317
     * @param  string  $channel
318
     * @return \React\Promise\PromiseInterface
319
     */
320
    public function getChannelMembers($appId, string $channel): PromiseInterface
321
    {
322
        $members = $this->users["{$appId}:{$channel}"] ?? [];
323
324
        $members = collect($members)->map(function ($user) {
325
            return json_decode($user);
326
        })->unique('user_id')->toArray();
327
328
        return new FulfilledPromise($members);
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
329
    }
330
331
    /**
332
     * Get a member from a presence channel based on connection.
333
     *
334
     * @param  \Ratchet\ConnectionInterface  $connection
335
     * @param  string  $channel
336
     * @return \React\Promise\PromiseInterface
337
     */
338
    public function getChannelMember(ConnectionInterface $connection, string $channel): PromiseInterface
339
    {
340
        $member = $this->users["{$connection->app->id}:{$channel}"][$connection->socketId] ?? null;
0 ignored issues
show
Bug introduced by
Accessing app on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing socketId on the interface Ratchet\ConnectionInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
341
342
        return new FulfilledPromise($member);
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
343
    }
344
345
    /**
346
     * Get the presence channels total members count.
347
     *
348
     * @param  string|int  $appId
349
     * @param  array  $channelNames
350
     * @return \React\Promise\PromiseInterface
351
     */
352
    public function getChannelsMembersCount($appId, array $channelNames): PromiseInterface
353
    {
354
        $results = collect($channelNames)
355
            ->reduce(function ($results, $channel) use ($appId) {
356
                $results[$channel] = isset($this->users["{$appId}:{$channel}"])
357
                    ? count($this->users["{$appId}:{$channel}"])
358
                    : 0;
359
360
                return $results;
361
            }, []);
362
363
        return new FulfilledPromise($results);
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
364
    }
365
366
    /**
367
     * Get the socket IDs for a presence channel member.
368
     *
369
     * @param  string|int  $userId
370
     * @param  string|int  $appId
371
     * @param  string  $channelName
372
     * @return \React\Promise\PromiseInterface
373
     */
374
    public function getMemberSockets($userId, $appId, $channelName): PromiseInterface
375
    {
376
        return new FulfilledPromise(
0 ignored issues
show
Deprecated Code introduced by
The class React\Promise\FulfilledPromise has been deprecated with message: 2.8.0 External usage of FulfilledPromise is deprecated, use `resolve()` instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
377
            $this->userSockets["{$appId}:{$channelName}:{$userId}"] ?? []
378
        );
379
    }
380
381
    /**
382
     * Keep tracking the connections availability when they pong.
383
     *
384
     * @param  \Ratchet\ConnectionInterface  $connection
385
     * @return bool
386
     */
387
    public function connectionPonged(ConnectionInterface $connection): bool
388
    {
389
        return true;
390
    }
391
392
    /**
393
     * Remove the obsolete connections that didn't ponged in a while.
394
     *
395
     * @return bool
396
     */
397
    public function removeObsoleteConnections(): bool
398
    {
399
        return true;
400
    }
401
402
    /**
403
     * Mark the current instance as unable to accept new connections.
404
     *
405
     * @return $this
406
     */
407
    public function declineNewConnections()
408
    {
409
        $this->acceptsNewConnections = false;
410
411
        return $this;
412
    }
413
414
    /**
415
     * Check if the current server instance
416
     * accepts new connections.
417
     *
418
     * @return bool
419
     */
420
    public function acceptsNewConnections(): bool
421
    {
422
        return $this->acceptsNewConnections;
423
    }
424
425
    /**
426
     * Get the channel class by the channel name.
427
     *
428
     * @param  string  $channelName
429
     * @return string
430
     */
431
    protected function getChannelClassName(string $channelName): string
432
    {
433
        if (Str::startsWith($channelName, 'private-')) {
434
            return PrivateChannel::class;
435
        }
436
437
        if (Str::startsWith($channelName, 'presence-')) {
438
            return PresenceChannel::class;
439
        }
440
441
        return Channel::class;
442
    }
443
}
444