Client
Client
- Full name:
\Hazaar\Warlock\Server\Client
- Parent class:
\Hazaar\Warlock\Protocol\WebSockets
- This class implements:
\Hazaar\Warlock\Interfaces\Client
Properties
log
public \Hazaar\Warlock\Server\Logger $log
address
public ?string $address
port
public int $port
id
public string $id
type
public string $type
stream
public null|false|resource $stream
closing
public bool $closing
frameBuffer
public ?string $frameBuffer
payloadBuffer
public ?string $payloadBuffer
applicationName
public string $applicationName
name
public string $name
username
public ?string $username
since
public int $since
lastContact
public int $lastContact
ping
public array<string,int> $ping
offset
Any detected time offset. This doesn't need to be exact so we don't bother worrying about latency.
public int $offset
subscriptions
This is an array of eventID and stream pairs.
public string[] $subscriptions
tasks
If the client has any child task.
public \Hazaar\Warlock\Server\Task[] $tasks
start
protected int $start
Methods
__construct
public __construct(resource $stream = null, ?\Hazaar\Map $options = null): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$stream | resource | |
$options | ?\Hazaar\Map |
__destruct
public __destruct(): mixed
initiateHandshake
Initiates a WebSocket client handshake.
public initiateHandshake(string $request): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$request | string |
recv
public recv(string& $buf): void
Parameters:
Parameter | Type | Description |
---|---|---|
$buf | string |
send
public send(string $command, mixed $payload = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$command | string | |
$payload | mixed |
disconnect
Process a stream client disconnect.
public disconnect(): bool
commandUnsubscribe
public commandUnsubscribe(string $eventID): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$eventID | string |
commandTrigger
public commandTrigger(string $eventID, mixed $data, bool $echoClient = true): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$data | mixed | |
$echoClient | bool |
sendEvent
public sendEvent(string $eventID, string $triggerID, mixed $data): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$triggerID | string | |
$data | mixed |
ping
public ping(): bool
pong
public pong(): void
checkRequestURL
Overridden method from WebSocket class to check the requested WebSocket URL is valid.
protected checkRequestURL(string $url): array<string,int|string>|bool
Parameters:
Parameter | Type | Description |
---|---|---|
$url | string |
httpResponse
Generate an HTTP response message.
protected httpResponse(int $code, string $body = null, string[] $headers = []): string
Parameters:
Parameter | Type | Description |
---|---|---|
$code | int | HTTP response code |
$body | string | The response body |
$headers | string[] | Additional headers |
write
protected write(string $frame): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$frame | string |
processFrame
Processes a client data frame.
protected processFrame(string& $frameBuffer): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$frameBuffer | string |
processCommand
protected processCommand(string $command, mixed $payload = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$command | string | |
$payload | mixed |
commandAuthorise
protected commandAuthorise(\stdClass $payload, bool $acknowledge = true): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$payload | \stdClass | |
$acknowledge | bool |
commandStatus
protected commandStatus(?\stdClass $payload = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$payload | ?\stdClass |
commandSubscribe
protected commandSubscribe(string $eventID, array<string,mixed> $filter = null): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$eventID | string | |
$filter | array<string,mixed> |
commandLog
protected commandLog(\stdClass $payload): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$payload | \stdClass |
initiateWebSocketsHandshake
Initiates a WebSocket client handshake.
private initiateWebSocketsHandshake(array<string,string> $headers): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$headers | array<string,string> |
initiateRESTHandshake
Initiates a REST client handshake.
private initiateRESTHandshake(array<string,string> $headers, string $body): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$headers | array<string,string> | |
$body | string |
Inherited methods
__construct
public __construct(string[] $allowed_protocols = []): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$allowed_protocols | string[] |
parseHeaders
public parseHeaders(string $request, string& $body = ''): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$request | string | |
$body | string |
createHandshake
protected createHandshake(string $path, string $host, ?string $origin, string $key, string[] $extra_headers = null): string
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string | |
$host | string | |
$origin | ?string | |
$key | string | |
$extra_headers | string[] |
acceptHandshake
protected acceptHandshake(string[] $headers, string[]& $responseHeaders = [], ?string $key = null, string[]& $results = []): bool|int
Parameters:
Parameter | Type | Description |
---|---|---|
$headers | string[] | |
$responseHeaders | string[] | |
$key | ?string | |
$results | string[] |
frame
protected frame(string $payload, ?string $type = null, bool $masked = true): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$payload | string | |
$type | ?string | |
$masked | bool |
getFrame
protected getFrame(string& $buffer, ?string& $payload = null): bool|int
Parameters:
Parameter | Type | Description |
---|---|---|
$buffer | string | |
$payload | ?string |
checkHost
protected checkHost(string $host): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$host | string |
checkRequestURL
protected checkRequestURL(string $path): array<string,int|string>|bool
Parameters:
Parameter | Type | Description |
---|---|---|
$path | string |
checkOrigin
protected checkOrigin(string $origin): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$origin | string |
checkProtocol
protected checkProtocol(string[]|string $protocols): string[]|false
Parameters:
Parameter | Type | Description |
---|---|---|
$protocols | string[]|string |
hexString
protected hexString(string $string): string[]
Parameters:
Parameter | Type | Description |
---|---|---|
$string | string |
getFrameHeaders
private getFrameHeaders(string $frame): (int|string)[]
Parameters:
Parameter | Type | Description |
---|---|---|
$frame | string |
applyMask
private applyMask(string[] $headers, string $payload): false|string
Parameters:
Parameter | Type | Description |
---|---|---|
$headers | string[] | |
$payload | string |
Automatically generated on 2024-11-14