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);
private _workerObjectUrl;
accessToken: (() => Promise<string | null>) | null;
accessTokenValue: 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;
httpEndpoint: string;
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;
worker?: boolean;
workerRef?: Worker;
workerUrl?: string;
 
channel(topic: string, params?: RealtimeChannelOptions): RealtimeChannel;
connect(): void;
connectionState(): CONNECTION_STATE;
disconnect(code?: number, reason?: string): void;
endpointURL(): string;
flushSendBuffer(): 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>;
sendHeartbeat(): Promise<void>;
setAuth(token?: string | null): Promise<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 httpEndpoint

The string HTTP endpoint, ie, "https://example.com", "/" (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.

@param options.worker

Use Web Worker to set a side flow. Defaults to false.

@param options.workerUrl

The URL of the worker script. Defaults to https://realtime.supabase.com/worker.js that includes a heartbeat event call to keep the connection alive.

§Properties

§
_workerObjectUrl
[src]
§
accessToken: (() => Promise<string | null>) | null
[src]
§
accessTokenValue: 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]
§
httpEndpoint: string
[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]
§
worker: boolean
[src]
§
workerRef: Worker
[src]
§
workerUrl: string
[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.

§
endpointURL(): string
[src]

Returns the URL of the websocket.

@return

string The URL of the websocket.

§
flushSendBuffer(): void
[src]

Flushes send buffer

§
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

§
sendHeartbeat(): Promise<void>
[src]

Sends a heartbeat message if the socket is connected.

§
setAuth(token?: string | null): Promise<void>
[src]

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

If param is null it will use the accessToken callback function or the token set on the client.

On callback used, it will set the value of the token internal to the client.

@param token

A JWT string to override the token set on the client.