Skip to content

Commit 3215313

Browse files
authored
Removed requirement ext-swoole from socketio-server. (#5844)
1 parent 44cffd1 commit 3215313

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/Sender.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
use Hyperf\Contract\ConfigInterface;
1515
use Hyperf\Contract\StdoutLoggerInterface;
16+
use Hyperf\Engine\Contract\WebSocket\FrameInterface;
17+
use Hyperf\Engine\WebSocket\Response as WsResponse;
1618
use Hyperf\Server\CoroutineServer;
1719
use Hyperf\WebSocketServer\Exception\InvalidMethodException;
1820
use Psr\Container\ContainerInterface;
@@ -21,6 +23,8 @@
2123
use Swoole\Server;
2224
use 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

Comments
 (0)