1 | <?php |
||
14 | class WebSocketHandler implements MessageComponentInterface |
||
15 | { |
||
16 | /** |
||
17 | * The channel manager. |
||
18 | * |
||
19 | * @var ChannelManager |
||
20 | */ |
||
21 | protected $channelManager; |
||
22 | |||
23 | /** |
||
24 | * Initialize a new handler. |
||
25 | * |
||
26 | * @param \BeyondCode\LaravelWebSockets\Contracts\ChannelManager $channelManager |
||
27 | * @return void |
||
|
|||
28 | */ |
||
29 | public function __construct(ChannelManager $channelManager) |
||
33 | |||
34 | /** |
||
35 | * Handle the socket opening. |
||
36 | * |
||
37 | * @param \Ratchet\ConnectionInterface $connection |
||
38 | * @return void |
||
39 | */ |
||
40 | public function onOpen(ConnectionInterface $connection) |
||
66 | |||
67 | /** |
||
68 | * Handle the incoming message. |
||
69 | * |
||
70 | * @param \Ratchet\ConnectionInterface $connection |
||
71 | * @param \Ratchet\RFC6455\Messaging\MessageInterface $message |
||
72 | * @return void |
||
73 | */ |
||
74 | public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
||
86 | |||
87 | /** |
||
88 | * Handle the websocket close. |
||
89 | * |
||
90 | * @param \Ratchet\ConnectionInterface $connection |
||
91 | * @return void |
||
92 | */ |
||
93 | public function onClose(ConnectionInterface $connection) |
||
107 | |||
108 | /** |
||
109 | * Handle the websocket errors. |
||
110 | * |
||
111 | * @param \Ratchet\ConnectionInterface $connection |
||
112 | * @param WebSocketException $exception |
||
113 | * @return void |
||
114 | */ |
||
115 | public function onError(ConnectionInterface $connection, Exception $exception) |
||
123 | |||
124 | /** |
||
125 | * Check if the connection can be made for the |
||
126 | * current server instance. |
||
127 | * |
||
128 | * @param \Ratchet\ConnectionInterface $connection |
||
129 | * @return bool |
||
130 | */ |
||
131 | protected function connectionCanBeMade(ConnectionInterface $connection): bool |
||
135 | |||
136 | /** |
||
137 | * Verify the app key validity. |
||
138 | * |
||
139 | * @param \Ratchet\ConnectionInterface $connection |
||
140 | * @return $this |
||
141 | */ |
||
142 | protected function verifyAppKey(ConnectionInterface $connection) |
||
156 | |||
157 | /** |
||
158 | * Verify the origin. |
||
159 | * |
||
160 | * @param \Ratchet\ConnectionInterface $connection |
||
161 | * @return $this |
||
162 | */ |
||
163 | protected function verifyOrigin(ConnectionInterface $connection) |
||
179 | |||
180 | /** |
||
181 | * Limit the connections count by the app. |
||
182 | * |
||
183 | * @param \Ratchet\ConnectionInterface $connection |
||
184 | * @return $this |
||
185 | */ |
||
186 | protected function limitConcurrentConnections(ConnectionInterface $connection) |
||
204 | |||
205 | /** |
||
206 | * Create a socket id. |
||
207 | * |
||
208 | * @param \Ratchet\ConnectionInterface $connection |
||
209 | * @return $this |
||
210 | */ |
||
211 | protected function generateSocketId(ConnectionInterface $connection) |
||
219 | |||
220 | /** |
||
221 | * Establish connection with the client. |
||
222 | * |
||
223 | * @param \Ratchet\ConnectionInterface $connection |
||
224 | * @return $this |
||
225 | */ |
||
226 | protected function establishConnection(ConnectionInterface $connection) |
||
238 | } |
||
239 |
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.