Skip to main content

Class: WsEndpoint

WebSocket connection to Chronik.

Constructors

constructor

new WsEndpoint(proxyInterface, config): WsEndpoint

Parameters

NameType
proxyInterfaceFailoverProxy
configWsConfig

Returns

WsEndpoint

Defined in

src/ChronikClient.ts:289

Properties

autoReconnect

autoReconnect: boolean

Whether to automatically reconnect on disconnect, default true.

Defined in

src/ChronikClient.ts:282


connected

connected: undefined | Promise<Event>

Defined in

src/ChronikClient.ts:285


manuallyClosed

manuallyClosed: boolean

Defined in

src/ChronikClient.ts:286


onConnect

Optional onConnect: (e: Event) => void

Fired when a connection has been (re)established.

Type declaration

▸ (e): void

Parameters
NameType
eEvent
Returns

void

Defined in

src/ChronikClient.ts:264


onEnd

Optional onEnd: (e: Event) => void

Fired after a connection has been manually closed, or if autoReconnect is false, if the WebSocket disconnects for any reason.

Type declaration

▸ (e): void

Parameters
NameType
eEvent
Returns

void

Defined in

src/ChronikClient.ts:279


onError

Optional onError: (e: ErrorEvent) => void

Fired when an error with the WebSocket occurs.

Type declaration

▸ (e): void

Parameters
NameType
eErrorEvent
Returns

void

Defined in

src/ChronikClient.ts:273


onMessage

Optional onMessage: (msg: SubscribeMsg) => void

Fired when a message is sent from the WebSocket.

Type declaration

▸ (msg): void

Parameters
NameType
msgSubscribeMsg
Returns

void

Defined in

src/ChronikClient.ts:261


onReconnect

Optional onReconnect: (e: Event) => void

Fired after a connection has been unexpectedly closed, and before a reconnection attempt is made. Only fired if autoReconnect is true.

Type declaration

▸ (e): void

Parameters
NameType
eEvent
Returns

void

Defined in

src/ChronikClient.ts:270


subs

subs: { scriptPayload: string ; scriptType: ScriptType }[]

Defined in

src/ChronikClient.ts:287


ws

ws: undefined | WebSocket

Defined in

src/ChronikClient.ts:284

Methods

close

close(): void

Close the WebSocket connection and prevent future any reconnection attempts.

Returns

void

Defined in

src/ChronikClient.ts:334


handleMsg

handleMsg(wsMsg): Promise<void>

Parameters

NameType
wsMsgMessageEvent

Returns

Promise<void>

Defined in

src/ChronikClient.ts:354


subUnsub

subUnsub(isSubscribe, scriptType, scriptPayload): void

Parameters

NameType
isSubscribeboolean
scriptTypeScriptType
scriptPayloadstring

Returns

void

Defined in

src/ChronikClient.ts:339


subscribe

subscribe(scriptType, scriptPayload): void

Subscribe to the given script type and payload. For "p2pkh", scriptPayload is the 20 byte public key hash.

Parameters

NameType
scriptTypeScriptType
scriptPayloadstring

Returns

void

Defined in

src/ChronikClient.ts:311


unsubscribe

unsubscribe(scriptType, scriptPayload): void

Unsubscribe from the given script type and payload.

Parameters

NameType
scriptTypeScriptType
scriptPayloadstring

Returns

void

Defined in

src/ChronikClient.ts:319


waitForOpen

waitForOpen(): Promise<void>

Wait for the WebSocket to be connected.

Returns

Promise<void>

Defined in

src/ChronikClient.ts:302