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.
Methods
Section titled “Methods”__construct()
Section titled “__construct()”Gateway constructor.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array | Configuration array containing ‘host’. |
$loop | LoopInterface | The ReactPHP event loop instance. |
$logger | LoggerInterface | The PSR-3 logger instance. |
$connector (optional) | ?Connector | The Ratchet Connector for WebSocket connections. |
connect()
Section titled “connect()”Connects to the WebSocket server using the provided token.
Parameters
| Parameter | Type | Description |
|---|---|---|
$token | string | The authentication token. |
Returns \PromiseInterface — Resolves when the handshake and join are complete.
sendRpc()
Section titled “sendRpc()”Sends a JSON-RPC request over the WebSocket and returns a Promise.
Parameters
| Parameter | Type | Description |
|---|---|---|
$method | string | The RPC method type (e.g., ‘query’, ‘mutation’, ‘subscription’). |
$params | array | The parameters for the RPC call. |
Returns \PromiseInterface — Resolves with the response data, or rejects on error.
subscribeRpc()
Section titled “subscribeRpc()”Sends a JSON-RPC subscription request and registers a persistent callback.
Parameters
| Parameter | Type | Description |
|---|---|---|
$path | string | The subscription path (e.g., ‘messages.create’). |
$callback | callable | The function to trigger when an event arrives. |
disconnect()
Section titled “disconnect()”Safely closes the current WebSocket connection.
Rejects all pending RPC Promises to prevent memory leaks across reconnect attempts.