@vapi-ai/web 1.0.259 → 1.0.261

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 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:
@@ -1,6 +1,6 @@
1
- import Vapi from '../vapi'; // Adjust the import path based on your project structure
1
+ import Vapi from "../vapi"; // Adjust the import path based on your project structure
2
2
 
3
- describe('Vapi', () => {
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('dummy_token');
15
- vapi['call'] = mockCall; // Assuming you have a way to set this for testing
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('setMuted', () => {
19
- it('should mute the audio', () => {
20
- vapi['setMuted'](true);
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('should unmute the audio', () => {
25
- vapi['setMuted'](false);
24
+ it("should unmute the audio", () => {
25
+ vapi["setMuted"](false);
26
26
  expect(mockCall.setLocalAudio).toHaveBeenCalledWith(true);
27
27
  });
28
28
 
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('Call object is not available.');
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('toggleMute', () => {
36
- it('should toggle audio from unmuted to muted', () => {
37
- mockCall.localAudio.mockReturnValue(true); // Initially not muted
38
- vapi.toggleMute();
39
- expect(mockCall.setLocalAudio).toHaveBeenCalledWith(false); // Should mute
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('should toggle audio from muted to unmuted', () => {
43
- mockCall.localAudio.mockReturnValue(false); // Initially muted
44
- vapi.toggleMute();
45
- expect(mockCall.setLocalAudio).toHaveBeenCalledWith(true); // Should unmute
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('should handle errors when call object is not available', () => {
49
- vapi['call'] = null; // Simulate call object not being available
50
- expect(() => vapi.toggleMute()).toThrow('Call object is not available.');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.259",
3
+ "version": "1.0.261",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
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
- private setMuted(mute: boolean) {
260
+ public setMuted(mute: boolean) {
261
261
  try {
262
262
  if (!this.call) {
263
- throw new Error('Call object is not available.');
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 toggleMute() {
271
+ public isMuted() {
273
272
  try {
274
273
  if (!this.call) {
275
- throw new Error('Call object is not available.');
274
+ return false;
276
275
  }
277
- const isCurrentlyMuted = this.call.localAudio() === false;
278
- this.setMuted(!isCurrentlyMuted);
276
+ return this.call.localAudio() === false;
279
277
  } catch (error) {
280
- console.error("Error in toggleMute:", error);
281
- throw error;
278
+ throw error;
282
279
  }
283
- }
280
+ }
284
281
  }