Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • RealtimeClient

Index

Constructors

  • Initializes the Socket.

    Parameters

    • endPoint: string

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

    • Optional options: RealtimeClientOptions

    Returns RealtimeClient

Properties

_appendParams: any
_flushSendBuffer: any
_onConnClose: any
_onConnError: any
_onConnOpen: any
_sendHeartbeat: any
_triggerChanError: any
accessToken: null | string
channels: RealtimeSubscription[]
conn: null | WebSocket
decode: Function
encode: Function
endPoint: string
headers?: {}

Type declaration

  • [key: string]: string
heartbeatIntervalMs: number
heartbeatTimer: undefined | Timer
logger: Function
longpollerTimeout: number
params?: {}

Type declaration

  • [key: string]: string
pendingHeartbeatRef: null | string
reconnectAfterMs: Function
reconnectTimer: default
ref: number
sendBuffer: Function[]
serializer: default
stateChangeCallbacks: { close: Function[]; error: Function[]; message: Function[]; open: Function[] }

Type declaration

  • close: Function[]
  • error: Function[]
  • message: Function[]
  • open: Function[]
timeout: number
transport: any

Methods

  • Parameters

    • topic: string
    • Optional chanParams: ChannelParams

    Returns RealtimeSubscription

  • connect(): void
  • Connects the socket, unless already connected.

    Returns void

  • connectionState(): CONNECTION_STATE
  • Returns the current state of the socket.

    Returns CONNECTION_STATE

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

    Parameters

    • Optional code: number

      A numeric status code to send on disconnect.

    • Optional reason: string

      A custom reason for the disconnect.

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

  • endPointURL(): string
  • Returns the URL of the websocket.

    Returns string

  • isConnected(): boolean
  • Retuns true is the connection is open.

    Returns boolean

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

    Parameters

    • topic: string

    Returns void

  • 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(): string
  • Return the next message ref, accounting for overflows

    Returns string

  • 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(rawMessage: { data: any }): void
  • Parameters

    • rawMessage: { data: any }
      • data: any

    Returns void

  • 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(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(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(data: Message): void
  • 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

    • data: Message

    Returns void

  • Removes a subscription from the socket.

    Parameters

    Returns void

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

    Parameters

    • token: null | string

      A JWT string.

    Returns void

Generated using TypeDoc