@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.
- package/dist/vapi.js +16 -13
- package/package.json +1 -1
- 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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
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
|
-
|
|
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
|
-
|
|
96
|
-
|
|
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 });
|