File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 1616use Hyperf \WebSocketClient \Exception \ConnectException ;
1717use Psr \Http \Message \UriInterface ;
1818use Swoole \Coroutine ;
19+ use Swoole \WebSocket \CloseFrame as SwCloseFrame ;
1920use Swoole \WebSocket \Frame as SwFrame ;
2021
2122class Client
@@ -63,11 +64,12 @@ public function __destruct()
6364 public function recv (float $ timeout = -1 )
6465 {
6566 $ ret = $ this ->client ->recv ($ timeout );
66- if ($ ret instanceof SwFrame) {
67- return new Frame ($ ret );
68- }
6967
70- return $ ret ;
68+ return match (true ) {
69+ $ ret instanceof SwCloseFrame => new CloseFrame ($ ret ),
70+ $ ret instanceof SwFrame => new Frame ($ ret ),
71+ default => $ ret ,
72+ };
7173 }
7274
7375 /**
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+ /**
5+ * This file is part of Hyperf.
6+ *
7+ * @link https://www.hyperf.io
8+ * @document https://hyperf.wiki
9+ * @contact group@hyperf.io
10+ * @license https://github.com/hyperf/hyperf/blob/master/LICENSE
11+ */
12+
13+ namespace Hyperf \WebSocketClient ;
14+
15+ use Swoole \WebSocket \CloseFrame as SwCloseFrame ;
16+
17+ class CloseFrame extends Frame
18+ {
19+ public int $ code = WEBSOCKET_CLOSE_NORMAL ;
20+
21+ public string $ reason = '' ;
22+
23+ public function __construct (SwCloseFrame $ frame )
24+ {
25+ parent ::__construct ($ frame );
26+
27+ $ this ->code = $ frame ->code ;
28+ $ this ->reason = $ frame ->reason ;
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments