Revert "改名"
This reverts commit fdf58326
This commit is contained in:
@@ -2,19 +2,81 @@
|
||||
|
||||
namespace Kiri\Websocket;
|
||||
|
||||
class Sender
|
||||
use Kiri\Kiri;
|
||||
use Swoole\{Coroutine\Http\Server as AliasServer, WebSocket\Server};
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Sender implements WebSocketInterface
|
||||
{
|
||||
|
||||
|
||||
public function push($fd, $data)
|
||||
/**
|
||||
* @var AliasServer|Server
|
||||
*/
|
||||
private AliasServer|Server $server;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->server = Kiri::getDi()->get(WebSocketInterface::class);
|
||||
}
|
||||
|
||||
|
||||
public function close($fd)
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param mixed $data
|
||||
* @param int $opcode
|
||||
* @param int $flags
|
||||
* @return bool
|
||||
*/
|
||||
public function push(int $fd, string $data, int $opcode = WEBSOCKET_OPCODE_TEXT, int $flags = SWOOLE_WEBSOCKET_FLAG_FIN): bool
|
||||
{
|
||||
|
||||
if ($this->isEstablished($fd)) {
|
||||
return $this->server->push($fd, $data, $opcode, $flags);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param int $code
|
||||
* @param string $reason
|
||||
* @return bool
|
||||
*/
|
||||
public function disconnect(int $fd, int $code = SWOOLE_WEBSOCKET_CLOSE_NORMAL, string $reason = ''): bool
|
||||
{
|
||||
if ($this->isEstablished($fd)) {
|
||||
// TODO: Implement disconnect() method.
|
||||
return $this->server->disconnect($fd, $code, $reason);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @return bool
|
||||
*/
|
||||
public function isEstablished(int $fd): bool
|
||||
{
|
||||
return $this->exist($fd) && $this->server->isEstablished($fd);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @return bool
|
||||
*/
|
||||
public function exist(int $fd): bool
|
||||
{
|
||||
return $this->server->exist($fd);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user