ably / ably-js

Javascript, Node, Typescript, React, React Native client library SDK for Ably realtime messaging service
https://ably.com/download
Apache License 2.0
303 stars 55 forks source link

channels.all not exposed in typescript types #1776

Open bastiankistner opened 1 month ago

bastiankistner commented 1 month ago

I was just looking for a way to ensure that all channels have been detached and released before I try to re-authorize the client with a different set of capabilities. I found that the actual instance of my realtime client provides a .all property on the channels object. But it's not exposed through the typescript definitions.

Is this intended behaviour or do I need to use a different way to instantiate my client?

Here is the particular code I'm talking about: https://github.com/ably/ably-js/blob/186de0b1538ccc089aed9a2a7ff9afd3cb0ea793/src/common/lib/client/baserealtime.ts#L93

and I instantiate the client as mentioned in the docs:

import * as Ably from 'ably';

let options: Ably.ClientOptions = { key: 'foo' };
let client = new Ably.Realtime(options); /* inferred type Ably.Realtime */
let channel = client.channels.get('feed'); /* inferred type Ably.RealtimeChannel */

┆Issue is synchronized with this Jira Task by Unito

lawrence-forooghian commented 1 month ago

Hi @bastiankistner, channels.all is not part of the public API of the library. If you wish to perform an operation on all channels, I'd suggest that you keep your own list of the channels that you've instantiated (i.e. you should add to this list each time you call channels.get()).

As far as I know, this is not a feature that is frequently requested, so I’d like to understand your use case a bit better. What's your motivation for needing to "ensure that all channels have been detached and released before (you) try to re-authorize the client with a different set of capabilities"?

bastiankistner commented 1 week ago

Hello @lawrence-forooghian !

I'm building a collaborative realtime multichannel ecommerce fulfillment application that is supposed to handle market orders in batches and allows for multi-tenancy. The latter is the reason why I need to switch capabilities and re-authorize.

I'm using ably's realtime communication for the following aspects:

Since a user can be part of multiple organizations, each with a different set of marketplaces and potential connected print clients, I have to tear down all channels when the user switches the organization and re-establish a newly authorized connection with the corresponding channels.

It took me a while to properly integrate ably into my system and I realized that I need more control over what's happening, which is why I turned from the react sdk to the plain js sdk. And to further increase transparency I was looking for ways that the sdk offers that could be of value. Then I stumbled upon the channels.all property and was wondering why ably doesn't publicly expose it as it would already provide a great tool to track channel usage.