Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"nyholm/psr7": "^1.4",
"phrity/http": "^1.1",
"phrity/net-uri": "^2.1",
"phrity/net-stream": "^2.3",
"phrity/net-stream": "dev-ws4 as 2.3.99",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/log": "^1.0 || ^2.0 || ^3.0"
Expand All @@ -39,7 +39,7 @@
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.0 || ^11.0 || ^12.0",
"phrity/logger-console": "^1.0",
"phrity/net-mock": "^2.3",
"phrity/net-mock": "dev-ws4 as 2.3.99",
"phrity/util-errorhandler": "^1.1",
"robiningelbrecht/phpunit-coverage-tools": "^1.9",
"squizlabs/php_codesniffer": "^4.0"
Expand Down
2 changes: 2 additions & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Configuration class for various settings (@sirn-se)
* Identity interface and implementation (@sirn-se)
* Using Nyholm PSR HTTP (intermediate solution) (@sirn-se)
* Runner class wraps stream-select handler (@sirn-se)
* StreamFactory as constructor option Client/Server (@sirn-se)
* Preparations for v4 (@sirn-se)

## `v3.6`
Expand Down
46 changes: 19 additions & 27 deletions docs/Class_Synopsis.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class WebSocket\Client imlements WebSocket\Runtime\IdentityInterface, Psr\Log\Lo
use WebSocket\Trait\SendMethodsTrait;
use WebSocket\Trait\StringableTrait;

public method __construct(Psr\Http\Message\UriInterface|string $uri, WebSocket\Configuration|null $configuration = null);
public method __construct(Psr\Http\Message\UriInterface|string $uri, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null);
public method __toString(): string;
public method addHeader(string $name, string $content): self;
public method addMiddleware(WebSocket\Middleware\MiddlewareInterface $middleware): self;
Expand Down Expand Up @@ -85,14 +85,13 @@ class WebSocket\Configuration imlements Psr\Log\LoggerAwareInterface, Stringable
public method setTimeout(int|float $timeout): void;
}

class WebSocket\Connection imlements WebSocket\Runtime\IdentityInterface, Psr\Log\LoggerAwareInterface, Stringable
class WebSocket\Connection imlements WebSocket\Runtime\IdentityInterface, Psr\Log\LoggerAwareInterface, Phrity\Net\StreamContainerInterface, Stringable
{
use WebSocket\Trait\ConfigurationTrait;
use WebSocket\Trait\SendMethodsTrait;
use WebSocket\Trait\StringableTrait;

public method __construct(Phrity\Net\SocketStream $stream, bool $pushMasked, bool $pullMaskedRequired, bool $ssl = false, Phrity\Http\HttpFactory|null $httpFactory = null, WebSocket\Configuration|null $configuration = null);
public method __destruct();
public method __toString(): string;
public method addMiddleware(WebSocket\Middleware\MiddlewareInterface $middleware): self;
public method closeRead(): self;
Expand All @@ -106,6 +105,7 @@ class WebSocket\Connection imlements WebSocket\Runtime\IdentityInterface, Psr\Lo
public method getMeta(string $key): mixed;
public method getName(): string|null;
public method getRemoteName(): string|null;
public method getStream(): Phrity\Net\SocketStream;
public method getTimeout(): int|float;
public method isConnected(): bool;
public method isReadable(): bool;
Expand Down Expand Up @@ -171,6 +171,10 @@ class WebSocket\Exception\ReconnectException extends WebSocket\Exception\Excepti
public method getUri(): Phrity\Net\Uri|null;
}

class WebSocket\Exception\RunnerException extends WebSocket\Exception\Exception
{
}

class WebSocket\Exception\ServerException extends WebSocket\Exception\Exception
{
}
Expand Down Expand Up @@ -412,14 +416,23 @@ class WebSocket\Middleware\SubprotocolNegotiation imlements Psr\Log\LoggerAwareI
public method setLogger(Psr\Log\LoggerInterface $logger): void;
}

class WebSocket\Server imlements WebSocket\Runtime\IdentityInterface, Psr\Log\LoggerAwareInterface, Stringable
class WebSocket\Runtime\Runner
{
public method __construct(Phrity\Net\StreamFactory $streamFactory);
public method attach(Phrity\Net\StreamContainerInterface $streamContainer, Closure $onSelect): void;
public method detach(string $identity): void;
public method handle(int|float $timeout): void;
public method select(int|float $timeout): Phrity\Net\StreamCollection;
}

class WebSocket\Server imlements WebSocket\Runtime\IdentityInterface, Psr\Log\LoggerAwareInterface, Phrity\Net\StreamContainerInterface, Stringable
{
use WebSocket\Trait\ConfigurationTrait;
use WebSocket\Trait\ListenerTrait;
use WebSocket\Trait\SendMethodsTrait;
use WebSocket\Trait\StringableTrait;

public method __construct(int $port = 80, bool $ssl = false, WebSocket\Configuration|null $configuration = null);
public method __construct(int $port = 80, bool $ssl = false, WebSocket\Configuration|null $configuration = null, Phrity\Net\StreamFactory|null $streamFactory = null);
public method __toString(): string;
public method addMiddleware(WebSocket\Middleware\MiddlewareInterface $middleware): self;
public method disconnect(): void;
Expand All @@ -431,6 +444,7 @@ class WebSocket\Server imlements WebSocket\Runtime\IdentityInterface, Psr\Log\Lo
public method getPort(): int;
public method getReadableConnections(): array;
public method getScheme(): string;
public method getStream(): Phrity\Net\SocketServer;
public method getTimeout(): int|float;
public method getWritableConnections(): array;
public method isRunning(): bool;
Expand Down Expand Up @@ -525,27 +539,5 @@ trait WebSocket\Trait\ListenerTrait
public method onDisconnect(Closure $closure): self;
public method onError(Closure $closure): self;
public method onHandshake(Closure $closure): self;
public method onPing(Closure $closure): self;
public method onPong(Closure $closure): self;
public method onText(Closure $closure): self;
public method onTick(Closure $closure): self;
}

trait WebSocket\Trait\OpcodeTrait
{
}

trait WebSocket\Trait\SendMethodsTrait
{
public method binary(string $message): WebSocket\Message\Binary;
public method close(int $status = 1000, string $message = "ttfn"): WebSocket\Message\Close;
public method ping(string $message = ""): WebSocket\Message\Ping;
public method pong(string $message = ""): WebSocket\Message\Pong;
public method text(string $message): WebSocket\Message\Text;
}

trait WebSocket\Trait\StringableTrait
{
public method __toString(): string;
}
```
10 changes: 9 additions & 1 deletion docs/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,17 @@ $client->close(1000, "Closing now");

## Configuration

The Client takes one argument: [URI](http://tools.ietf.org/html/rfc3986) as a class implementing [UriInterface](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface) or as string.
The Client has one required argument: [URI](http://tools.ietf.org/html/rfc3986) as a class implementing [UriInterface](https://www.php-fig.org/psr/psr-7/#35-psrhttpmessageuriinterface) or as string.
The client support `ws` (`tcp`) and `wss` (`ssl`) schemas, depending on SSL configuration.

```php
__construct(
Psr\Http\Message\UriInterface|string $uri,
WebSocket\Configuration|null $configuration = null,
Phrity\Net\StreamFactory|null $streamFactory = null,
);
```

Other options are available using the Configuration class.

- Logger
Expand Down
7 changes: 4 additions & 3 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Get and set Configuration;
```php
$configuration = $client->getConfiguration();
$client->setConfiguration($configuration);

$configuration = $server->getConfiguration();
$server->setConfiguration($configuration);
```
Expand All @@ -49,7 +50,7 @@ type: Psr\Log\LoggerInterface
default: Psr\Log\NullLogger
```

Attach any [PSR-4 compatible](https://www.php-fig.org/psr/psr-3/) logger.
Attach any [PSR-3 compatible](https://www.php-fig.org/psr/psr-3/) logger.

```php
// Configuration instance
Expand Down Expand Up @@ -104,7 +105,7 @@ default: 60
Timeout for various operations can be specified in seconds.
This affects how long Client and Server will wait for connection, read and write operations, and listener scope.
Default is `60` seconds. Minimum is `0` seconds. Accepts int or float value.
Avoid setting very low values as it will cause a read loop to use all
Avoid setting very low values as it will cause a read loop that uses lots of the
available processing power even when there's nothing to read.

```php
Expand All @@ -127,7 +128,7 @@ type: int<1, max>
default: 4096
```

Defines the maximum payload per frame size in bytes.
Defines the maximum frame payload size in bytes.
Default is `4096` bytes. Minimum is `1` byte.
Do not change unless you have a strong reason to do so.

Expand Down
11 changes: 10 additions & 1 deletion docs/Server.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,18 @@ $server->close(1000, "Closing now");

## Configuration

The Server takes two arguments; port and ssl.
The Server has two main arguments; port and ssl.
By default, ssl is false. If port is not specified, it will use 80 for non-secure and 443 for secure server.

```php
__construct(
int $port = 80,
bool $ssl = false,
WebSocket\Configuration|null $configuration = null,
Phrity\Net\StreamFactory|null $streamFactory = null,
);
```

Other options are available using the Configuration class.

- Logger
Expand Down
Loading