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'. |
options |
An object with the following keys:
waitForAuth : A boolean value 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.
priority : In case of a resubscribe (e.g. after recovering from a lost connection), this value determines the order in which channel subscriptions will be processed. Higher priority channels will be processed first. This value may be undefined.
data : Data which was passed along with the the channel subscription (if specified). This value can be accessed by the SUBSCRIBE action on the MIDDLEWARE_INBOUND middleware on the server side as part of the channel subscription.
|
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. |
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.
|
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 |
transmitPublish(data)
|
Publish data to this channel. Do not expect a response from the server.
The data argument can be any JSON-compatible object/array or primitive.
|
invokePublish(data)
|
Publish data to this channel. Expect a response from the server.
The data argument can be any JSON-compatible object/array or primitive.
This method returns a Promise which will be rejected if the operation fails.
For example, it can be rejected if the MIDDLEWARE_INBOUND middleware blocks the action on the server side.
The promise will resolve once the server has processed the publish action.
|
listener(eventName)
|
This method returns an event listener stream for the specified eventName . This object is an asyncIterable which can be consumed with a for-await-of loop.
|
closeListener(eventName)
|
This method will signal to all consuming for-await-of loops (for the eventName listener) to break after they have finished iterating over their current backlogs of events.
|
closeAllListeners()
|
This method will signal to all consuming for-await-of loops for all listeners to break after they have finished consuming their respective backlogs of events.
|
killListener(eventName)
|
This method will signal to all consuming for-await-of loops for the eventName listener to break immediately and will reset the backpressure for that listener to 0.
|
killAllListeners()
|
This method will signal to all consuming for-await-of loops for all listeners to break immediately and will reset the aggregate backpressure for all listeners to 0.
|
closeOutput()
|
This method will signal to all consuming for-await-of loops for the channel's output stream to break after they have finished consuming their backlogs of data.
|
killOutput()
|
This method will signal to all consuming for-await-of loops for the channel's output stream to break immediately and will reset the aggregate backpressure for the channel's output stream to 0.
|
close()
|
This method will signal to all consuming for-await-of loops for all of the channel's streams (including all listener streams) to break after they have finished consuming their backlogs of data.
|
kill()
|
This method will signal to all consuming for-await-of loops for all of the channel's streams (including all listener streams) to break immediately and will reset the aggregate backpressure for the channel to 0.
|
getBackpressure()
|
Get the aggregate backpressure for all streams on the current channel. The aggregate backpressure represents the highest backpressure of all consumers.
|
getOutputBackpressure()
|
Get the aggregate backpressure for the main output stream of the current channel. The aggregate backpressure represents the highest backpressure of all consumers.
|
getAllListenersBackpressure()
|
Get the aggregate backpressure for all listener streams on the current channel. The aggregate backpressure represents the highest backpressure of all consumers.
|
getListenerBackpressure(eventName)
|
Get the aggregate backpressure for the eventName listener stream on the current channel. The aggregate backpressure represents the highest backpressure of all consumers for that listener.
|
These methods should only be used for advanced use cases when you need more control over stream management; for example, when you want to break
out of a specific consumer loop without affecting any other consumer.
These methods can also be useful to check that consumers are being cleaned up properly and to selectively kill specific consumers which are causing backpressure to build up.
For most use cases, you should try to stick to the methods in the table above as it will lead to cleaner logic.
getListenerConsumerStatsList(eventName)
|
Get the list of consumers which are consuming data from the specified event listener. This method returns a list of objects which have an id and backpressure property.
|
getAllListenersConsumerStatsList()
|
Get the list of all consumers which are consuming events from any listener on the channel. This method returns a list of objects which have an id and backpressure property.
|
killListenerConsumer(consumerId)
|
This will cause the target listener consumer's for-await-of loop to break immediately.
|
getOutputConsumerStatsList()
|
Get the list of all consumers which are consuming output data from the channel. This method returns a list of objects which have an id and backpressure property.
|
killOutputConsumer(consumerId)
|
This will cause the target channel output consumer's for-await-of loop to break immediately.
|