Channels
The Channels interface is used to create and destroy Channel objects. Access it via the channels property of a Rest client instance.
1
const channels = rest.channels;Properties
The Channels interface has the following properties:
Get a channel
channels.get(name: string, channelOptions?: ChannelOptions): ChannelCreates a new Channel object if none for the given name exists, or returns the existing channel object. The channel is created or returned with the supplied ChannelOptions.
1
2
3
4
5
6
const channel = rest.channels.get('all-gas-ion');
// With channel options
const encryptedChannel = rest.channels.get('all-gas-ion', {
cipher: { key: '<key>' }
});Parameters
The get() method takes the following parameters:
namerequiredStringchannelOptionsoptionalChannelOptionsReturns
Channel
Returns a Channel object for the given name. If a channel with that name already exists, the existing object is returned.
Release a channel
channels.release(name: string): voidReleases all SDK-held references to a Channel object, enabling it to be garbage collected. Useful for applications that work with a continually changing set of channels on a single client and need to avoid unbounded memory growth; if this does not describe your application, don't call it.
This method only affects the local client-side representation of the channel. The channel itself on the Ably platform is not deleted or changed, and other client instances (in the same or different processes) are unaffected. After release, calling channels.get() with the same name returns a fresh channel object.
1
rest.channels.release('all-gas-ion');Parameters
The release() method takes the following parameters:
namerequiredString