Channels

The Channels interface is used to create and destroy Channel objects. Access it via the channels property of a Rest client instance.

JavaScript

1

const channels = rest.channels;

Properties

The Channels interface has the following properties:

allRecord<String, Channel>
A map of all the channels that have been instantiated via get() and have not yet been released via release().

Get a channel

channels.get(name: string, channelOptions?: ChannelOptions): Channel

Creates 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.

JavaScript

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:

namerequiredString
The name of the channel.
channelOptionsoptionalChannelOptions
Options for the channel, such as encryption.

Returns

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): void

Releases 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.

JavaScript

1

rest.channels.release('all-gas-ion');

Parameters

The release() method takes the following parameters:

namerequiredString
The name of the channel to release.