@nht-pandats/sdk / @nht-pandats/sdk/clients / @nht-pandats/sdk/clients/socket.io / SocketClient
Class: SocketClient
@nht-pandats/sdk/clients.@nht-pandats/sdk/clients/socket.io.SocketClient
A strongly typed & opinionated client for interacting with the PandaTS socket.io API
Constructors
constructor
• new SocketClient(brandOrHost?, apiDomain?, unsafe?): SocketClient
Create a new SocketClient instance
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
brandOrHost | string | URL | 'panda-fx' | Brand prefix or websocket host for connecting to the API |
apiDomain | string | 'pandats-client.io' | Top level domain of the websocket server host |
unsafe | boolean | false | If to allow connections which do not verify SSL connections |
Returns
Defined in
src/clients/socket.io/index.ts:212
Accessors
connected
• get connected(): null | boolean
Gets the current connection state of the socket.
Returns
null | boolean
The current connection state of the socket. Returns null if the socket is reconnecting
Defined in
src/clients/socket.io/index.ts:264
lastPingAt
• get lastPingAt(): any
Gets the timestamp of the last ping sent from the socket server.
Returns
any
The timestamp of the last ping sent from the socket server. Returns null if no ping has been sent yet.
Defined in
src/clients/socket.io/index.ts:282
pressure
• get pressure(): number
Gets the number of pending requests waiting for a response from the server.
Returns
number
The number of pending requests.
Defined in
src/clients/socket.io/index.ts:291
time
• get time(): any
Gets the current time of the socket server.
Returns
any
The current time of the socket server.
Defined in
src/clients/socket.io/index.ts:273
Methods
clear
▸ clear(event?): void
Parameters
| Name | Type |
|---|---|
event? | string |
Returns
void
Defined in
src/clients/socket.io/index.ts:560
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "connect" |
Returns
void
Defined in
src/clients/socket.io/index.ts:561
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "disconnect" |
Returns
void
Defined in
src/clients/socket.io/index.ts:562
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "error" |
Returns
void
Defined in
src/clients/socket.io/index.ts:563
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "time" |
Returns
void
Defined in
src/clients/socket.io/index.ts:564
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "ping" |
Returns
void
Defined in
src/clients/socket.io/index.ts:565
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "quotes" |
Returns
void
Defined in
src/clients/socket.io/index.ts:566
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "quotes:object" |
Returns
void
Defined in
src/clients/socket.io/index.ts:567
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "loginToken" |
Returns
void
Defined in
src/clients/socket.io/index.ts:568
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "refreshClient" |
Returns
void
Defined in
src/clients/socket.io/index.ts:569
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "refreshSite" |
Returns
void
Defined in
src/clients/socket.io/index.ts:570
▸ clear(event): void
Parameters
| Name | Type |
|---|---|
event | "blStatus" |
Returns
void
Defined in
src/clients/socket.io/index.ts:571
connect
▸ connect(timeout?): Promise<void>
Connects the socket to the server.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
timeout | number | 5000 | The maximum amount of time to wait for the connection to be established, in milliseconds. Defaults to 5000. |
Returns
Promise<void>
A Promise that resolves when the connection is established, or rejects if an error occurs or the timeout is exceeded.
Throws
If the timeout is greater than 15 seconds or less than 0.
Throws
If the connection fails to connect after the timeout period.
Defined in
src/clients/socket.io/index.ts:343
disconnect
▸ disconnect(timeout?): Promise<void>
Disconnects the socket from the server.
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
timeout | number | 5000 | The maximum amount of time to wait for the disconnection to be completed, in milliseconds. Defaults to 5000. |
Returns
Promise<void>
A Promise that resolves when the disconnection is completed, or rejects if an error occurs or the timeout is exceeded.
Throws
If the timeout is less than 0.
Throws
If the disconnection fails to complete after the timeout period.
Defined in
src/clients/socket.io/index.ts:379
off
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | string |
cb | EventCallback |
Returns
void
Defined in
src/clients/socket.io/index.ts:544
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "connect" |
cb | () => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:545
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "disconnect" |
cb | (reason: string) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:546
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "error" |
cb | (err: Error) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:547
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "time" |
cb | (time: DateTime) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:548
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "ping" |
cb | (latency: number, at: DateTime) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:549
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "quotes" |
cb | (quotes: Quote[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:550
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "quotes:object" |
cb | (quotes: QuoteObject[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:551
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "loginToken" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:552
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "refreshClient" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:553
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "refreshSite" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:554
▸ off(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "blStatus" |
cb | (info: PandaApiResponse<BaseResponse>) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:555
on
▸ on(event, cb): void
Registers a callback function to be executed when the specified event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | string | The name of the event to listen for. |
cb | EventCallback | The callback function to execute when the event is emitted. |
Returns
void
Defined in
src/clients/socket.io/index.ts:413
▸ on(event, cb): void
Registers a callback function to be executed when the 'connect' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "connect" | The name of the event to listen for. |
cb | () => void | The callback function to execute when the event is emitted. |
Returns
void
See
https://socket.io/docs/v4/client-api/#event-connect
Defined in
src/clients/socket.io/index.ts:421
▸ on(event, cb): void
Registers a callback function to be executed when the 'disconnect' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "disconnect" | The name of the event to listen for. |
cb | (reason: string) => void | The callback function to execute when the event is emitted. |
Returns
void
See
https://socket.io/docs/v4/client-api/#event-disconnect
Defined in
src/clients/socket.io/index.ts:429
▸ on(event, cb): void
Registers a callback function to be executed when the 'error' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "error" | The name of the event to listen for. |
cb | (err: Error) => void | The callback function to execute when the event is emitted. |
Returns
void
Remark
This occurs on any error caused by the socket.io connection. It does not occur on request responses
See
https://socket.io/docs/v4/client-api/#event-connect_error
Defined in
src/clients/socket.io/index.ts:440
▸ on(event, cb): void
Registers a callback function to be executed when the 'time' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "time" | The name of the event to listen for. |
cb | (time: DateTime) => void | The callback function to execute when the event is emitted. |
Returns
void
Remark
The time is an event which is triggered by the PandaTS Socket.IO API It represents the current server time, and has been converted to a Luxon DateTime object for ease of consumption
Defined in
src/clients/socket.io/index.ts:453
▸ on(event, cb): void
Registers a callback function to be executed when the 'ping' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "ping" | The name of the event to listen for. |
cb | (latency: number, at: DateTime) => void | The callback function to execute when the event is emitted. |
Returns
void
Remark
The "ping" event is actually the "pong" event sent by the PandaTS Socket.IO API The pong event determines how much latency there is between the client and the server Additionally, we append a DateTime object to the event to allow for easy consumption
Defined in
src/clients/socket.io/index.ts:466
▸ on(event, cb): void
Registers a callback function to be executed when the 'quotes' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "quotes" | The name of the event to listen for. |
cb | (quotes: Quote[]) => void | The callback function to execute when the event is emitted. |
Returns
void
Remark
The "quotes" event is an event which occurs after the SocketClient.quotesSubscribe method is called. This version of the event passes the quote as an array of numbers, while the timestamp has been converted into a DateTime object for easier consumption
Defined in
src/clients/socket.io/index.ts:479
▸ on(event, cb): void
Registers a callback function to be executed when the 'quotes:object' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "quotes:object" | The name of the event to listen for. |
cb | (quotes: QuoteObject[]) => void | The callback function to execute when the event is emitted. |
Returns
void
Remark
The "quotes" event is an event which occurs after the SocketClient.quotesSubscribe method is called. This version of the event passes the quote as an object for easier consumption
Defined in
src/clients/socket.io/index.ts:490
▸ on(event, cb): void
Registers a callback function to be executed when the 'loginToken' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "loginToken" | The name of the event to listen for. |
cb | (...args: unknown[]) => void | The callback function to execute when the event is emitted. |
Returns
void
Defined in
src/clients/socket.io/index.ts:497
▸ on(event, cb): void
Registers a callback function to be executed when the 'refreshClient' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "refreshClient" | The name of the event to listen for. |
cb | (...args: unknown[]) => void | The callback function to execute when the event is emitted. |
Returns
void
Defined in
src/clients/socket.io/index.ts:504
▸ on(event, cb): void
Registers a callback function to be executed when the 'refreshSite' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "refreshSite" | The name of the event to listen for. |
cb | (...args: unknown[]) => void | The callback function to execute when the event is emitted. |
Returns
void
Defined in
src/clients/socket.io/index.ts:511
▸ on(event, cb): void
Registers a callback function to be executed when the 'blStatus' event is emitted.
Parameters
| Name | Type | Description |
|---|---|---|
event | "blStatus" | The name of the event to listen for. |
cb | (info: PandaApiResponse<BaseResponse>) => void | The callback function to execute when the event is emitted. |
Returns
void
Defined in
src/clients/socket.io/index.ts:518
once
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | string |
cb | EventCallback |
Returns
void
Defined in
src/clients/socket.io/index.ts:528
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "connect" |
cb | () => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:529
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "disconnect" |
cb | (reason: string) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:530
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "error" |
cb | (err: Error) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:531
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "time" |
cb | (time: DateTime) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:532
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "ping" |
cb | (latency: number, at: DateTime) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:533
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "quotes" |
cb | (quotes: Quote[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:534
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "quotes:object" |
cb | (quotes: QuoteObject[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:535
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "loginToken" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:536
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "refreshClient" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:537
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "refreshSite" |
cb | (...args: unknown[]) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:538
▸ once(event, cb): void
Parameters
| Name | Type |
|---|---|
event | "blStatus" |
cb | (info: PandaApiResponse<BaseResponse>) => void |
Returns
void
Defined in
src/clients/socket.io/index.ts:539
request
▸ request<Response>(method, payload?, fingerprint?, timeout?, autoconnect?, abortController?): Promise<Response>
Sends a request to the server and returns a promise that resolves with the response.
Type parameters
| Name | Type | Description |
|---|---|---|
Response | extends BaseResponse = BaseResponse | The type of the expected response. |
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
method | string | undefined | The name of the method to call on the server. |
payload? | Record<string, unknown> | undefined | The payload to send with the request. |
fingerprint? | number | undefined | The fingerprint to include in the payload. |
timeout? | number | 10000 | The timeout for the request in milliseconds. |
autoconnect? | boolean | false | Whether to automatically connect to the server if not already connected. |
abortController? | AbortController | undefined | The AbortController to use for the request. |
Returns
Promise<Response>
A promise that resolves with the response.
Throws
If the request times out.
Throws
If not connected and autoconnect is false.
Throws
If the server returns an error code.
Throws
If the server returns an unknown error.
Throws
If the request is aborted.
Remarks
Making multiple requests to the same method at the same time using Promise.all or similar may result in unexpected behavior, since the PandaTS Socket.IO API doesn't actually return the request ID in the response, so it's not possible to match the response to the request.
Defined in
src/clients/socket.io/index.ts:602
generateFingerprint
▸ generateFingerprint(brandOrHost?, apiDomain?, index?): Promise<undefined | number>
Generate a consistant fingerprint for use with the Socket.IO API
Parameters
| Name | Type | Default value | Description |
|---|---|---|---|
brandOrHost | string | URL | 'panda-fx' | Brand Prefix or full hostname of the Socket.IO API |
apiDomain | string | 'pandats-client.io' | The Top Level Domain of the Socket.IO API |
index | number | 1 | Integer representing a variant of fingerprint to produce |
Returns
Promise<undefined | number>
a fingerprint or undefined if there is an error