Instances of the SCChannel object let you subscribe to and watch for incoming data which is published on that channel by other clients or the server.
This object is the client-side equivalent to the server-side SCChannel object.
name |
The channel's name. Must be a string. |
state |
Holds a string which indicates the state of this channel. Can be 'subscribed', 'unsubscribed' or 'pending'. |
waitForAuth |
A boolean which indicates whether or not this channel will wait for socket authentication before subscribing to the server. It will remain in the 'pending' state until the socket becomes authenticated. |
batch |
A boolean which indicates whether or not this channel's subscribe and unsubscribe requests will be batched together with that of other channels (for a performance boost). If false, then the subscribe/unsubscribe requests will be sent individually and immediately (assuming that the socket is online) instead of batched asynchronously. This option is false by default. |
SUBSCRIBED |
A string constant which is used to indicate that this channel is in a subscribed state. See the state property above. |
PENDING |
A string constant which is used to indicate that this channel is in a pending state. See the state property above. |
UNSUBSCRIBED |
A string constant which is used to indicate that this channel is in an unsubscribed state. See the state property above. |
getState() |
Returns the state of the channel as a string. Can be channel.SUBSCRIBED, channel.PENDING or channel.UNSUBSCRIBED. |
subscribe([options]) |
Activate this channel so that it will receive all data published to it from the backend. You can provide an optional options object in the
form {waitForAuth: true, data: someCustomData} (all properties are optional) - If waitForAuth is true, the channel
will wait for the underlying socket to become authenticated before trying to subscribe to the server - This channel will then
behave as a "private channel" - Note that in this case, "authenticated" means that the client socket has received a valid JWT authToken - Read about the server-side socket.setAuthToken(tokenData) function here for more details.
The data property of the options object can be used to pass data along with the subscription.
See this comment for more details about how ot handle the data property.
|
unsubscribe() |
Deactivate this channel. |
isSubscribed([includePending]) |
Check whether or not this channel is active (subscribed to the backend). The includePending argument is optional; if true, the function will return true if the channel is in a pending state |
publish(data, [callback]) |
Publish data to this channel.
The optional callback is in the form callback(err).
|
watch(handler) |
Capture any data which is published to this channel. The handler is a function in the form handler(data). |
unwatch([handler]) |
Unbind the specified handler from this channel. If no handler is specified, it will unbind all handlers. |
watchers() |
Get a list of functions which are currently observing this channel. |
destroy() |
Destroy the current SCChannel object - This makes it unusable and it will allow it to be garbage collected. |