@layercode/js-sdk 2.6.0 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,6 +27,13 @@ interface AuthorizeSessionRequestParams {
27
27
  };
28
28
  }
29
29
  type AuthorizeSessionRequest = (params: AuthorizeSessionRequestParams) => Promise<Response>;
30
+ export type LayercodeAudioInputDevice = (MediaDeviceInfo & {
31
+ default: boolean;
32
+ }) & {
33
+ label: string;
34
+ };
35
+ export declare const listAudioInputDevices: () => Promise<LayercodeAudioInputDevice[]>;
36
+ export declare const watchAudioInputDevices: (callback: (devices: LayercodeAudioInputDevice[]) => void) => (() => void);
30
37
  /**
31
38
  * Interface for LayercodeClient public methods
32
39
  */
@@ -37,14 +44,20 @@ interface ILayercodeClient {
37
44
  triggerUserTurnFinished(): Promise<void>;
38
45
  getStream(): MediaStream | null;
39
46
  setInputDevice(deviceId: string): Promise<void>;
47
+ setPreferredInputDevice(deviceId: string | null): Promise<void>;
40
48
  setAudioInput(state: boolean): Promise<void>;
41
49
  setAudioOutput(state: boolean): Promise<void>;
42
50
  listDevices(): Promise<Array<MediaDeviceInfo & {
43
51
  default: boolean;
44
52
  }>>;
53
+ onDeviceSwitched?: (deviceId: string) => void;
54
+ onDevicesChanged?: (devices: Array<MediaDeviceInfo & {
55
+ default: boolean;
56
+ }>) => void;
45
57
  mute(): void;
46
58
  unmute(): void;
47
59
  sendClientResponseText(text: string): Promise<void>;
60
+ sendClientResponseData(data: any): Promise<void>;
48
61
  readonly status: string;
49
62
  readonly userAudioAmplitude: number;
50
63
  readonly agentAudioAmplitude: number;
@@ -142,6 +155,9 @@ declare class LayercodeClient implements ILayercodeClient {
142
155
  private stopPlayerAmplitude?;
143
156
  private stopRecorderAmplitude?;
144
157
  private deviceChangeListener;
158
+ private recorderRestartChain;
159
+ private deviceListenerReady;
160
+ private resolveDeviceListenerReady;
145
161
  _websocketUrl: string;
146
162
  status: string;
147
163
  userAudioAmplitude: number;
@@ -153,6 +169,12 @@ declare class LayercodeClient implements ILayercodeClient {
153
169
  * @param {Object} options - Configuration options
154
170
  */
155
171
  constructor(options: LayercodeClientOptions);
172
+ get onDeviceSwitched(): (deviceId: string) => void;
173
+ set onDeviceSwitched(callback: LayercodeClientOptions['onDeviceSwitched']);
174
+ get onDevicesChanged(): (devices: Array<MediaDeviceInfo & {
175
+ default: boolean;
176
+ }>) => void;
177
+ set onDevicesChanged(callback: LayercodeClientOptions['onDevicesChanged']);
156
178
  private _initializeVAD;
157
179
  /**
158
180
  * Updates the connection status and triggers the callback
@@ -199,6 +221,8 @@ declare class LayercodeClient implements ILayercodeClient {
199
221
  /** Emitters for audio flags */
200
222
  private _emitAudioInput;
201
223
  private _emitAudioOutput;
224
+ private _shouldCaptureUserAudio;
225
+ private _hasLiveRecorderStream;
202
226
  get audioInputEnabled(): boolean;
203
227
  get userSpeaking(): boolean;
204
228
  get agentSpeaking(): boolean;
@@ -232,10 +256,13 @@ declare class LayercodeClient implements ILayercodeClient {
232
256
  * @param {string} deviceId - The deviceId of the new microphone
233
257
  */
234
258
  setInputDevice(deviceId: string): Promise<void>;
259
+ setPreferredInputDevice(deviceId: string | null): Promise<void>;
235
260
  /**
236
261
  * Restarts audio recording after a device switch to ensure audio is captured from the new device
237
262
  */
238
263
  private _restartAudioRecording;
264
+ private _queueRecorderRestart;
265
+ private _initializeRecorderWithDefaultDevice;
239
266
  /**
240
267
  * Disconnect VAD
241
268
  */
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Layercode",
3
3
  "license": "MIT",
4
4
  "name": "@layercode/js-sdk",
5
- "version": "2.6.0",
5
+ "version": "2.8.0",
6
6
  "description": "Layercode JavaScript SDK for browser usage",
7
7
  "type": "module",
8
8
  "main": "dist/layercode-js-sdk.esm.js",
@@ -45,7 +45,7 @@
45
45
  "typescript": "^5.8.2"
46
46
  },
47
47
  "dependencies": {
48
- "@ricky0123/vad-web": "^0.0.24",
49
- "onnxruntime-web": "^1.21.1"
48
+ "@ricky0123/vad-web": "^0.0.29",
49
+ "onnxruntime-web": "^1.23.2"
50
50
  }
51
51
  }