Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • RealtimeClient

Index

Constructors

constructor

  • Initializes the Socket.

    Parameters

    • endPoint: string

      The string WebSocket endpoint, ie, "ws://example.com/socket", "wss://example.com", "/socket" (inherited host & protocol)

    • Optional options: Options

    Returns RealtimeClient

Properties

accessToken

accessToken: string | null = null

channels

channels: RealtimeSubscription[] = []

conn

conn: WebSocket | null = null

decode

decode: Function

encode

encode: Function

endPoint

endPoint: string = ""

Optional headers

headers: undefined | {} = DEFAULT_HEADERS

heartbeatIntervalMs

heartbeatIntervalMs: number = 30000

heartbeatTimer

heartbeatTimer: ReturnType<typeof setInterval> | undefined = undefined

logger

logger: Function = noop

longpollerTimeout

longpollerTimeout: number = 20000

Optional params

params: undefined | {}

pendingHeartbeatRef

pendingHeartbeatRef: string | null = null

reconnectAfterMs

reconnectAfterMs: Function

reconnectTimer

reconnectTimer: Timer

ref

ref: number = 0

sendBuffer

sendBuffer: Function[] = []

serializer

serializer: Serializer = new Serializer()

timeout

timeout: number = DEFAULT_TIMEOUT

transport

transport: any = w3cwebsocket

Methods

Private _appendParams

  • _appendParams(url: string, params: {}): string
  • Parameters

    • url: string
    • params: {}
      • [key: string]: string

    Returns string

Private _flushSendBuffer

  • _flushSendBuffer(): void

Private _onConnClose

  • _onConnClose(event: any): void

Private _onConnError

  • _onConnError(error: ErrorEvent): void

Private _onConnOpen

  • _onConnOpen(): void

Private _sendHeartbeat

  • _sendHeartbeat(): void

Private _triggerChanError

  • _triggerChanError(): void

channel

connect

  • connect(): void

connectionState

disconnect

  • disconnect(code?: undefined | number, reason?: undefined | string): Promise<{ data: boolean; error: Error | null }>
  • Disconnects the socket.

    Parameters

    • Optional code: undefined | number

      A numeric status code to send on disconnect.

    • Optional reason: undefined | string

      A custom reason for the disconnect.

    Returns Promise<{ data: boolean; error: Error | null }>

endPointURL

  • endPointURL(): string

isConnected

  • isConnected(): boolean

leaveOpenTopic

  • leaveOpenTopic(topic: string): void
  • Unsubscribe from channels with the specified topic.

    Parameters

    • topic: string

    Returns void

log

  • log(kind: string, msg: string, data?: any): void
  • Logs the message.

    For customized logging, this.logger can be overriden.

    Parameters

    • kind: string
    • msg: string
    • Optional data: any

    Returns void

makeRef

  • makeRef(): string

onClose

  • onClose(callback: Function): void
  • Registers a callback for connection state change events.

    example

    socket.onOpen(() => console.log("Socket closed."))

    Parameters

    • callback: Function

      A function to be called when the event occurs.

    Returns void

onConnMessage

  • onConnMessage(rawMessage: { data: any }): void

onError

  • onError(callback: Function): void
  • Registers a callback for connection state change events.

    example

    socket.onOpen((error) => console.log("An error occurred"))

    Parameters

    • callback: Function

      A function to be called when the event occurs.

    Returns void

onMessage

  • onMessage(callback: Function): void
  • Calls a function any time a message is received.

    example

    socket.onMessage((message) => console.log(message))

    Parameters

    • callback: Function

      A function to be called when the event occurs.

    Returns void

onOpen

  • onOpen(callback: Function): void
  • Registers a callback for connection state change event.

    example

    socket.onOpen(() => console.log("Socket opened."))

    Parameters

    • callback: Function

      A function to be called when the event occurs.

    Returns void

push

  • Push out a message if the socket is connected.

    If the socket is not connected, the message gets enqueued within a local buffer, and sent out when a connection is next established.

    Parameters

    Returns void

remove

setAuth

  • setAuth(token: string | null): void
  • Sets the JWT access token used for channel subscription authorization and Realtime RLS.

    Parameters

    • token: string | null

      A JWT string.

    Returns void

Object literals

stateChangeCallbacks

stateChangeCallbacks: object

close

close: never[] = []

error

error: never[] = []

message

message: never[] = []

open

open: never[] = []

Legend

  • Constructor
  • Property
  • Method
  • Private method

Generated using TypeDoc