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 16
16
use Hyperf \WebSocketClient \Exception \ConnectException ;
17
17
use Psr \Http \Message \UriInterface ;
18
18
use Swoole \Coroutine ;
19
+ use Swoole \WebSocket \CloseFrame as SwCloseFrame ;
19
20
use Swoole \WebSocket \Frame as SwFrame ;
20
21
21
22
class Client
@@ -63,11 +64,12 @@ public function __destruct()
63
64
public function recv (float $ timeout = -1 )
64
65
{
65
66
$ ret = $ this ->client ->recv ($ timeout );
66
- if ($ ret instanceof SwFrame) {
67
- return new Frame ($ ret );
68
- }
69
67
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
+ };
71
73
}
72
74
73
75
/**
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