deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

feat: namespace configs for transmitters and options #273

Closed lukeocodes closed 1 month ago

lukeocodes commented 1 month ago

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
  }
} 
dennisofficial commented 1 month ago

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

lukeocodes commented 1 month ago

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: @.***>

dennisofficial commented 1 month ago

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

dennisofficial commented 1 month ago

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.

lukeocodes commented 1 month ago

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.