Total Complexity | 4 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class WebsocketHandler implements HandlerContract |
||
13 | { |
||
14 | /** |
||
15 | * "onOpen" listener. |
||
16 | * |
||
17 | * @param int $fd |
||
18 | * @param \Illuminate\Http\Request $request |
||
19 | * |
||
20 | * @return bool |
||
21 | */ |
||
22 | public function onOpen($fd, Request $request) |
||
23 | { |
||
24 | if (! $request->input('sid')) { |
||
25 | $payload = json_encode( |
||
26 | [ |
||
27 | 'sid' => base64_encode(uniqid()), |
||
28 | 'upgrades' => [], |
||
29 | 'pingInterval' => Config::get('swoole_websocket.ping_interval'), |
||
30 | 'pingTimeout' => Config::get('swoole_websocket.ping_timeout'), |
||
31 | ] |
||
32 | ); |
||
33 | $initPayload = Packet::OPEN . $payload; |
||
34 | $connectPayload = Packet::MESSAGE . Packet::CONNECT; |
||
35 | |||
36 | App::make(Server::class)->push($fd, $initPayload); |
||
37 | App::make(Server::class)->push($fd, $connectPayload); |
||
38 | |||
39 | return true; |
||
40 | } |
||
41 | |||
42 | return false; |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * "onMessage" listener. |
||
47 | * only triggered when event handler not found |
||
48 | * |
||
49 | * @param \Swoole\Websocket\Frame $frame |
||
50 | */ |
||
51 | public function onMessage(Frame $frame) |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * "onClose" listener. |
||
58 | * |
||
59 | * @param int $fd |
||
60 | * @param int $reactorId |
||
61 | */ |
||
62 | public function onClose($fd, $reactorId) |
||
65 | } |
||
66 | } |
||
67 |