@micdrop/client 1.7.3 → 1.8.1
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 +22 -20
- package/dist/index.d.ts +22 -20
- package/dist/index.js +36 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -32
- 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];
|
|
@@ -218,37 +219,37 @@ declare class VolumeVAD extends VAD {
|
|
|
218
219
|
resetOptions(): void;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
declare enum
|
|
222
|
+
declare enum CallClientErrorCode {
|
|
222
223
|
Mic = "Mic",
|
|
223
224
|
Unauthorized = "Unauthorized",
|
|
224
225
|
Error = "Error"
|
|
225
226
|
}
|
|
226
|
-
declare class
|
|
227
|
-
code:
|
|
228
|
-
constructor(code?:
|
|
227
|
+
declare class CallClientError extends Error {
|
|
228
|
+
code: CallClientErrorCode;
|
|
229
|
+
constructor(code?: CallClientErrorCode);
|
|
229
230
|
}
|
|
230
231
|
|
|
231
|
-
interface
|
|
232
|
+
interface CallClientEvents {
|
|
232
233
|
EndCall: [];
|
|
233
|
-
Error: [
|
|
234
|
+
Error: [CallClientError];
|
|
234
235
|
StateChange: void;
|
|
235
236
|
}
|
|
236
|
-
interface
|
|
237
|
+
interface CallClientOptions {
|
|
237
238
|
vad?: VADConfig;
|
|
238
239
|
}
|
|
239
240
|
declare global {
|
|
240
241
|
interface Window {
|
|
241
|
-
|
|
242
|
+
micdropCallClient: any;
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
|
-
declare class
|
|
245
|
+
declare class CallClient<Params extends {}, Options extends CallClientOptions = CallClientOptions> extends EventEmitter<CallClientEvents> {
|
|
245
246
|
private options?;
|
|
246
|
-
static getInstance<P extends {}, O extends
|
|
247
|
+
static getInstance<P extends {}, O extends CallClientOptions = CallClientOptions>(options?: O): CallClient<P, O>;
|
|
247
248
|
url?: string;
|
|
248
249
|
params?: Params;
|
|
249
250
|
micRecorder?: MicRecorder;
|
|
250
|
-
vad: VAD;
|
|
251
|
-
conversation: Conversation;
|
|
251
|
+
vad: VAD$1;
|
|
252
|
+
conversation: Conversation$1;
|
|
252
253
|
debug: boolean;
|
|
253
254
|
private ws?;
|
|
254
255
|
private micStream?;
|
|
@@ -307,18 +308,19 @@ interface CallSummary {
|
|
|
307
308
|
duration: number;
|
|
308
309
|
}
|
|
309
310
|
type Conversation = ConversationMessage[];
|
|
310
|
-
type
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
type AnswerCommands = {
|
|
312
|
+
endCall?: boolean;
|
|
313
|
+
cancelLastUserMessage?: boolean;
|
|
314
|
+
skipAnswer?: boolean;
|
|
315
|
+
};
|
|
316
|
+
type AnswerMetadata = {
|
|
316
317
|
[key: string]: any;
|
|
317
318
|
};
|
|
318
|
-
interface ConversationMessage<Data extends
|
|
319
|
+
interface ConversationMessage<Data extends AnswerMetadata = AnswerMetadata> {
|
|
319
320
|
role: 'system' | 'user' | 'assistant';
|
|
320
321
|
content: string;
|
|
322
|
+
commands?: AnswerCommands;
|
|
321
323
|
metadata?: Data;
|
|
322
324
|
}
|
|
323
325
|
|
|
324
|
-
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];
|
|
@@ -218,37 +219,37 @@ declare class VolumeVAD extends VAD {
|
|
|
218
219
|
resetOptions(): void;
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
declare enum
|
|
222
|
+
declare enum CallClientErrorCode {
|
|
222
223
|
Mic = "Mic",
|
|
223
224
|
Unauthorized = "Unauthorized",
|
|
224
225
|
Error = "Error"
|
|
225
226
|
}
|
|
226
|
-
declare class
|
|
227
|
-
code:
|
|
228
|
-
constructor(code?:
|
|
227
|
+
declare class CallClientError extends Error {
|
|
228
|
+
code: CallClientErrorCode;
|
|
229
|
+
constructor(code?: CallClientErrorCode);
|
|
229
230
|
}
|
|
230
231
|
|
|
231
|
-
interface
|
|
232
|
+
interface CallClientEvents {
|
|
232
233
|
EndCall: [];
|
|
233
|
-
Error: [
|
|
234
|
+
Error: [CallClientError];
|
|
234
235
|
StateChange: void;
|
|
235
236
|
}
|
|
236
|
-
interface
|
|
237
|
+
interface CallClientOptions {
|
|
237
238
|
vad?: VADConfig;
|
|
238
239
|
}
|
|
239
240
|
declare global {
|
|
240
241
|
interface Window {
|
|
241
|
-
|
|
242
|
+
micdropCallClient: any;
|
|
242
243
|
}
|
|
243
244
|
}
|
|
244
|
-
declare class
|
|
245
|
+
declare class CallClient<Params extends {}, Options extends CallClientOptions = CallClientOptions> extends EventEmitter<CallClientEvents> {
|
|
245
246
|
private options?;
|
|
246
|
-
static getInstance<P extends {}, O extends
|
|
247
|
+
static getInstance<P extends {}, O extends CallClientOptions = CallClientOptions>(options?: O): CallClient<P, O>;
|
|
247
248
|
url?: string;
|
|
248
249
|
params?: Params;
|
|
249
250
|
micRecorder?: MicRecorder;
|
|
250
|
-
vad: VAD;
|
|
251
|
-
conversation: Conversation;
|
|
251
|
+
vad: VAD$1;
|
|
252
|
+
conversation: Conversation$1;
|
|
252
253
|
debug: boolean;
|
|
253
254
|
private ws?;
|
|
254
255
|
private micStream?;
|
|
@@ -307,18 +308,19 @@ interface CallSummary {
|
|
|
307
308
|
duration: number;
|
|
308
309
|
}
|
|
309
310
|
type Conversation = ConversationMessage[];
|
|
310
|
-
type
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
311
|
+
type AnswerCommands = {
|
|
312
|
+
endCall?: boolean;
|
|
313
|
+
cancelLastUserMessage?: boolean;
|
|
314
|
+
skipAnswer?: boolean;
|
|
315
|
+
};
|
|
316
|
+
type AnswerMetadata = {
|
|
316
317
|
[key: string]: any;
|
|
317
318
|
};
|
|
318
|
-
interface ConversationMessage<Data extends
|
|
319
|
+
interface ConversationMessage<Data extends AnswerMetadata = AnswerMetadata> {
|
|
319
320
|
role: 'system' | 'user' | 'assistant';
|
|
320
321
|
content: string;
|
|
322
|
+
commands?: AnswerCommands;
|
|
321
323
|
metadata?: Data;
|
|
322
324
|
}
|
|
323
325
|
|
|
324
|
-
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,
|
|
@@ -553,18 +553,18 @@ var MicRecorder = class extends import_eventemitter33.default {
|
|
|
553
553
|
this.speakingConfirmed = true;
|
|
554
554
|
}).bind(this);
|
|
555
555
|
this.onCancelSpeaking = (async () => {
|
|
556
|
-
if (
|
|
556
|
+
if (this.state.isMuted) return;
|
|
557
557
|
try {
|
|
558
|
-
this.recorder
|
|
558
|
+
this.recorder?.stop();
|
|
559
559
|
} catch (error) {
|
|
560
560
|
console.error(error);
|
|
561
561
|
}
|
|
562
562
|
this.queuedChunks.length = 0;
|
|
563
563
|
}).bind(this);
|
|
564
564
|
this.onStopSpeaking = (async () => {
|
|
565
|
-
if (
|
|
565
|
+
if (this.state.isMuted) return;
|
|
566
566
|
try {
|
|
567
|
-
this.recorder
|
|
567
|
+
this.recorder?.stop();
|
|
568
568
|
} catch (error) {
|
|
569
569
|
console.error(error);
|
|
570
570
|
}
|
|
@@ -654,6 +654,7 @@ var MicRecorder = class extends import_eventemitter33.default {
|
|
|
654
654
|
await this.vad.stop();
|
|
655
655
|
}
|
|
656
656
|
async onDataAvailable(blobEvent) {
|
|
657
|
+
if (this.state.isMuted) return;
|
|
657
658
|
if (!this.speakingConfirmed) {
|
|
658
659
|
this.queuedChunks.push(blobEvent.data);
|
|
659
660
|
return;
|
|
@@ -1028,25 +1029,25 @@ if (!window.micdropSpeaker) {
|
|
|
1028
1029
|
}
|
|
1029
1030
|
speaker = window.micdropSpeaker;
|
|
1030
1031
|
|
|
1031
|
-
// src/call/
|
|
1032
|
+
// src/call/CallClient.ts
|
|
1032
1033
|
var import_eventemitter34 = __toESM(require("eventemitter3"));
|
|
1033
1034
|
|
|
1034
|
-
// src/call/
|
|
1035
|
-
var
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
return
|
|
1040
|
-
})(
|
|
1041
|
-
var
|
|
1035
|
+
// src/call/CallClientError.ts
|
|
1036
|
+
var CallClientErrorCode = /* @__PURE__ */ ((CallClientErrorCode2) => {
|
|
1037
|
+
CallClientErrorCode2["Mic"] = "Mic";
|
|
1038
|
+
CallClientErrorCode2["Unauthorized"] = "Unauthorized";
|
|
1039
|
+
CallClientErrorCode2["Error"] = "Error";
|
|
1040
|
+
return CallClientErrorCode2;
|
|
1041
|
+
})(CallClientErrorCode || {});
|
|
1042
|
+
var CallClientError = class extends Error {
|
|
1042
1043
|
constructor(code = "Error" /* Error */) {
|
|
1043
1044
|
super();
|
|
1044
1045
|
this.code = code;
|
|
1045
1046
|
}
|
|
1046
1047
|
};
|
|
1047
1048
|
|
|
1048
|
-
// src/call/
|
|
1049
|
-
var
|
|
1049
|
+
// src/call/CallClient.ts
|
|
1050
|
+
var CallClient = class _CallClient extends import_eventemitter34.default {
|
|
1050
1051
|
constructor(options) {
|
|
1051
1052
|
super();
|
|
1052
1053
|
this.options = options;
|
|
@@ -1057,10 +1058,10 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1057
1058
|
this.vad = getVAD(this.options?.vad);
|
|
1058
1059
|
}
|
|
1059
1060
|
static getInstance(options) {
|
|
1060
|
-
if (!window.
|
|
1061
|
-
window.
|
|
1061
|
+
if (!window.micdropCallClient) {
|
|
1062
|
+
window.micdropCallClient = new _CallClient(options);
|
|
1062
1063
|
}
|
|
1063
|
-
return window.
|
|
1064
|
+
return window.micdropCallClient;
|
|
1064
1065
|
}
|
|
1065
1066
|
get isStarted() {
|
|
1066
1067
|
return this.isWSStarted && this.micRecorder?.state.isStarted || false;
|
|
@@ -1097,13 +1098,13 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1097
1098
|
try {
|
|
1098
1099
|
this.stopWS();
|
|
1099
1100
|
} catch (error) {
|
|
1100
|
-
console.error("[
|
|
1101
|
+
console.error("[CallClient] stop WS", error);
|
|
1101
1102
|
}
|
|
1102
1103
|
try {
|
|
1103
1104
|
this.micRecorder?.stop();
|
|
1104
1105
|
this.stopMic();
|
|
1105
1106
|
} catch (error) {
|
|
1106
|
-
console.error("[
|
|
1107
|
+
console.error("[CallClient] stop mic", error);
|
|
1107
1108
|
}
|
|
1108
1109
|
}
|
|
1109
1110
|
pause() {
|
|
@@ -1156,8 +1157,8 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1156
1157
|
await this.micRecorder.start(this.micStream);
|
|
1157
1158
|
}
|
|
1158
1159
|
} catch (error) {
|
|
1159
|
-
console.error("[
|
|
1160
|
-
this.emit("Error", new
|
|
1160
|
+
console.error("[CallClient] startMic", error);
|
|
1161
|
+
this.emit("Error", new CallClientError("Mic" /* Mic */));
|
|
1161
1162
|
this.stop();
|
|
1162
1163
|
}
|
|
1163
1164
|
}
|
|
@@ -1170,13 +1171,13 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1170
1171
|
}
|
|
1171
1172
|
async startWS() {
|
|
1172
1173
|
if (this.ws) {
|
|
1173
|
-
throw new Error("[
|
|
1174
|
+
throw new Error("[CallClient] startWS: WebSocket is already started");
|
|
1174
1175
|
}
|
|
1175
1176
|
if (!this.isMicStarted) {
|
|
1176
|
-
throw new Error("[
|
|
1177
|
+
throw new Error("[CallClient] startWS: Microphone is not started");
|
|
1177
1178
|
}
|
|
1178
1179
|
if (!this.url) {
|
|
1179
|
-
throw new Error("[
|
|
1180
|
+
throw new Error("[CallClient] startWS: URL is not set");
|
|
1180
1181
|
}
|
|
1181
1182
|
this.ws = new WebSocket(this.url);
|
|
1182
1183
|
this.ws.binaryType = "blob";
|
|
@@ -1230,18 +1231,18 @@ var CallHandler = class _CallHandler extends import_eventemitter34.default {
|
|
|
1230
1231
|
this.log("[WS] Closed", event);
|
|
1231
1232
|
this.stop();
|
|
1232
1233
|
if (event.code >= 1001 && event.code <= 1011 && event.code !== 1005) {
|
|
1233
|
-
this.emit("Error", new
|
|
1234
|
+
this.emit("Error", new CallClientError());
|
|
1234
1235
|
} else if (event.code === 4401) {
|
|
1235
1236
|
this.emit(
|
|
1236
1237
|
"Error",
|
|
1237
|
-
new
|
|
1238
|
+
new CallClientError("Unauthorized" /* Unauthorized */)
|
|
1238
1239
|
);
|
|
1239
1240
|
} else if (event.code >= 4e3) {
|
|
1240
|
-
this.emit("Error", new
|
|
1241
|
+
this.emit("Error", new CallClientError());
|
|
1241
1242
|
}
|
|
1242
1243
|
};
|
|
1243
1244
|
this.ws.onerror = (event) => {
|
|
1244
|
-
console.error("[
|
|
1245
|
+
console.error("[CallClient] [WS] Error:", event);
|
|
1245
1246
|
this.stop();
|
|
1246
1247
|
};
|
|
1247
1248
|
}
|
|
@@ -1282,10 +1283,10 @@ var CallServerCommands = /* @__PURE__ */ ((CallServerCommands2) => {
|
|
|
1282
1283
|
})(CallServerCommands || {});
|
|
1283
1284
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1284
1285
|
0 && (module.exports = {
|
|
1286
|
+
CallClient,
|
|
1285
1287
|
CallClientCommands,
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
CallHandlerErrorCode,
|
|
1288
|
+
CallClientError,
|
|
1289
|
+
CallClientErrorCode,
|
|
1289
1290
|
CallServerCommands,
|
|
1290
1291
|
LocalStorageKeys,
|
|
1291
1292
|
Mic,
|