@vapi-ai/web 1.0.193 → 1.0.197

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.
Files changed (3) hide show
  1. package/dist/vapi.js +16 -13
  2. package/package.json +1 -1
  3. package/vapi.ts +15 -14
package/dist/vapi.js CHANGED
@@ -31,14 +31,25 @@ function startPlayer(player, track) {
31
31
  }
32
32
  function buildAudioPlayer(track, participantId) {
33
33
  return __awaiter(this, void 0, void 0, function* () {
34
- const audioContainer = document.getElementById("audio-container");
35
34
  const player = document.createElement("audio");
36
35
  player.dataset.participantId = participantId;
37
- audioContainer === null || audioContainer === void 0 ? void 0 : audioContainer.appendChild(player);
36
+ document.body.appendChild(player);
38
37
  yield startPlayer(player, track);
39
38
  return player;
40
39
  });
41
40
  }
41
+ function subscribeToTracks(sessionId, call) {
42
+ console.log(sessionId);
43
+ if (sessionId === "local") {
44
+ return;
45
+ }
46
+ call.updateParticipant(sessionId, {
47
+ setSubscribedTracks: {
48
+ audio: true,
49
+ video: false,
50
+ },
51
+ });
52
+ }
42
53
  class Vapi extends events_1.default {
43
54
  constructor(apiToken, apiBaseUrl) {
44
55
  super();
@@ -79,8 +90,6 @@ class Vapi extends events_1.default {
79
90
  });
80
91
  this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
81
92
  var _b, _c;
82
- console.log("TRACK");
83
- console.log(e);
84
93
  if (!e)
85
94
  return;
86
95
  if (e.track.kind === "audio" && e.participant) {
@@ -92,15 +101,9 @@ class Vapi extends events_1.default {
92
101
  this.emit("call-start");
93
102
  }));
94
103
  this.call.on("participant-joined", (e) => {
95
- var _a, _b;
96
- console.log("JOINED");
97
- console.log(e);
98
- (_a = this.call) === null || _a === void 0 ? void 0 : _a.updateParticipant((_b = e === null || e === void 0 ? void 0 : e.participant.session_id) !== null && _b !== void 0 ? _b : "", {
99
- setSubscribedTracks: {
100
- audio: true,
101
- video: false,
102
- },
103
- });
104
+ if (!e || !this.call)
105
+ return;
106
+ subscribeToTracks(e.participant.session_id, this.call);
104
107
  });
105
108
  yield this.call.join({ url, subscribeToTracksAutomatically: false });
106
109
  this.call.startRemoteParticipantsAudioLevelObserver();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.193",
3
+ "version": "1.0.197",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -24,13 +24,24 @@ async function startPlayer(player: HTMLAudioElement, track: any) {
24
24
  }
25
25
  }
26
26
  async function buildAudioPlayer(track: any, participantId: string) {
27
- const audioContainer = document.getElementById("audio-container");
28
27
  const player = document.createElement("audio");
29
28
  player.dataset.participantId = participantId;
30
- audioContainer?.appendChild(player);
29
+ document.body.appendChild(player);
31
30
  await startPlayer(player, track);
32
31
  return player;
33
32
  }
33
+ function subscribeToTracks(sessionId: string, call: DailyCall) {
34
+ console.log(sessionId);
35
+ if (sessionId === "local") {
36
+ return;
37
+ }
38
+ call.updateParticipant(sessionId, {
39
+ setSubscribedTracks: {
40
+ audio: true,
41
+ video: false,
42
+ },
43
+ });
44
+ }
34
45
 
35
46
  export default class Vapi extends EventEmitter {
36
47
  private started: boolean = false;
@@ -78,9 +89,6 @@ export default class Vapi extends EventEmitter {
78
89
  });
79
90
 
80
91
  this.call.on("track-started", async (e) => {
81
- console.log("TRACK");
82
- console.log(e);
83
-
84
92
  if (!e) return;
85
93
  if (e.track.kind === "audio" && e.participant) {
86
94
  await buildAudioPlayer(e.track, e.participant.session_id);
@@ -92,15 +100,8 @@ export default class Vapi extends EventEmitter {
92
100
  });
93
101
 
94
102
  this.call.on("participant-joined", (e) => {
95
- console.log("JOINED");
96
- console.log(e);
97
-
98
- this.call?.updateParticipant(e?.participant.session_id ?? "", {
99
- setSubscribedTracks: {
100
- audio: true,
101
- video: false,
102
- },
103
- });
103
+ if (!e || !this.call) return;
104
+ subscribeToTracks(e.participant.session_id, this.call);
104
105
  });
105
106
 
106
107
  await this.call.join({ url, subscribeToTracksAutomatically: false });