deepgram-js-sdk icon indicating copy to clipboard operation
deepgram-js-sdk copied to clipboard

feat: namespace configs for transmitters and options

Open lukeocodes opened this issue 1 year ago • 4 comments

Full compatible with existing config (through a legacy config transformer)

The client options will look like this for custom headers for Fetch and WS Node clients;

{
  global: {
    fetch: { options: { headers: { "customheader": "value" } } },
    websocket: { options: { _nodeOnlyHeaders: { "customheader": "value" } } }
  }
  // ... other namespaces
} 

Namespace configurations are coming, too.

You'll now be able to provide config to specific namespaces in the SDK.

{
  global: {
    fetch: { options: { headers: { "customheader": "value" } } },
  },
  listen: {
    fetch: { options: { 
      url: "http://localhost:3000"
    } },
  }
  // ... other namespaces
} 

Finally, for the holy grail of overriding a client, which will also be available in namespace config, and will have access to the namespaceOptions scope.

{
  listen: {
    client: async (options) => {} // their client here
  }
} 

lukeocodes avatar Apr 29 '24 23:04 lukeocodes

Oooooo. Elaborate the namespace? You mean we can abstract the client classes? Like 'PrerecordedClient' class?

dennisofficial avatar May 06 '24 06:05 dennisofficial

You'll be able to configure listen separately of read, speak etc from the client options. Examples in the PR. using the classes directly is possible but risky, as it's not a public interface it can change without a major version increase

On Mon, 6 May 2024, 07:29 Dennis Lysenko, @.***> wrote:

Oooooo. Elaborate the namespace? You mean we can abstract the client classes? Like 'PrerecordedClient' class?

— Reply to this email directly, view it on GitHub https://github.com/deepgram/deepgram-js-sdk/pull/273#issuecomment-2095278626, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHJPARIV4SFGBU2BHMIGUDZA4POBAVCNFSM6AAAAABG7GASTWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJVGI3TQNRSGY . You are receiving this because you were assigned.Message ID: @.***>

lukeocodes avatar May 06 '24 06:05 lukeocodes

Does this allow us to set a fetch timeout or abort signal? That would be so helpful ❤️

dennisofficial avatar May 06 '24 06:05 dennisofficial

The only reason I would override the class is to include an abort signal code so I can attach the signal property to the fetch request.

dennisofficial avatar May 06 '24 06:05 dennisofficial

The only reason I would override the class is to include an abort signal code so I can attach the signal property to the fetch request.

Depends on the environment. As far as I know, you cannot provide Fetch a custom timeout, but you'll be able to create your own fetch wrapper than maybe even uses http/https instead, and bridges the compability layer.

You'll definitely be able to provide it a signal controller though.

lukeocodes avatar May 09 '24 17:05 lukeocodes