1 | <?php |
||
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 | * Create a new channel manager instance. |
||
34 | * |
||
35 | * @param LoopInterface $loop |
||
36 | * @param string|null $factoryClass |
||
37 | * @return void |
||
|
|||
38 | */ |
||
39 | public function __construct(LoopInterface $loop, $factoryClass = null) |
||
43 | |||
44 | /** |
||
45 | * Find the channel by app & name. |
||
46 | * |
||
47 | * @param string|int $appId |
||
48 | * @param string $channel |
||
49 | * @return null|BeyondCode\LaravelWebSockets\Channels\Channel |
||
50 | */ |
||
51 | public function find($appId, string $channel) |
||
55 | |||
56 | /** |
||
57 | * Find a channel by app & name or create one. |
||
58 | * |
||
59 | * @param string|int $appId |
||
60 | * @param string $channel |
||
61 | * @return BeyondCode\LaravelWebSockets\Channels\Channel |
||
62 | */ |
||
63 | public function findOrCreate($appId, string $channel) |
||
73 | |||
74 | /** |
||
75 | * Get all channels for a specific app |
||
76 | * for the current instance. |
||
77 | * |
||
78 | * @param string|int $appId |
||
79 | * @return \React\Promise\PromiseInterface[array] |
||
80 | */ |
||
81 | public function getLocalChannels($appId): PromiseInterface |
||
87 | |||
88 | /** |
||
89 | * Get all channels for a specific app |
||
90 | * across multiple servers. |
||
91 | * |
||
92 | * @param string|int $appId |
||
93 | * @return \React\Promise\PromiseInterface[array] |
||
94 | */ |
||
95 | public function getGlobalChannels($appId): PromiseInterface |
||
99 | |||
100 | /** |
||
101 | * Remove connection from all channels. |
||
102 | * |
||
103 | * @param \Ratchet\ConnectionInterface $connection |
||
104 | * @return void |
||
105 | */ |
||
106 | public function unsubscribeFromAllChannels(ConnectionInterface $connection) |
||
130 | |||
131 | /** |
||
132 | * Subscribe the connection to a specific channel. |
||
133 | * |
||
134 | * @param \Ratchet\ConnectionInterface $connection |
||
135 | * @param string $channelName |
||
136 | * @param stdClass $payload |
||
137 | * @return void |
||
138 | */ |
||
139 | public function subscribeToChannel(ConnectionInterface $connection, string $channelName, stdClass $payload) |
||
145 | |||
146 | /** |
||
147 | * Unsubscribe the connection from the channel. |
||
148 | * |
||
149 | * @param \Ratchet\ConnectionInterface $connection |
||
150 | * @param string $channelName |
||
151 | * @param stdClass $payload |
||
152 | * @return void |
||
153 | */ |
||
154 | public function unsubscribeFromChannel(ConnectionInterface $connection, string $channelName, stdClass $payload) |
||
160 | |||
161 | /** |
||
162 | * Subscribe the connection to a specific channel. |
||
163 | * |
||
164 | * @param string|int $appId |
||
165 | * @return void |
||
166 | */ |
||
167 | public function subscribeToApp($appId) |
||
171 | |||
172 | /** |
||
173 | * Unsubscribe the connection from the channel. |
||
174 | * |
||
175 | * @param string|int $appId |
||
176 | * @return void |
||
177 | */ |
||
178 | public function unsubscribeFromApp($appId) |
||
182 | |||
183 | /** |
||
184 | * Get the connections count on the app |
||
185 | * for the current server instance. |
||
186 | * |
||
187 | * @param string|int $appId |
||
188 | * @param string|null $channelName |
||
189 | * @return \React\Promise\PromiseInterface |
||
190 | */ |
||
191 | public function getLocalConnectionsCount($appId, string $channelName = null): PromiseInterface |
||
208 | |||
209 | /** |
||
210 | * Get the connections count |
||
211 | * across multiple servers. |
||
212 | * |
||
213 | * @param string|int $appId |
||
214 | * @param string|null $channelName |
||
215 | * @return \React\Promise\PromiseInterface |
||
216 | */ |
||
217 | public function getGlobalConnectionsCount($appId, string $channelName = null): PromiseInterface |
||
221 | |||
222 | /** |
||
223 | * Broadcast the message across multiple servers. |
||
224 | * |
||
225 | * @param string|int $appId |
||
226 | * @param string $channel |
||
227 | * @param stdClass $payload |
||
228 | * @return bool |
||
229 | */ |
||
230 | public function broadcastAcrossServers($appId, string $channel, stdClass $payload) |
||
234 | |||
235 | /** |
||
236 | * Handle the user when it joined a presence channel. |
||
237 | * |
||
238 | * @param \Ratchet\ConnectionInterface $connection |
||
239 | * @param stdClass $user |
||
240 | * @param string $channel |
||
241 | * @param stdClass $payload |
||
242 | * @return void |
||
243 | */ |
||
244 | public function userJoinedPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel, stdClass $payload) |
||
248 | |||
249 | /** |
||
250 | * Handle the user when it left a presence channel. |
||
251 | * |
||
252 | * @param \Ratchet\ConnectionInterface $connection |
||
253 | * @param stdClass $user |
||
254 | * @param string $channel |
||
255 | * @param stdClass $payload |
||
256 | * @return void |
||
257 | */ |
||
258 | public function userLeftPresenceChannel(ConnectionInterface $connection, stdClass $user, string $channel) |
||
262 | |||
263 | /** |
||
264 | * Get the presence channel members. |
||
265 | * |
||
266 | * @param string|int $appId |
||
267 | * @param string $channel |
||
268 | * @return \React\Promise\PromiseInterface |
||
269 | */ |
||
270 | public function getChannelMembers($appId, string $channel): PromiseInterface |
||
280 | |||
281 | /** |
||
282 | * Get a member from a presence channel based on connection. |
||
283 | * |
||
284 | * @param \Ratchet\ConnectionInterface $connection |
||
285 | * @param string $channel |
||
286 | * @return \React\Promise\PromiseInterface |
||
287 | */ |
||
288 | public function getChannelMember(ConnectionInterface $connection, string $channel): PromiseInterface |
||
294 | |||
295 | /** |
||
296 | * Get the presence channels total members count. |
||
297 | * |
||
298 | * @param string|int $appId |
||
299 | * @param array $channelNames |
||
300 | * @return \React\Promise\PromiseInterface |
||
301 | */ |
||
302 | public function getChannelsMembersCount($appId, array $channelNames): PromiseInterface |
||
315 | |||
316 | /** |
||
317 | * Get the channel class by the channel name. |
||
318 | * |
||
319 | * @param string $channelName |
||
320 | * @return string |
||
321 | */ |
||
322 | protected function getChannelClassName(string $channelName): string |
||
334 | } |
||
335 |
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.