Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Client<T>

RPC Client

Can be used in both node.js and the browser. Also see IClientOptions.

Type parameters

  • T: Service

Hierarchy

  • EventEmitter
    • Client

Implements

Index

Constructors

constructor

  • Parameters

    • address: string

      The address to the Server, eg ws://example.com:8042.

    • service: object

      The protocol buffer service class to use, an instance of this will be available as Client.service.

      • create: function
        • create(rpcImpl: protobuf.RPCImpl): T
        • Parameters

          • rpcImpl: protobuf.RPCImpl

          Returns T

    • Default value options: IClientOptions = {}

    Returns Client

Properties

Private active

active: boolean = false

Private address

address: string

Private backoff

backoff: function

Type declaration

    • (tries: number): number
    • Parameters

      • tries: number

      Returns number

Private eventTypes

eventTypes: object

Type declaration

Private messageBuffer

messageBuffer: object

Type declaration

Private nextSeq

nextSeq: number = 0

Private numRetries

numRetries: number = 0

options

Client options, readonly.

Private sendTimeout

sendTimeout: number

service

service: T

The protobuf service instance which holds all the rpc methods defined in your protocol.

Private Optional socket

socket: WebSocket

Private writeMessage

writeMessage: function

Type declaration

    • (message: IMessage): Promise<void>
    • Parameters

      • message: IMessage

      Returns Promise<void>

Static defaultMaxListeners

defaultMaxListeners: number

Methods

addListener

  • addListener(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

Private closeHandler

  • closeHandler(): void

connect

  • connect(): Promise<void>
  • Connect to the server.

    Returns Promise<void>

disconnect

  • disconnect(): Promise<void>
  • Disconnect from the server.

    Returns Promise<void>

emit

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

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

    Returns boolean

Private errorHandler

  • errorHandler(error: any): void

Private eventHandler

  • eventHandler(event: IEvent): void

eventNames

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

Private flushMessageBuffer

  • flushMessageBuffer(): Promise<void>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

isConnected

  • isConnected(): boolean
  • Return true if the client is connected, otherwise false.

    Returns boolean

listenerCount

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

    • type: string | symbol

    Returns number

listeners

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

    • event: string | symbol

    Returns Function[]

Private messageHandler

  • messageHandler(event: object): void
  • Parameters

    • event: object
      • data: any
      • target: WebSocket
      • type: string

    Returns void

off

  • off(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

Private openHandler

  • openHandler(): void

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...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
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

Private responseHandler

  • responseHandler(response: IResponse): Promise<void>
  • Parameters

    • response: IResponse

    Returns Promise<void>

Private retryHandler

  • retryHandler(): void

Private rpcCallback

  • rpcCallback(seq: number, error: Error | null, response?: undefined | null | Uint8Array): void
  • Parameters

    • seq: number
    • error: Error | null
    • Optional response: undefined | null | Uint8Array

    Returns void

Private rpcImpl

  • rpcImpl(method: Method | function, requestData: Uint8Array, callback: function): void
  • Parameters

    • method: Method | function
    • requestData: Uint8Array
    • callback: function
        • (error: null | Error, response?: undefined | null | Uint8Array): void
        • Parameters

          • error: null | Error
          • Optional response: undefined | null | Uint8Array

          Returns void

    Returns void

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Private writeMessageBrowser

  • writeMessageBrowser(message: IMessage): Promise<void>
  • Parameters

    • message: IMessage

    Returns Promise<void>

Private writeMessageNode

  • writeMessageNode(message: IMessage): Promise<void>
  • Parameters

    • message: IMessage

    Returns Promise<void>

Static listenerCount

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

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Generated using TypeDoc