Skip to content

Gateway

Class  ·  Sharkord\WebSocket\Gateway

Class Gateway

Responsible for managing the persistent WebSocket connection to the Sharkord API, handling the handshake, and routing JSON-RPC requests and subscriptions.

Gateway constructor.

Parameters

ParameterTypeDescription
$configarrayConfiguration array containing ‘host’.
$loopLoopInterfaceThe ReactPHP event loop instance.
$loggerLoggerInterfaceThe PSR-3 logger instance.
$connector (optional)?ConnectorThe Ratchet Connector for WebSocket connections.

Connects to the WebSocket server using the provided token.

Parameters

ParameterTypeDescription
$tokenstringThe authentication token.

Returns \PromiseInterface — Resolves when the handshake and join are complete.


Sends a JSON-RPC request over the WebSocket and returns a Promise.

Parameters

ParameterTypeDescription
$methodstringThe RPC method type (e.g., ‘query’, ‘mutation’, ‘subscription’).
$paramsarrayThe parameters for the RPC call.

Returns \PromiseInterface — Resolves with the response data, or rejects on error.


Sends a JSON-RPC subscription request and registers a persistent callback.

Parameters

ParameterTypeDescription
$pathstringThe subscription path (e.g., ‘messages.create’).
$callbackcallableThe function to trigger when an event arrives.

Safely closes the current WebSocket connection.

Rejects all pending RPC Promises to prevent memory leaks across reconnect attempts.