1 | <?php |
||
22 | class WebSocketHandler implements MessageComponentInterface |
||
23 | { |
||
24 | /** |
||
25 | * The channel manager. |
||
26 | * |
||
27 | * @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager |
||
28 | */ |
||
29 | protected $channelManager; |
||
30 | |||
31 | /** |
||
32 | * The replicator client. |
||
33 | * |
||
34 | * @var ReplicationInterface |
||
35 | */ |
||
36 | protected $replicator; |
||
37 | |||
38 | /** |
||
39 | * Initialize a new handler. |
||
40 | * |
||
41 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
42 | * @return void |
||
|
|||
43 | */ |
||
44 | public function __construct(ChannelManager $channelManager) |
||
49 | |||
50 | /** |
||
51 | * Handle the socket opening. |
||
52 | * |
||
53 | * @param \Ratchet\ConnectionInterface $connection |
||
54 | * @return void |
||
55 | */ |
||
56 | public function onOpen(ConnectionInterface $connection) |
||
64 | |||
65 | /** |
||
66 | * Handle the incoming message. |
||
67 | * |
||
68 | * @param \Ratchet\ConnectionInterface $connection |
||
69 | * @param \Ratchet\RFC6455\Messaging\MessageInterface $message |
||
70 | * @return void |
||
71 | */ |
||
72 | public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
||
80 | |||
81 | /** |
||
82 | * Handle the websocket close. |
||
83 | * |
||
84 | * @param \Ratchet\ConnectionInterface $connection |
||
85 | * @return void |
||
86 | */ |
||
87 | public function onClose(ConnectionInterface $connection) |
||
99 | |||
100 | /** |
||
101 | * Handle the websocket errors. |
||
102 | * |
||
103 | * @param \Ratchet\ConnectionInterface $connection |
||
104 | * @param WebSocketException $exception |
||
105 | * @return void |
||
106 | */ |
||
107 | public function onError(ConnectionInterface $connection, Exception $exception) |
||
117 | |||
118 | /** |
||
119 | * Verify the app key validity. |
||
120 | * |
||
121 | * @param \Ratchet\ConnectionInterface $connection |
||
122 | * @return $this |
||
123 | */ |
||
124 | protected function verifyAppKey(ConnectionInterface $connection) |
||
136 | |||
137 | /** |
||
138 | * Verify the origin. |
||
139 | * |
||
140 | * @param \Ratchet\ConnectionInterface $connection |
||
141 | * @return $this |
||
142 | */ |
||
143 | protected function verifyOrigin(ConnectionInterface $connection) |
||
159 | |||
160 | /** |
||
161 | * Limit the connections count by the app. |
||
162 | * |
||
163 | * @param \Ratchet\ConnectionInterface $connection |
||
164 | * @return $this |
||
165 | */ |
||
166 | protected function limitConcurrentConnections(ConnectionInterface $connection) |
||
182 | |||
183 | /** |
||
184 | * Create a socket id. |
||
185 | * |
||
186 | * @param \Ratchet\ConnectionInterface $connection |
||
187 | * @return $this |
||
188 | */ |
||
189 | protected function generateSocketId(ConnectionInterface $connection) |
||
197 | |||
198 | /** |
||
199 | * Establish connection with the client. |
||
200 | * |
||
201 | * @param \Ratchet\ConnectionInterface $connection |
||
202 | * @return $this |
||
203 | */ |
||
204 | protected function establishConnection(ConnectionInterface $connection) |
||
228 | |||
229 | /** |
||
230 | * Throw a ConnectionsOverCapacity exception. |
||
231 | * |
||
232 | * @param int $connectionsCount |
||
233 | * @param int $capacity |
||
234 | * @return void |
||
235 | * @throws ConnectionsOverCapacity |
||
236 | */ |
||
237 | protected function throwExceptionIfOverCapacity(int $connectionsCount, int $capacity) |
||
243 | |||
244 | /** |
||
245 | * Send the ConnectionsOverCapacity exception through |
||
246 | * the connection and close the channel. |
||
247 | * |
||
248 | * @param int $connectionsCount |
||
249 | * @param int $capacity |
||
250 | * @param ConnectionInterface $connection |
||
251 | * @return void |
||
252 | */ |
||
253 | protected function sendExceptionIfOverCapacity(int $connectionsCount, int $capacity, ConnectionInterface $connection) |
||
261 | } |
||
262 |
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.