@vapi-ai/web 1.0.259 → 1.0.260
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 +8 -0
- package/__tests__/vapi.test.ts +28 -25
- package/package.json +1 -1
- package/vapi.ts +9 -12
package/README.md
CHANGED
|
@@ -69,6 +69,14 @@ vapi.stop();
|
|
|
69
69
|
|
|
70
70
|
This will stop the recording and close the connection.
|
|
71
71
|
|
|
72
|
+
The `setMuted(muted: boolean)` can be used to mute and un-mute the user's microphone.
|
|
73
|
+
|
|
74
|
+
```javascript
|
|
75
|
+
vapi.isMuted(); // false
|
|
76
|
+
vapi.setMuted(true);
|
|
77
|
+
vapi.isMuted(); // true
|
|
78
|
+
```
|
|
79
|
+
|
|
72
80
|
## Events
|
|
73
81
|
|
|
74
82
|
You can listen to the following events:
|
package/__tests__/vapi.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Vapi from
|
|
1
|
+
import Vapi from "../vapi"; // Adjust the import path based on your project structure
|
|
2
2
|
|
|
3
|
-
describe(
|
|
3
|
+
describe("Vapi", () => {
|
|
4
4
|
let vapi: Vapi;
|
|
5
5
|
let mockCall: any;
|
|
6
6
|
|
|
@@ -11,43 +11,46 @@ describe('Vapi', () => {
|
|
|
11
11
|
localAudio: jest.fn(),
|
|
12
12
|
};
|
|
13
13
|
// Initialize Vapi instance and inject the mock
|
|
14
|
-
vapi = new Vapi(
|
|
15
|
-
vapi[
|
|
14
|
+
vapi = new Vapi("dummy_token");
|
|
15
|
+
vapi["call"] = mockCall; // Assuming you have a way to set this for testing
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
describe(
|
|
19
|
-
it(
|
|
20
|
-
vapi[
|
|
18
|
+
describe("setMuted", () => {
|
|
19
|
+
it("should mute the audio", () => {
|
|
20
|
+
vapi["setMuted"](true);
|
|
21
21
|
expect(mockCall.setLocalAudio).toHaveBeenCalledWith(false);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it(
|
|
25
|
-
vapi[
|
|
24
|
+
it("should unmute the audio", () => {
|
|
25
|
+
vapi["setMuted"](false);
|
|
26
26
|
expect(mockCall.setLocalAudio).toHaveBeenCalledWith(true);
|
|
27
27
|
});
|
|
28
28
|
|
|
29
|
-
it(
|
|
30
|
-
vapi[
|
|
31
|
-
expect(() => vapi[
|
|
29
|
+
it("should handle errors when call object is not available", () => {
|
|
30
|
+
vapi["call"] = null; // Simulate call object not being available
|
|
31
|
+
expect(() => vapi["setMuted"](true)).toThrow(
|
|
32
|
+
"Call object is not available."
|
|
33
|
+
);
|
|
32
34
|
});
|
|
33
35
|
});
|
|
34
36
|
|
|
35
|
-
describe(
|
|
36
|
-
it(
|
|
37
|
-
mockCall.localAudio.mockReturnValue(
|
|
38
|
-
vapi.
|
|
39
|
-
expect(
|
|
37
|
+
describe("isMuted", () => {
|
|
38
|
+
it("should return false if false", () => {
|
|
39
|
+
mockCall.localAudio.mockReturnValue(false); // Initially not muted
|
|
40
|
+
const res = vapi.isMuted();
|
|
41
|
+
expect(res).toBe(true);
|
|
40
42
|
});
|
|
41
43
|
|
|
42
|
-
it(
|
|
43
|
-
mockCall.localAudio.mockReturnValue(
|
|
44
|
-
vapi.
|
|
45
|
-
expect(
|
|
44
|
+
it("should return true if true", () => {
|
|
45
|
+
mockCall.localAudio.mockReturnValue(true); // Initially not muted
|
|
46
|
+
const res = vapi.isMuted();
|
|
47
|
+
expect(res).toBe(false);
|
|
46
48
|
});
|
|
47
49
|
|
|
48
|
-
it(
|
|
49
|
-
vapi[
|
|
50
|
-
|
|
50
|
+
it("should return false if no call in progress", () => {
|
|
51
|
+
vapi["call"] = null; // Simulate call object not being available
|
|
52
|
+
const res = vapi.isMuted();
|
|
53
|
+
expect(res).toBe(false);
|
|
51
54
|
});
|
|
52
55
|
});
|
|
53
|
-
});
|
|
56
|
+
});
|
package/package.json
CHANGED
package/vapi.ts
CHANGED
|
@@ -178,7 +178,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
178
178
|
});
|
|
179
179
|
|
|
180
180
|
this.call.startRemoteParticipantsAudioLevelObserver(100);
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
this.call.on("remote-participants-audio-level", (e) => {
|
|
183
183
|
if (e) this.handleRemoteParticipantsAudioLevel(e);
|
|
184
184
|
});
|
|
@@ -212,7 +212,7 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
212
212
|
const parsedMessage = JSON.parse(e.data);
|
|
213
213
|
this.emit("message", parsedMessage);
|
|
214
214
|
} catch (parseError) {
|
|
215
|
-
console.log("Error parsing message data: ", parseError);
|
|
215
|
+
console.log("Error parsing message data: ", parseError);
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
} catch (e) {
|
|
@@ -257,28 +257,25 @@ export default class Vapi extends VapiEventEmitter {
|
|
|
257
257
|
this.call?.sendAppMessage(JSON.stringify(message));
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
|
|
260
|
+
public setMuted(mute: boolean) {
|
|
261
261
|
try {
|
|
262
262
|
if (!this.call) {
|
|
263
|
-
throw new Error(
|
|
263
|
+
throw new Error("Call object is not available.");
|
|
264
264
|
}
|
|
265
265
|
this.call.setLocalAudio(!mute);
|
|
266
266
|
} catch (error) {
|
|
267
|
-
console.error("Error in setMuted:", error);
|
|
268
267
|
throw error;
|
|
269
268
|
}
|
|
270
269
|
}
|
|
271
270
|
|
|
272
|
-
public
|
|
271
|
+
public isMuted() {
|
|
273
272
|
try {
|
|
274
273
|
if (!this.call) {
|
|
275
|
-
|
|
274
|
+
return false;
|
|
276
275
|
}
|
|
277
|
-
|
|
278
|
-
this.setMuted(!isCurrentlyMuted);
|
|
276
|
+
return this.call.localAudio() === false;
|
|
279
277
|
} catch (error) {
|
|
280
|
-
|
|
281
|
-
throw error;
|
|
278
|
+
throw error;
|
|
282
279
|
}
|
|
283
|
-
}
|
|
280
|
+
}
|
|
284
281
|
}
|