Renamed codec to protocol

This commit is contained in:
Chris 2024-02-22 01:22:52 +01:00
parent be6955ea48
commit b0aede55b9
3 changed files with 10 additions and 8 deletions

View File

@ -28,8 +28,8 @@ class WebSocketConnection implements WebSocketInterface
/** @var string|null The name of the group that this connection has joined, or null */ /** @var string|null The name of the group that this connection has joined, or null */
private ?string $groupName = null; private ?string $groupName = null;
/** @var WebSocketCodec The frame encoder/decoder */ /** @var WebSocketProtocol The frame encoder/decoder */
private WebSocketCodec $codec; private WebSocketProtocol $codec;
private ?ConnectionGroup $group = null; private ?ConnectionGroup $group = null;
@ -41,14 +41,16 @@ class WebSocketConnection implements WebSocketInterface
private ServerRequestInterface $request; private ServerRequestInterface $request;
/** @var string|null Buffer for fragmented messages */
private ?string $buffer = null; private ?string $buffer = null;
/** @var int|null The opcode of a fragmented message */
private ?int $bufferedOp = null; private ?int $bufferedOp = null;
public function __construct(ServerRequestInterface $request, ReadableStreamInterface $inStream, WritableStreamInterface $outStream, GroupManager $groupManager) public function __construct(ServerRequestInterface $request, ReadableStreamInterface $inStream, WritableStreamInterface $outStream, GroupManager $groupManager)
{ {
// The codec is used to encode and decode frames // The codec is used to encode and decode frames
$this->codec = new WebSocketCodec(); $this->codec = new WebSocketProtocol();
$this->request = $request; $this->request = $request;
$this->inStream = $inStream; $this->inStream = $inStream;

View File

@ -14,7 +14,7 @@ use React\Stream\ReadableStreamInterface;
use React\Stream\ThroughStream; use React\Stream\ThroughStream;
use React\Stream\WritableStreamInterface; use React\Stream\WritableStreamInterface;
class WebSocketCodec class WebSocketProtocol
{ {
/** /**

View File

@ -4,13 +4,13 @@ namespace NoccyLabs\React\WebSocket;
use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversClass;
#[CoversClass(WebSocketCodec::class)] #[CoversClass(WebSocketProtocol::class)]
class WebSocketCodecTest extends \PHPUnit\Framework\TestCase class WebSocketProtocolTest extends \PHPUnit\Framework\TestCase
{ {
public function testEncodingFrames() public function testEncodingFrames()
{ {
$codec = new WebSocketCodec(); $codec = new WebSocketProtocol();
$msg = $codec->encode([ $msg = $codec->encode([
'opcode'=>WebSocketConnection::OP_PING, 'opcode'=>WebSocketConnection::OP_PING,
@ -43,7 +43,7 @@ class WebSocketCodecTest extends \PHPUnit\Framework\TestCase
public function testDecodingFrames() public function testDecodingFrames()
{ {
$codec = new WebSocketCodec(); $codec = new WebSocketProtocol();
$msg = $codec->decode("\x89\x04ping"); $msg = $codec->decode("\x89\x04ping");
$this->assertEquals([ $this->assertEquals([