Options
All
  • Public
  • Public/Protected
  • All
Menu

Class WebSocketClient

An object repesenting a connection to a Terra node's WebSocket RPC endpoint. This allows for subscribing to Tendermint events through WebSocket.

Events

error emitted when error raises connect emitted after connection establishment reconnect emitted upon every attempt of reconnection destroyed emitted when socket has been destroyed

Example

import { WebSocketClient } from '@terra-money/terra.js';

const wsclient = new WebSocketClient("ws://localhost:26657/websocket");

wsclient.subscribe('NewBlock', {}, (data) => {
   console.log(data.value);

   // close after receiving one block.
   wsclient.destroy();
})

wsclient.subscribe(
'Tx',
 {
   'message.action': 'send',
   'message.sender': ['CONTAINS', 'terra1...'],
 },
 (data) => {
   console.log(data.value);

  // close after receiving one send Tx
  wsclient.destroy();
});

Hierarchy

  • EventEmitter
    • WebSocketClient

Index

Constructors

constructor

  • new WebSocketClient(URL: string, reconnectCount?: number, reconnectInterval?: number): WebSocketClient
  • WebSocketClient constructor

    Parameters

    • URL: string

      The WebSocket endpoint URL on the Tendermint RPC server. Ex: ws://localhost:26657/websocket

    • Default value reconnectCount: number = 0

      0 for not to attempt reconnect, -1 for infinite, > 0 for number of times to attempt

    • Default value reconnectInterval: number = 1000

      retry interval in milliseconds

    Returns WebSocketClient

Properties

isConnected

isConnected: boolean

Static defaultMaxListeners

defaultMaxListeners: number

Static Readonly errorMonitor

errorMonitor: unique symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

destroy

  • destroy(): void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

getMaxListeners

  • getMaxListeners(): number

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

subscribe

subscribeTx

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number