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.
status | Meaning |
|---|---|
SUBSCRIBED | Subscription succeeded |
CHANNEL_ERROR | Subscription failed; inspect err (including cause) |
TIMED_OUT | Server did not respond in time |
CLOSED | Channel 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);
}
});