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) |
||
62 | |||
63 | /** |
||
64 | * Handle the incoming message. |
||
65 | * |
||
66 | * @param \Ratchet\ConnectionInterface $connection |
||
67 | * @param \Ratchet\RFC6455\Messaging\MessageInterface $message |
||
68 | * @return void |
||
69 | */ |
||
70 | public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
||
78 | |||
79 | /** |
||
80 | * Handle the websocket close. |
||
81 | * |
||
82 | * @param \Ratchet\ConnectionInterface $connection |
||
83 | * @return void |
||
84 | */ |
||
85 | 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) |
||
115 | |||
116 | /** |
||
117 | * Verify the app key validity. |
||
118 | * |
||
119 | * @param \Ratchet\ConnectionInterface $connection |
||
120 | * @return $this |
||
121 | */ |
||
122 | 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) |
||
184 | |||
185 | /** |
||
186 | * Create a socket id. |
||
187 | * |
||
188 | * @param \Ratchet\ConnectionInterface $connection |
||
189 | * @return $this |
||
190 | */ |
||
191 | protected function generateSocketId(ConnectionInterface $connection) |
||
199 | |||
200 | /** |
||
201 | * Establish connection with the client. |
||
202 | * |
||
203 | * @param \Ratchet\ConnectionInterface $connection |
||
204 | * @return $this |
||
205 | */ |
||
206 | protected function establishConnection(ConnectionInterface $connection) |
||
218 | } |
||
219 |
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.