WebSocketManager
A class in Alta.Api.Client, Alta.Api.Client.HighLevel.Subscriptions.
A small WebSocket client for the Alta API that sends JSON messages and routes incoming events to handlers by event name. Opens the socket lazily on the first send.
- Listed in Alta.Api.Client
Constructors
| Member | What it is |
|---|---|
WebSocketManager(string authToken, string apiKey, string uri) | Creates a WebSocketManager from authToken, apiKey and uri. |
Fields
5 private and internal fields
Methods
| Member | What it is |
|---|---|
async Task SendMessage(string path, object body) | Serialises body to JSON, wraps it in a WebsocketMessageBody with the given path and sends it, connecting first if needed. |
void SetHandler(string type, Action<string> handle) | Registers a callback for an event type. A second handler for the same type is chained after the first, not replaced. |
3 private and internal methods
| Member | What it is |
|---|---|
private Task<WebSocket> GetWebSocket() | Returns the shared socket task, opening the connection with the auth and API key headers the first time it's called. |
private void HandleError(object sender, ErrorEventArgs e) | Socket error handler; only writes the exception to the console. |
private void MessageReceived(object sender, MessageReceivedEventArgs eventArgs) | Parses each incoming message as a WebsocketResponseBody and calls the handler registered for its Event with the Content. |