Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

RealtimeClient

class RealtimeClient {
constructor(endPoint: string, options?: RealtimeClientOptions);
accessToken: string | null;
apiKey: string | null;
channels: RealtimeChannel[];
conn: WebSocketLike | null;
decode: Function;
encode: Function;
endPoint: string;
fetch: Fetch;
headers?: {
[key: string]: string;
}
;
heartbeatIntervalMs: number;
heartbeatTimer: ReturnType<setInterval> | undefined;
logger: Function;
params?: {
[key: string]: string;
}
;
pendingHeartbeatRef: string | null;
reconnectAfterMs: Function;
reconnectTimer: Timer;
ref: number;
sendBuffer: Function[];
serializer: Serializer;
stateChangeCallbacks: {
open: Function[];
close: Function[];
error: Function[];
message: Function[];
}
;
timeout: number;
transport: WebSocketLikeConstructor | null;
 
channel(topic: string, params?: RealtimeChannelOptions): RealtimeChannel;
connect(): void;
connectionState(): CONNECTION_STATE;
disconnect(code?: number, reason?: string): void;
getChannels(): RealtimeChannel[];
isConnected(): boolean;
log(
kind: string,
msg: string,
data?: any,
): void;
push(data: RealtimeMessage): void;
removeAllChannels(): Promise<RealtimeRemoveChannelResponse[]>;
removeChannel(channel: RealtimeChannel): Promise<RealtimeRemoveChannelResponse>;
setAuth(token: string | null): void;
}

§Constructors

§
new RealtimeClient(endPoint: string, options?: RealtimeClientOptions)
[src]

Initializes the Socket.

@param endPoint

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

@param options.transport

The Websocket Transport, for example WebSocket.

@param options.timeout

The default timeout in milliseconds to trigger push timeouts.

@param options.params

The optional params to pass when connecting.

@param options.headers

The optional headers to pass when connecting.

@param options.heartbeatIntervalMs

The millisec interval to send a heartbeat message.

@param options.logger

The optional function for specialized logging, ie: logger: (kind, msg, data) => { console.log(${kind}: ${msg}, data) }

@param options.encode

The function to encode outgoing messages. Defaults to JSON: (payload, callback) => callback(JSON.stringify(payload))

@param options.decode

The function to decode incoming messages. Defaults to Serializer's decode.

@param options.reconnectAfterMs

he optional function that returns the millsec reconnect interval. Defaults to stepped backoff off.

§Properties

§
accessToken: string | null
[src]
§
apiKey: string | null
[src]
§
conn: WebSocketLike | null
[src]
§
decode: Function
[src]
§
encode: Function
[src]
§
endPoint: string
[src]
§
headers: {
[key: string]: string;
}
[src]
§
heartbeatIntervalMs: number
[src]
§
heartbeatTimer: ReturnType<setInterval> | undefined
[src]
§
logger: Function
[src]
§
params: {
[key: string]: string;
}
[src]
§
pendingHeartbeatRef: string | null
[src]
§
reconnectAfterMs: Function
[src]
§
reconnectTimer: Timer
[src]
§
ref: number
[src]
§
sendBuffer: Function[]
[src]
§
serializer: Serializer
[src]
§
stateChangeCallbacks: {
open: Function[];
close: Function[];
error: Function[];
message: Function[];
}
[src]
§
timeout: number
[src]
§
transport: WebSocketLikeConstructor | null
[src]

§Methods

§
channel(topic: string, params?: RealtimeChannelOptions): RealtimeChannel
[src]
§
connect(): void
[src]

Connects the socket, unless already connected.

§
connectionState(): CONNECTION_STATE
[src]

Returns the current state of the socket.

§
disconnect(code?: number, reason?: string): void
[src]

Disconnects the socket.

@param code

A numeric status code to send on disconnect.

@param reason

A custom reason for the disconnect.

§
getChannels(): RealtimeChannel[]
[src]

Returns all created channels

§
isConnected(): boolean
[src]

Returns true is the connection is open.

§
log(kind: string, msg: string, data?: any): void
[src]

Logs the message.

For customized logging, this.logger can be overridden.

§
push(data: RealtimeMessage): void
[src]

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.

§
removeAllChannels(): Promise<RealtimeRemoveChannelResponse[]>
[src]

Unsubscribes and removes all channels

§
removeChannel(channel: RealtimeChannel): Promise<RealtimeRemoveChannelResponse>
[src]

Unsubscribes and removes a single channel

@param channel

A RealtimeChannel instance

§
setAuth(token: string | null): void
[src]

Sets the JWT access token used for channel subscription authorization and Realtime RLS.

@param token

A JWT string.