@micdrop/client 1.7.2 → 1.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.
- package/README.md +7 -4
- package/dist/index.d.mts +42 -24
- package/dist/index.d.ts +42 -24
- package/dist/index.js +103 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -32,10 +32,13 @@ pnpm add @micdrop/client
|
|
|
32
32
|
## Quick Start
|
|
33
33
|
|
|
34
34
|
```typescript
|
|
35
|
-
import {
|
|
35
|
+
import { CallClient } from '@micdrop/client'
|
|
36
36
|
|
|
37
37
|
// Create a new call handler instance
|
|
38
|
-
const call =
|
|
38
|
+
const call = CallClient.getInstance<YourParamsType>({
|
|
39
|
+
// VAD (see docs)
|
|
40
|
+
vad: ['volume', 'silero'],
|
|
41
|
+
})
|
|
39
42
|
|
|
40
43
|
// Configure the call
|
|
41
44
|
call.url = 'wss://your-server.com/ws'
|
|
@@ -70,7 +73,7 @@ await call.stop()
|
|
|
70
73
|
Check out the demo implementation in the [@micdrop/demo-client](../demo-client/README.md) package. It shows:
|
|
71
74
|
|
|
72
75
|
- Setting up a React application with WebSocket communication
|
|
73
|
-
- Configuring the
|
|
76
|
+
- Configuring the CallClient with custom parameters
|
|
74
77
|
- Managing microphone input and audio playback
|
|
75
78
|
- Handling conversation state and UI updates
|
|
76
79
|
- Error handling patterns
|
|
@@ -79,7 +82,7 @@ Here's a simplified version from the demo:
|
|
|
79
82
|
|
|
80
83
|
## Documentation
|
|
81
84
|
|
|
82
|
-
- **[
|
|
85
|
+
- **[CallClient](./docs/CallClient.md)** - Manages WebSocket connections, audio streaming, and conversation state
|
|
83
86
|
|
|
84
87
|
- **[MicRecorder](./docs/MicRecorder.md)** - Records audio from microphone with voice activity detection and speech events
|
|
85
88
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { VAD as VAD$1, Conversation as Conversation$1 } from '@micdrop/client';
|
|
2
3
|
|
|
3
4
|
interface AudioAnalyserEvents {
|
|
4
5
|
volume: [number];
|
|
@@ -45,12 +46,19 @@ interface VADEvents {
|
|
|
45
46
|
ConfirmSpeaking: void;
|
|
46
47
|
CancelSpeaking: void;
|
|
47
48
|
StopSpeaking: void;
|
|
49
|
+
ChangeStatus: [VADStatus];
|
|
50
|
+
}
|
|
51
|
+
declare enum VADStatus {
|
|
52
|
+
Silence = 0,
|
|
53
|
+
MaybeSpeaking = 1,
|
|
54
|
+
Speaking = 2
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
57
|
* Abstract VAD class
|
|
51
58
|
* VAD = Voice Activity Detection
|
|
52
59
|
*/
|
|
53
60
|
declare abstract class VAD extends EventEmitter<VADEvents> {
|
|
61
|
+
status: VADStatus;
|
|
54
62
|
delay: number;
|
|
55
63
|
/**
|
|
56
64
|
* Checks if the VAD is started
|
|
@@ -66,6 +74,18 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
|
|
|
66
74
|
* Stops the VAD
|
|
67
75
|
*/
|
|
68
76
|
abstract stop(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Emits an event (overrides the default implementation)
|
|
79
|
+
* @param event - The event to emit
|
|
80
|
+
* @param args - The arguments to emit
|
|
81
|
+
* @returns True if the event was emitted, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
emit<T extends keyof VADEvents>(event: T, ...args: EventEmitter.EventArgs<VADEvents, T>): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the status of the VAD
|
|
86
|
+
* @param status - The status to set
|
|
87
|
+
*/
|
|
88
|
+
setStatus(status: VADStatus): void;
|
|
69
89
|
}
|
|
70
90
|
|
|
71
91
|
type VADConfigName = 'volume' | 'silero';
|
|
@@ -144,13 +164,10 @@ declare enum LocalStorageKeys {
|
|
|
144
164
|
*/
|
|
145
165
|
declare class MultipleVAD extends VAD {
|
|
146
166
|
vads: VAD[];
|
|
147
|
-
private startSpeakingCount;
|
|
148
|
-
private confirmSpeakingCount;
|
|
149
|
-
private lastEventName;
|
|
150
167
|
constructor(vads: Array<VAD | VADConfigName>);
|
|
151
|
-
emit(eventName: keyof VADEvents, ..._: any[]): boolean;
|
|
152
168
|
get isStarted(): boolean;
|
|
153
169
|
start(stream: MediaStream, threshold?: number): Promise<void>;
|
|
170
|
+
private onStatusChange;
|
|
154
171
|
stop(): Promise<void>;
|
|
155
172
|
}
|
|
156
173
|
|
|
@@ -202,37 +219,37 @@ declare class VolumeVAD extends VAD {
|
|
|
202
219
|
resetOptions(): void;
|
|
203
220
|
}
|
|
204
221
|
|
|
205
|
-
declare enum
|
|
222
|
+
declare enum CallClientErrorCode {
|
|
206
223
|
Mic = "Mic",
|
|
207
224
|
Unauthorized = "Unauthorized",
|
|
208
225
|
Error = "Error"
|
|
209
226
|
}
|
|
210
|
-
declare class
|
|
211
|
-
code:
|
|
212
|
-
constructor(code?:
|
|
227
|
+
declare class CallClientError extends Error {
|
|
228
|
+
code: CallClientErrorCode;
|
|
229
|
+
constructor(code?: CallClientErrorCode);
|
|
213
230
|
}
|
|
214
231
|
|
|
215
|
-
interface
|
|
232
|
+
interface CallClientEvents {
|
|
216
233
|
EndCall: [];
|
|
217
|
-
Error: [
|
|
234
|
+
Error: [CallClientError];
|
|
218
235
|
StateChange: void;
|
|
219
236
|
}
|
|
220
|
-
interface
|
|
237
|
+
interface CallClientOptions {
|
|
221
238
|
vad?: VADConfig;
|
|
222
239
|
}
|
|
223
240
|
declare global {
|
|
224
241
|
interface Window {
|
|
225
|
-
|
|
242
|
+
micdropCallClient: any;
|
|
226
243
|
}
|
|
227
244
|
}
|
|
228
|
-
declare class
|
|
245
|
+
declare class CallClient<Params extends {}, Options extends CallClientOptions = CallClientOptions> extends EventEmitter<CallClientEvents> {
|
|
229
246
|
private options?;
|
|
230
|
-
static getInstance<P extends {}, O extends
|
|
247
|
+
static getInstance<P extends {}, O extends CallClientOptions = CallClientOptions>(options?: O): CallClient<P, O>;
|
|
231
248
|
url?: string;
|
|
232
249
|
params?: Params;
|
|
233
250
|
micRecorder?: MicRecorder;
|
|
234
|
-
vad: VAD;
|
|
235
|
-
conversation: Conversation;
|
|
251
|
+
vad: VAD$1;
|
|
252
|
+
conversation: Conversation$1;
|
|
236
253
|
debug: boolean;
|
|
237
254
|
private ws?;
|
|
238
255
|
private micStream?;
|
|
@@ -291,18 +308,19 @@ interface CallSummary {
|
|
|
291
308
|
duration: number;
|
|
292
309
|
}
|
|
293
310
|
type Conversation = ConversationMessage[];
|
|
294
|
-
type
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
311
|
+
type AnswerCommands = {
|
|
312
|
+
endCall?: boolean;
|
|
313
|
+
cancelLastUserMessage?: boolean;
|
|
314
|
+
skipAnswer?: boolean;
|
|
315
|
+
};
|
|
316
|
+
type AnswerMetadata = {
|
|
300
317
|
[key: string]: any;
|
|
301
318
|
};
|
|
302
|
-
interface ConversationMessage<Data extends
|
|
319
|
+
interface ConversationMessage<Data extends AnswerMetadata = AnswerMetadata> {
|
|
303
320
|
role: 'system' | 'user' | 'assistant';
|
|
304
321
|
content: string;
|
|
322
|
+
commands?: AnswerCommands;
|
|
305
323
|
metadata?: Data;
|
|
306
324
|
}
|
|
307
325
|
|
|
308
|
-
export {
|
|
326
|
+
export { type AnswerCommands, type AnswerMetadata, CallClient, CallClientCommands, CallClientError, CallClientErrorCode, type CallClientEvents, type CallClientOptions, type CallConfig, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, MultipleVAD, SileroVAD, type SileroVADOptions, speaker as Speaker, VAD, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { VAD as VAD$1, Conversation as Conversation$1 } from '@micdrop/client';
|
|
2
3
|
|
|
3
4
|
interface AudioAnalyserEvents {
|
|
4
5
|
volume: [number];
|
|
@@ -45,12 +46,19 @@ interface VADEvents {
|
|
|
45
46
|
ConfirmSpeaking: void;
|
|
46
47
|
CancelSpeaking: void;
|
|
47
48
|
StopSpeaking: void;
|
|
49
|
+
ChangeStatus: [VADStatus];
|
|
50
|
+
}
|
|
51
|
+
declare enum VADStatus {
|
|
52
|
+
Silence = 0,
|
|
53
|
+
MaybeSpeaking = 1,
|
|
54
|
+
Speaking = 2
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
57
|
* Abstract VAD class
|
|
51
58
|
* VAD = Voice Activity Detection
|
|
52
59
|
*/
|
|
53
60
|
declare abstract class VAD extends EventEmitter<VADEvents> {
|
|
61
|
+
status: VADStatus;
|
|
54
62
|
delay: number;
|
|
55
63
|
/**
|
|
56
64
|
* Checks if the VAD is started
|
|
@@ -66,6 +74,18 @@ declare abstract class VAD extends EventEmitter<VADEvents> {
|
|
|
66
74
|
* Stops the VAD
|
|
67
75
|
*/
|
|
68
76
|
abstract stop(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Emits an event (overrides the default implementation)
|
|
79
|
+
* @param event - The event to emit
|
|
80
|
+
* @param args - The arguments to emit
|
|
81
|
+
* @returns True if the event was emitted, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
emit<T extends keyof VADEvents>(event: T, ...args: EventEmitter.EventArgs<VADEvents, T>): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Sets the status of the VAD
|
|
86
|
+
* @param status - The status to set
|
|
87
|
+
*/
|
|
88
|
+
setStatus(status: VADStatus): void;
|
|
69
89
|
}
|
|
70
90
|
|
|
71
91
|
type VADConfigName = 'volume' | 'silero';
|
|
@@ -144,13 +164,10 @@ declare enum LocalStorageKeys {
|
|
|
144
164
|
*/
|
|
145
165
|
declare class MultipleVAD extends VAD {
|
|
146
166
|
vads: VAD[];
|
|
147
|
-
private startSpeakingCount;
|
|
148
|
-
private confirmSpeakingCount;
|
|
149
|
-
private lastEventName;
|
|
150
167
|
constructor(vads: Array<VAD | VADConfigName>);
|
|
151
|
-
emit(eventName: keyof VADEvents, ..._: any[]): boolean;
|
|
152
168
|
get isStarted(): boolean;
|
|
153
169
|
start(stream: MediaStream, threshold?: number): Promise<void>;
|
|
170
|
+
private onStatusChange;
|
|
154
171
|
stop(): Promise<void>;
|
|
155
172
|
}
|
|
156
173
|
|
|
@@ -202,37 +219,37 @@ declare class VolumeVAD extends VAD {
|
|
|
202
219
|
resetOptions(): void;
|
|
203
220
|
}
|
|
204
221
|
|
|
205
|
-
declare enum
|
|
222
|
+
declare enum CallClientErrorCode {
|
|
206
223
|
Mic = "Mic",
|
|
207
224
|
Unauthorized = "Unauthorized",
|
|
208
225
|
Error = "Error"
|
|
209
226
|
}
|
|
210
|
-
declare class
|
|
211
|
-
code:
|
|
212
|
-
constructor(code?:
|
|
227
|
+
declare class CallClientError extends Error {
|
|
228
|
+
code: CallClientErrorCode;
|
|
229
|
+
constructor(code?: CallClientErrorCode);
|
|
213
230
|
}
|
|
214
231
|
|
|
215
|
-
interface
|
|
232
|
+
interface CallClientEvents {
|
|
216
233
|
EndCall: [];
|
|
217
|
-
Error: [
|
|
234
|
+
Error: [CallClientError];
|
|
218
235
|
StateChange: void;
|
|
219
236
|
}
|
|
220
|
-
interface
|
|
237
|
+
interface CallClientOptions {
|
|
221
238
|
vad?: VADConfig;
|
|
222
239
|
}
|
|
223
240
|
declare global {
|
|
224
241
|
interface Window {
|
|
225
|
-
|
|
242
|
+
micdropCallClient: any;
|
|
226
243
|
}
|
|
227
244
|
}
|
|
228
|
-
declare class
|
|
245
|
+
declare class CallClient<Params extends {}, Options extends CallClientOptions = CallClientOptions> extends EventEmitter<CallClientEvents> {
|
|
229
246
|
private options?;
|
|
230
|
-
static getInstance<P extends {}, O extends
|
|
247
|
+
static getInstance<P extends {}, O extends CallClientOptions = CallClientOptions>(options?: O): CallClient<P, O>;
|
|
231
248
|
url?: string;
|
|
232
249
|
params?: Params;
|
|
233
250
|
micRecorder?: MicRecorder;
|
|
234
|
-
vad: VAD;
|
|
235
|
-
conversation: Conversation;
|
|
251
|
+
vad: VAD$1;
|
|
252
|
+
conversation: Conversation$1;
|
|
236
253
|
debug: boolean;
|
|
237
254
|
private ws?;
|
|
238
255
|
private micStream?;
|
|
@@ -291,18 +308,19 @@ interface CallSummary {
|
|
|
291
308
|
duration: number;
|
|
292
309
|
}
|
|
293
310
|
type Conversation = ConversationMessage[];
|
|
294
|
-
type
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
311
|
+
type AnswerCommands = {
|
|
312
|
+
endCall?: boolean;
|
|
313
|
+
cancelLastUserMessage?: boolean;
|
|
314
|
+
skipAnswer?: boolean;
|
|
315
|
+
};
|
|
316
|
+
type AnswerMetadata = {
|
|
300
317
|
[key: string]: any;
|
|
301
318
|
};
|
|
302
|
-
interface ConversationMessage<Data extends
|
|
319
|
+
interface ConversationMessage<Data extends AnswerMetadata = AnswerMetadata> {
|
|
303
320
|
role: 'system' | 'user' | 'assistant';
|
|
304
321
|
content: string;
|
|
322
|
+
commands?: AnswerCommands;
|
|
305
323
|
metadata?: Data;
|
|
306
324
|
}
|
|
307
325
|
|
|
308
|
-
export {
|
|
326
|
+
export { type AnswerCommands, type AnswerMetadata, CallClient, CallClientCommands, CallClientError, CallClientErrorCode, type CallClientEvents, type CallClientOptions, type CallConfig, CallServerCommands, type CallSummary, type Conversation, type ConversationMessage, LocalStorageKeys, mic as Mic, MicRecorder, type MicRecorderEvents, type MicRecorderState, MultipleVAD, SileroVAD, type SileroVADOptions, speaker as Speaker, VAD, type VADEvents, VADStatus, VolumeVAD, type VolumeVADOptions };
|
package/dist/index.js
CHANGED
|
@@ -30,10 +30,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
+
CallClient: () => CallClient,
|
|
33
34
|
CallClientCommands: () => CallClientCommands,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
CallHandlerErrorCode: () => CallHandlerErrorCode,
|
|
35
|
+
CallClientError: () => CallClientError,
|
|
36
|
+
CallClientErrorCode: () => CallClientErrorCode,
|
|
37
37
|
CallServerCommands: () => CallServerCommands,
|
|
38
38
|
LocalStorageKeys: () => LocalStorageKeys,
|
|
39
39
|
Mic: () => mic,
|
|
@@ -42,6 +42,7 @@ __export(index_exports, {
|
|
|
42
42
|
SileroVAD: () => SileroVAD,
|
|
43
43
|
Speaker: () => speaker,
|
|
44
44
|
VAD: () => VAD,
|
|
45
|
+
VADStatus: () => VADStatus,
|
|
45
46
|
VolumeVAD: () => VolumeVAD
|
|
46
47
|
});
|
|
47
48
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -221,26 +222,61 @@ function createDelayedStream(stream, delay) {
|
|
|
221
222
|
|
|
222
223
|
// src/audio/vad/VAD.ts
|
|
223
224
|
var import_eventemitter32 = __toESM(require("eventemitter3"));
|
|
225
|
+
var VADStatus = /* @__PURE__ */ ((VADStatus2) => {
|
|
226
|
+
VADStatus2[VADStatus2["Silence"] = 0] = "Silence";
|
|
227
|
+
VADStatus2[VADStatus2["MaybeSpeaking"] = 1] = "MaybeSpeaking";
|
|
228
|
+
VADStatus2[VADStatus2["Speaking"] = 2] = "Speaking";
|
|
229
|
+
return VADStatus2;
|
|
230
|
+
})(VADStatus || {});
|
|
224
231
|
var VAD = class extends import_eventemitter32.default {
|
|
225
232
|
constructor() {
|
|
226
233
|
super(...arguments);
|
|
234
|
+
this.status = 0 /* Silence */;
|
|
227
235
|
// Max delay to detect speech, can be used to record delayed stream
|
|
228
236
|
this.delay = 100;
|
|
229
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Emits an event (overrides the default implementation)
|
|
240
|
+
* @param event - The event to emit
|
|
241
|
+
* @param args - The arguments to emit
|
|
242
|
+
* @returns True if the event was emitted, false otherwise
|
|
243
|
+
*/
|
|
244
|
+
emit(event, ...args) {
|
|
245
|
+
switch (event) {
|
|
246
|
+
case "StartSpeaking":
|
|
247
|
+
this.setStatus(1 /* MaybeSpeaking */);
|
|
248
|
+
break;
|
|
249
|
+
case "ConfirmSpeaking":
|
|
250
|
+
this.setStatus(2 /* Speaking */);
|
|
251
|
+
break;
|
|
252
|
+
case "CancelSpeaking":
|
|
253
|
+
this.setStatus(0 /* Silence */);
|
|
254
|
+
break;
|
|
255
|
+
case "StopSpeaking":
|
|
256
|
+
this.setStatus(0 /* Silence */);
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
return super.emit(event, ...args);
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Sets the status of the VAD
|
|
265
|
+
* @param status - The status to set
|
|
266
|
+
*/
|
|
267
|
+
setStatus(status) {
|
|
268
|
+
if (this.status === status) return;
|
|
269
|
+
this.status = status;
|
|
270
|
+
super.emit("ChangeStatus", status);
|
|
271
|
+
}
|
|
230
272
|
};
|
|
231
273
|
|
|
232
274
|
// src/audio/vad/MultipleVAD.ts
|
|
233
275
|
var MultipleVAD = class extends VAD {
|
|
234
276
|
constructor(vads) {
|
|
235
277
|
super();
|
|
236
|
-
this.startSpeakingCount = 0;
|
|
237
|
-
this.confirmSpeakingCount = 0;
|
|
238
|
-
this.lastEventName = "StopSpeaking";
|
|
239
278
|
this.vads = vads.map((vad) => getVAD(vad));
|
|
240
|
-
|
|
241
|
-
emit(eventName, ..._) {
|
|
242
|
-
this.lastEventName = eventName;
|
|
243
|
-
return super.emit(eventName);
|
|
279
|
+
this.onStatusChange = this.onStatusChange.bind(this);
|
|
244
280
|
}
|
|
245
281
|
get isStarted() {
|
|
246
282
|
return this.vads.some((vad) => vad.isStarted);
|
|
@@ -250,40 +286,45 @@ var MultipleVAD = class extends VAD {
|
|
|
250
286
|
if (vad.isStarted) {
|
|
251
287
|
continue;
|
|
252
288
|
}
|
|
253
|
-
vad.on("
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
vad
|
|
260
|
-
|
|
261
|
-
|
|
289
|
+
vad.on("ChangeStatus", this.onStatusChange);
|
|
290
|
+
await vad.start(stream);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
onStatusChange() {
|
|
294
|
+
const isAllSilence = this.vads.every(
|
|
295
|
+
(vad) => vad.status === 0 /* Silence */
|
|
296
|
+
);
|
|
297
|
+
const isAllSpeaking = this.vads.every(
|
|
298
|
+
(vad) => vad.status === 2 /* Speaking */
|
|
299
|
+
);
|
|
300
|
+
switch (this.status) {
|
|
301
|
+
case 0 /* Silence */:
|
|
302
|
+
if (isAllSilence) break;
|
|
303
|
+
this.emit("StartSpeaking");
|
|
304
|
+
if (isAllSpeaking) {
|
|
262
305
|
this.emit("ConfirmSpeaking");
|
|
263
306
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
if (this.lastEventName === "StartSpeaking") {
|
|
307
|
+
break;
|
|
308
|
+
case 1 /* MaybeSpeaking */:
|
|
309
|
+
if (isAllSilence) {
|
|
268
310
|
this.emit("CancelSpeaking");
|
|
311
|
+
break;
|
|
269
312
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
313
|
+
if (isAllSpeaking) {
|
|
314
|
+
this.emit("ConfirmSpeaking");
|
|
315
|
+
}
|
|
316
|
+
break;
|
|
317
|
+
case 2 /* Speaking */:
|
|
318
|
+
if (isAllSilence) {
|
|
275
319
|
this.emit("StopSpeaking");
|
|
276
320
|
}
|
|
277
|
-
|
|
278
|
-
this.confirmSpeakingCount = 0;
|
|
279
|
-
});
|
|
280
|
-
await vad.start(stream);
|
|
321
|
+
break;
|
|
281
322
|
}
|
|
282
323
|
}
|
|
283
324
|
async stop() {
|
|
284
325
|
for (const vad of this.vads) {
|
|
326
|
+
vad.off("ChangeStatus", this.onStatusChange);
|
|
285
327
|
await vad.stop();
|
|
286
|
-
vad.removeAllListeners();
|
|
287
328
|
}
|
|
288
329
|
}
|
|
289
330
|
};
|
|
@@ -596,9 +637,6 @@ var MicRecorder = class extends import_eventemitter33.default {
|
|
|
596
637
|
}
|
|
597
638
|
}
|
|
598
639
|
async startSpeakingDetection(stream) {
|
|
599
|
-
if (!this.vad) {
|
|
600
|
-
throw new Error("VAD not initialized");
|
|
601
|
-
}
|
|
602
640
|
if (this.vad.isStarted) {
|
|
603
641
|
this.vad.stop();
|
|
604
642
|
}
|
|
@@ -609,9 +647,6 @@ var MicRecorder = class extends import_eventemitter33.default {
|
|
|
609
647
|
await this.vad.start(stream);
|
|
610
648
|
}
|
|
611
649
|
async stopSpeakingDetection() {
|
|
612
|
-
if (!this.vad) {
|
|
613
|
-
throw new Error("VAD not initialized");
|
|
614
|
-
}
|
|
615
650
|
this.vad.off("StartSpeaking", this.onStartSpeaking);
|
|
616
651
|
this.vad.off("ConfirmSpeaking", this.onConfirmSpeaking);
|
|
617
652
|
this.vad.off("CancelSpeaking", this.onCancelSpeaking);
|
|
@@ -993,25 +1028,25 @@ if (!window.micdropSpeaker) {
|
|
|
993
1028
|
}
|
|
994
1029
|
speaker = window.micdropSpeaker;
|
|
995
1030
|
|
|
996
|
-
// src/call/
|
|
1031
|
+
// src/call/CallClient.ts
|
|
997
1032
|
var import_eventemitter34 = __toESM(require("eventemitter3"));
|
|
998
1033
|
|
|
999
|
-
// src/call/
|
|
1000
|
-
var
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
return
|
|
1005
|
-
})(
|
|
1006
|
-
var
|
|
1034
|
+
// src/call/CallClientError.ts
|
|
1035
|
+
var CallClientErrorCode = /* @__PURE__ */ ((CallClientErrorCode2) => {
|
|
1036
|
+
CallClientErrorCode2["Mic"] = "Mic";
|
|
1037
|
+
CallClientErrorCode2["Unauthorized"] = "Unauthorized";
|
|
1038
|
+
CallClientErrorCode2["Error"] = "Error";
|
|
1039
|
+
return CallClientErrorCode2;
|
|
1040
|
+
})(CallClientErrorCode || {});
|
|
1041
|
+
var CallClientError = class extends Error {
|
|
1007
1042
|
constructor(code = "Error" /* Error */) {
|
|
1008
1043
|
super();
|
|
1009
1044
|
this.code = code;
|
|
1010
1045
|
}
|
|
1011
1046
|
};
|
|
1012
1047
|
|
|
1013
|
-
// src/call/
|
|
1014
|
-
var
|
|
1048
|
+
// src/call/CallClient.ts
|
|
1049
|
+
var CallClient = class _CallClient extends import_eventemitter34.default {
|
|
1015
1050
|
constructor(options) {
|
|
1016
1051
|
super();
|
|
1017
1052
|
this.options = options;
|
|
@@ -1022,10 +1057,10 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1022
1057
|
this.vad = getVAD(this.options?.vad);
|
|
1023
1058
|
}
|
|
1024
1059
|
static getInstance(options) {
|
|
1025
|
-
if (!window.
|
|
1026
|
-
window.
|
|
1060
|
+
if (!window.micdropCallClient) {
|
|
1061
|
+
window.micdropCallClient = new _CallClient(options);
|
|
1027
1062
|
}
|
|
1028
|
-
return window.
|
|
1063
|
+
return window.micdropCallClient;
|
|
1029
1064
|
}
|
|
1030
1065
|
get isStarted() {
|
|
1031
1066
|
return this.isWSStarted && this.micRecorder?.state.isStarted || false;
|
|
@@ -1062,13 +1097,13 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1062
1097
|
try {
|
|
1063
1098
|
this.stopWS();
|
|
1064
1099
|
} catch (error) {
|
|
1065
|
-
console.error("[
|
|
1100
|
+
console.error("[CallClient] stop WS", error);
|
|
1066
1101
|
}
|
|
1067
1102
|
try {
|
|
1068
1103
|
this.micRecorder?.stop();
|
|
1069
1104
|
this.stopMic();
|
|
1070
1105
|
} catch (error) {
|
|
1071
|
-
console.error("[
|
|
1106
|
+
console.error("[CallClient] stop mic", error);
|
|
1072
1107
|
}
|
|
1073
1108
|
}
|
|
1074
1109
|
pause() {
|
|
@@ -1121,8 +1156,8 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1121
1156
|
await this.micRecorder.start(this.micStream);
|
|
1122
1157
|
}
|
|
1123
1158
|
} catch (error) {
|
|
1124
|
-
console.error("[
|
|
1125
|
-
this.emit("Error", new
|
|
1159
|
+
console.error("[CallClient] startMic", error);
|
|
1160
|
+
this.emit("Error", new CallClientError("Mic" /* Mic */));
|
|
1126
1161
|
this.stop();
|
|
1127
1162
|
}
|
|
1128
1163
|
}
|
|
@@ -1135,13 +1170,13 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1135
1170
|
}
|
|
1136
1171
|
async startWS() {
|
|
1137
1172
|
if (this.ws) {
|
|
1138
|
-
throw new Error("[
|
|
1173
|
+
throw new Error("[CallClient] startWS: WebSocket is already started");
|
|
1139
1174
|
}
|
|
1140
1175
|
if (!this.isMicStarted) {
|
|
1141
|
-
throw new Error("[
|
|
1176
|
+
throw new Error("[CallClient] startWS: Microphone is not started");
|
|
1142
1177
|
}
|
|
1143
1178
|
if (!this.url) {
|
|
1144
|
-
throw new Error("[
|
|
1179
|
+
throw new Error("[CallClient] startWS: URL is not set");
|
|
1145
1180
|
}
|
|
1146
1181
|
this.ws = new WebSocket(this.url);
|
|
1147
1182
|
this.ws.binaryType = "blob";
|
|
@@ -1195,18 +1230,18 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1195
1230
|
this.log("[WS] Closed", event);
|
|
1196
1231
|
this.stop();
|
|
1197
1232
|
if (event.code >= 1001 && event.code <= 1011 && event.code !== 1005) {
|
|
1198
|
-
this.emit("Error", new
|
|
1233
|
+
this.emit("Error", new CallClientError());
|
|
1199
1234
|
} else if (event.code === 4401) {
|
|
1200
1235
|
this.emit(
|
|
1201
1236
|
"Error",
|
|
1202
|
-
new
|
|
1237
|
+
new CallClientError("Unauthorized" /* Unauthorized */)
|
|
1203
1238
|
);
|
|
1204
1239
|
} else if (event.code >= 4e3) {
|
|
1205
|
-
this.emit("Error", new
|
|
1240
|
+
this.emit("Error", new CallClientError());
|
|
1206
1241
|
}
|
|
1207
1242
|
};
|
|
1208
1243
|
this.ws.onerror = (event) => {
|
|
1209
|
-
console.error("[
|
|
1244
|
+
console.error("[CallClient] [WS] Error:", event);
|
|
1210
1245
|
this.stop();
|
|
1211
1246
|
};
|
|
1212
1247
|
}
|
|
@@ -1247,10 +1282,10 @@ var CallServerCommands = /* @__PURE__ */ ((CallServerCommands2) => {
|
|
|
1247
1282
|
})(CallServerCommands || {});
|
|
1248
1283
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1249
1284
|
0 && (module.exports = {
|
|
1285
|
+
CallClient,
|
|
1250
1286
|
CallClientCommands,
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
CallHandlerErrorCode,
|
|
1287
|
+
CallClientError,
|
|
1288
|
+
CallClientErrorCode,
|
|
1254
1289
|
CallServerCommands,
|
|
1255
1290
|
LocalStorageKeys,
|
|
1256
1291
|
Mic,
|
|
@@ -1259,6 +1294,7 @@ var CallServerCommands = /* @__PURE__ */ ((CallServerCommands2) => {
|
|
|
1259
1294
|
SileroVAD,
|
|
1260
1295
|
Speaker,
|
|
1261
1296
|
VAD,
|
|
1297
|
+
VADStatus,
|
|
1262
1298
|
VolumeVAD
|
|
1263
1299
|
});
|
|
1264
1300
|
//# sourceMappingURL=index.js.map
|