Skip to content

@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 ​

NameTypeDefault valueDescription
brandOrHoststring | URL'panda-fx'Brand prefix or websocket host for connecting to the API
apiDomainstring'pandats-client.io'Top level domain of the websocket server host
unsafebooleanfalseIf to allow connections which do not verify SSL connections

Returns ​

SocketClient

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 ​

NameType
event?string

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:560

▸ clear(event): void

Parameters ​

NameType
event"connect"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:561

▸ clear(event): void

Parameters ​

NameType
event"disconnect"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:562

▸ clear(event): void

Parameters ​

NameType
event"error"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:563

▸ clear(event): void

Parameters ​

NameType
event"time"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:564

▸ clear(event): void

Parameters ​

NameType
event"ping"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:565

▸ clear(event): void

Parameters ​

NameType
event"quotes"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:566

▸ clear(event): void

Parameters ​

NameType
event"quotes:object"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:567

▸ clear(event): void

Parameters ​

NameType
event"loginToken"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:568

▸ clear(event): void

Parameters ​

NameType
event"refreshClient"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:569

▸ clear(event): void

Parameters ​

NameType
event"refreshSite"

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:570

▸ clear(event): void

Parameters ​

NameType
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 ​

NameTypeDefault valueDescription
timeoutnumber5000The 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 ​

NameTypeDefault valueDescription
timeoutnumber5000The 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 ​

NameType
eventstring
cbEventCallback

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:544

▸ off(event, cb): void

Parameters ​

NameType
event"connect"
cb() => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:545

▸ off(event, cb): void

Parameters ​

NameType
event"disconnect"
cb(reason: string) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:546

▸ off(event, cb): void

Parameters ​

NameType
event"error"
cb(err: Error) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:547

▸ off(event, cb): void

Parameters ​

NameType
event"time"
cb(time: DateTime) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:548

▸ off(event, cb): void

Parameters ​

NameType
event"ping"
cb(latency: number, at: DateTime) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:549

▸ off(event, cb): void

Parameters ​

NameType
event"quotes"
cb(quotes: Quote[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:550

▸ off(event, cb): void

Parameters ​

NameType
event"quotes:object"
cb(quotes: QuoteObject[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:551

▸ off(event, cb): void

Parameters ​

NameType
event"loginToken"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:552

▸ off(event, cb): void

Parameters ​

NameType
event"refreshClient"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:553

▸ off(event, cb): void

Parameters ​

NameType
event"refreshSite"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:554

▸ off(event, cb): void

Parameters ​

NameType
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 ​

NameTypeDescription
eventstringThe name of the event to listen for.
cbEventCallbackThe 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 ​

NameTypeDescription
event"connect"The name of the event to listen for.
cb() => voidThe 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 ​

NameTypeDescription
event"disconnect"The name of the event to listen for.
cb(reason: string) => voidThe 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 ​

NameTypeDescription
event"error"The name of the event to listen for.
cb(err: Error) => voidThe 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 ​

NameTypeDescription
event"time"The name of the event to listen for.
cb(time: DateTime) => voidThe 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 ​

NameTypeDescription
event"ping"The name of the event to listen for.
cb(latency: number, at: DateTime) => voidThe 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 ​

NameTypeDescription
event"quotes"The name of the event to listen for.
cb(quotes: Quote[]) => voidThe 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 ​

NameTypeDescription
event"quotes:object"The name of the event to listen for.
cb(quotes: QuoteObject[]) => voidThe 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 ​

NameTypeDescription
event"loginToken"The name of the event to listen for.
cb(...args: unknown[]) => voidThe 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 ​

NameTypeDescription
event"refreshClient"The name of the event to listen for.
cb(...args: unknown[]) => voidThe 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 ​

NameTypeDescription
event"refreshSite"The name of the event to listen for.
cb(...args: unknown[]) => voidThe 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 ​

NameTypeDescription
event"blStatus"The name of the event to listen for.
cb(info: PandaApiResponse<BaseResponse>) => voidThe 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 ​

NameType
eventstring
cbEventCallback

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:528

▸ once(event, cb): void

Parameters ​

NameType
event"connect"
cb() => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:529

▸ once(event, cb): void

Parameters ​

NameType
event"disconnect"
cb(reason: string) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:530

▸ once(event, cb): void

Parameters ​

NameType
event"error"
cb(err: Error) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:531

▸ once(event, cb): void

Parameters ​

NameType
event"time"
cb(time: DateTime) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:532

▸ once(event, cb): void

Parameters ​

NameType
event"ping"
cb(latency: number, at: DateTime) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:533

▸ once(event, cb): void

Parameters ​

NameType
event"quotes"
cb(quotes: Quote[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:534

▸ once(event, cb): void

Parameters ​

NameType
event"quotes:object"
cb(quotes: QuoteObject[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:535

▸ once(event, cb): void

Parameters ​

NameType
event"loginToken"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:536

▸ once(event, cb): void

Parameters ​

NameType
event"refreshClient"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:537

▸ once(event, cb): void

Parameters ​

NameType
event"refreshSite"
cb(...args: unknown[]) => void

Returns ​

void

Defined in ​

src/clients/socket.io/index.ts:538

▸ once(event, cb): void

Parameters ​

NameType
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 ​

NameTypeDescription
Responseextends BaseResponse = BaseResponseThe type of the expected response.

Parameters ​

NameTypeDefault valueDescription
methodstringundefinedThe name of the method to call on the server.
payload?Record<string, unknown>undefinedThe payload to send with the request.
fingerprint?numberundefinedThe fingerprint to include in the payload.
timeout?number10000The timeout for the request in milliseconds.
autoconnect?booleanfalseWhether to automatically connect to the server if not already connected.
abortController?AbortControllerundefinedThe 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 ​

NameTypeDefault valueDescription
brandOrHoststring | URL'panda-fx'Brand Prefix or full hostname of the Socket.IO API
apiDomainstring'pandats-client.io'The Top Level Domain of the Socket.IO API
indexnumber1Integer representing a variant of fingerprint to produce

Returns ​

Promise<undefined | number>

a fingerprint or undefined if there is an error

Defined in ​

src/clients/socket.io/index.ts:1021