Skip to main content

subscribe()

subscribe(callback?: (status: REALTIME_SUBSCRIBE_STATES, err?: Error) => void, timeout?: number): RealtimeChannel

Register the channel with the server. Calls connect() automatically when the socket is not connected.

statusMeaning
SUBSCRIBEDSubscription succeeded
CHANNEL_ERRORSubscription failed; inspect err (including cause)
TIMED_OUTServer did not respond in time
CLOSEDChannel was closed

Parameters

callback
(status, err?) => void

Subscription status callback

timeout
number

Timeout in milliseconds

Response

RealtimeChannel
RealtimeChannel

Current channel, for chaining

Example

channel.subscribe((status, err) => {
if (status === "CHANNEL_ERROR" || status === "TIMED_OUT") {
console.error(status, err);
}
});