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

View File

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

View File

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