1 | <?php |
||
11 | class ServerHandler extends WebSocket |
||
12 | { |
||
13 | |||
14 | /* |
||
15 | * if You need to parse URI context like /messanger/chat/JKN324jn4213 |
||
16 | * You can do so by placing URI parts into an array - $pathParams, when Socket will receive a connection |
||
17 | * this variable will be appropriately set to key => value pairs, ex.: ':context' => 'chat' |
||
18 | * Otherwise leave $pathParams as an empty array |
||
19 | */ |
||
20 | |||
21 | public $pathParams = [':entity', ':context', ':token']; |
||
22 | private $clients = []; |
||
23 | |||
24 | private $log; |
||
25 | |||
26 | /** |
||
27 | * ServerHandler constructor. |
||
28 | * |
||
29 | * @throws \Exception |
||
30 | */ |
||
31 | public function __construct() |
||
37 | |||
38 | public function onOpen(ConnectionContract $conn) |
||
44 | |||
45 | public function onMessage(ConnectionContract $recv, $msg) |
||
50 | |||
51 | public function onClose(ConnectionContract $conn) |
||
56 | |||
57 | /** |
||
58 | * @param ConnectionContract $conn |
||
59 | * @param WebSocketException $ex |
||
60 | */ |
||
61 | public function onError(ConnectionContract $conn, WebSocketException $ex) |
||
65 | |||
66 | /** |
||
67 | * You may want to implement these methods to bring ping/pong events |
||
68 | * @param ConnectionContract $conn |
||
69 | * @param string $msg |
||
70 | */ |
||
71 | public function onPing(ConnectionContract $conn, $msg) |
||
75 | |||
76 | /** |
||
77 | * @param ConnectionContract $conn |
||
78 | * @param $msg |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public function onPong(ConnectionContract $conn, $msg) |
||
85 | } |
||
86 |