1 | <?php |
||
21 | class WebSocketHandler implements MessageComponentInterface |
||
22 | { |
||
23 | /** |
||
24 | * The channel manager. |
||
25 | * |
||
26 | * @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager |
||
27 | */ |
||
28 | protected $channelManager; |
||
29 | |||
30 | /** |
||
31 | * The replicator client. |
||
32 | * |
||
33 | * @var ReplicationInterface |
||
34 | */ |
||
35 | protected $replicator; |
||
36 | |||
37 | /** |
||
38 | * Initialize a new handler. |
||
39 | * |
||
40 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
41 | * @return void |
||
|
|||
42 | */ |
||
43 | public function __construct(ChannelManager $channelManager) |
||
48 | |||
49 | /** |
||
50 | * Handle the socket opening. |
||
51 | * |
||
52 | * @param \Ratchet\ConnectionInterface $connection |
||
53 | * @return void |
||
54 | */ |
||
55 | public function onOpen(ConnectionInterface $connection) |
||
63 | |||
64 | /** |
||
65 | * Handle the incoming message. |
||
66 | * |
||
67 | * @param \Ratchet\ConnectionInterface $connection |
||
68 | * @param \Ratchet\RFC6455\Messaging\MessageInterface $message |
||
69 | * @return void |
||
70 | */ |
||
71 | public function onMessage(ConnectionInterface $connection, MessageInterface $message) |
||
79 | |||
80 | /** |
||
81 | * Handle the websocket close. |
||
82 | * |
||
83 | * @param \Ratchet\ConnectionInterface $connection |
||
84 | * @return void |
||
85 | */ |
||
86 | public function onClose(ConnectionInterface $connection) |
||
98 | |||
99 | /** |
||
100 | * Handle the websocket errors. |
||
101 | * |
||
102 | * @param \Ratchet\ConnectionInterface $connection |
||
103 | * @param WebSocketException $exception |
||
104 | * @return void |
||
105 | */ |
||
106 | public function onError(ConnectionInterface $connection, Exception $exception) |
||
116 | |||
117 | /** |
||
118 | * Verify the app key validity. |
||
119 | * |
||
120 | * @param \Ratchet\ConnectionInterface $connection |
||
121 | * @return $this |
||
122 | */ |
||
123 | protected function verifyAppKey(ConnectionInterface $connection) |
||
135 | |||
136 | /** |
||
137 | * Verify the origin. |
||
138 | * |
||
139 | * @param \Ratchet\ConnectionInterface $connection |
||
140 | * @return $this |
||
141 | */ |
||
142 | protected function verifyOrigin(ConnectionInterface $connection) |
||
158 | |||
159 | /** |
||
160 | * Limit the connections count by the app. |
||
161 | * |
||
162 | * @param \Ratchet\ConnectionInterface $connection |
||
163 | * @return $this |
||
164 | */ |
||
165 | protected function limitConcurrentConnections(ConnectionInterface $connection) |
||
177 | |||
178 | /** |
||
179 | * Create a socket id. |
||
180 | * |
||
181 | * @param \Ratchet\ConnectionInterface $connection |
||
182 | * @return $this |
||
183 | */ |
||
184 | protected function generateSocketId(ConnectionInterface $connection) |
||
192 | |||
193 | /** |
||
194 | * Establish connection with the client. |
||
195 | * |
||
196 | * @param \Ratchet\ConnectionInterface $connection |
||
197 | * @return $this |
||
198 | */ |
||
199 | protected function establishConnection(ConnectionInterface $connection) |
||
223 | } |
||
224 |
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.