1313
1414use Hyperf \Contract \ConfigInterface ;
1515use Hyperf \Contract \StdoutLoggerInterface ;
16+ use Hyperf \Engine \Contract \WebSocket \FrameInterface ;
17+ use Hyperf \Engine \WebSocket \Response as WsResponse ;
1618use Hyperf \Server \CoroutineServer ;
1719use Hyperf \WebSocketServer \Exception \InvalidMethodException ;
1820use Psr \Container \ContainerInterface ;
2123use Swoole \Server ;
2224use Swow \Psr7 \Server \ServerConnection ;
2325
26+ use function Hyperf \Engine \swoole_get_flags_from_frame ;
27+
2428/**
2529 * @method push(int $fd, $data, int $opcode = null, $finish = null)
2630 * @method disconnect(int $fd, int $code = null, string $reason = null)
@@ -56,6 +60,7 @@ public function __call($name, $arguments)
5660 if ($ method === 'disconnect ' ) {
5761 $ method = 'close ' ;
5862 }
63+
5964 $ this ->responses [$ fd ]->{$ method }(...$ arguments );
6065 $ this ->logger ->debug ("[WebSocket] Worker send to # {$ fd }" );
6166 }
@@ -67,6 +72,24 @@ public function __call($name, $arguments)
6772 }
6873 }
6974
75+ public function pushFrame (int $ fd , FrameInterface $ frame ): bool
76+ {
77+ if ($ this ->isCoroutineServer ) {
78+ if (isset ($ this ->responses [$ fd ])) {
79+ return (new WsResponse ($ this ->responses [$ fd ]))->init ($ fd )->push ($ frame );
80+ }
81+
82+ return false ;
83+ }
84+
85+ if ($ this ->check ($ fd )) {
86+ return (new WsResponse ($ this ->getServer ()))->init ($ fd )->push ($ frame );
87+ }
88+
89+ $ this ->sendPipeMessage ('push ' , [$ fd , (string ) $ frame ->getPayloadData (), $ frame ->getOpcode (), swoole_get_flags_from_frame ($ frame )]);
90+ return false ;
91+ }
92+
7093 public function proxy (int $ fd , string $ method , array $ arguments ): bool
7194 {
7295 $ result = $ this ->check ($ fd );
0 commit comments