@vapi-ai/web 1.0.219 → 1.0.221

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { CreateAssistantDTO } from "./api";
2
+ import { Call, CreateAssistantDTO } from "./api";
3
3
  import EventEmitter from "events";
4
4
  type VapiEventNames = "call-end" | "call-start" | "volume-level" | "speech-start" | "speech-end" | "error";
5
5
  type VapiEventListeners = {
@@ -22,7 +22,7 @@ export default class Vapi extends VapiEventEmitter {
22
22
  private call;
23
23
  private speakingTimeout;
24
24
  constructor(apiToken: string, apiBaseUrl?: string);
25
- start(assistant: CreateAssistantDTO | string): void;
25
+ start(assistant: CreateAssistantDTO | string): Promise<Call | null>;
26
26
  private handleRemoteParticipantsAudioLevel;
27
27
  stop(): void;
28
28
  }
package/dist/vapi.js CHANGED
@@ -79,71 +79,74 @@ class Vapi extends VapiEventEmitter {
79
79
  client_1.client.setSecurityData(apiToken);
80
80
  }
81
81
  start(assistant) {
82
- if (this.started) {
83
- return;
84
- }
85
- this.started = true;
86
- client_1.client.call
87
- .callControllerCreateWebCall({
88
- assistant: typeof assistant === "string" ? undefined : assistant,
89
- assistantId: typeof assistant === "string" ? assistant : undefined,
90
- })
91
- .then(({ data }) => __awaiter(this, void 0, void 0, function* () {
92
- var _a;
93
- const { webCallUrl } = data;
94
- this.call = daily_js_1.default.createCallObject({
95
- audioSource: true,
96
- videoSource: false,
97
- });
98
- (_a = this.call.iframe()) === null || _a === void 0 ? void 0 : _a.style.setProperty("display", "none");
99
- this.call.on("left-meeting", () => {
100
- this.emit("call-end");
101
- });
102
- this.call.on("participant-left", (e) => {
103
- if (!e)
104
- return;
105
- destroyAudioPlayer(e.participant.session_id);
106
- });
107
- this.call.on("error", () => {
108
- // Ignore error
109
- });
110
- this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
111
- var _b, _c, _d;
112
- if (!e || !e.participant)
113
- return;
114
- if ((_b = e.participant) === null || _b === void 0 ? void 0 : _b.local)
115
- return;
116
- if (e.track.kind !== "audio")
117
- return;
118
- yield buildAudioPlayer(e.track, e.participant.session_id);
119
- if (((_c = e === null || e === void 0 ? void 0 : e.participant) === null || _c === void 0 ? void 0 : _c.user_name) !== "Vapi Speaker")
120
- return;
121
- (_d = this.call) === null || _d === void 0 ? void 0 : _d.sendAppMessage("playable");
122
- this.emit("call-start");
123
- }));
124
- this.call.on("participant-joined", (e) => {
125
- if (!e || !this.call)
126
- return;
127
- subscribeToTracks(e, this.call);
128
- });
129
- yield this.call.join({
130
- url: webCallUrl,
131
- subscribeToTracksAutomatically: false,
132
- });
133
- this.call.startRemoteParticipantsAudioLevelObserver(100);
134
- this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
135
- this.call.updateInputSettings({
136
- audio: {
137
- processor: {
138
- type: "noise-cancellation",
82
+ var _a;
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ if (this.started) {
85
+ return null;
86
+ }
87
+ this.started = true;
88
+ try {
89
+ const webCall = (yield client_1.client.call.callControllerCreateWebCall({
90
+ assistant: typeof assistant === "string" ? undefined : assistant,
91
+ assistantId: typeof assistant === "string" ? assistant : undefined,
92
+ })).data;
93
+ this.call = daily_js_1.default.createCallObject({
94
+ audioSource: true,
95
+ videoSource: false,
96
+ });
97
+ (_a = this.call.iframe()) === null || _a === void 0 ? void 0 : _a.style.setProperty("display", "none");
98
+ this.call.on("left-meeting", () => {
99
+ this.emit("call-end");
100
+ this.started = false;
101
+ });
102
+ this.call.on("participant-left", (e) => {
103
+ if (!e)
104
+ return;
105
+ destroyAudioPlayer(e.participant.session_id);
106
+ });
107
+ this.call.on("error", () => {
108
+ // Ignore error
109
+ });
110
+ this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
111
+ var _b, _c, _d;
112
+ if (!e || !e.participant)
113
+ return;
114
+ if ((_b = e.participant) === null || _b === void 0 ? void 0 : _b.local)
115
+ return;
116
+ if (e.track.kind !== "audio")
117
+ return;
118
+ yield buildAudioPlayer(e.track, e.participant.session_id);
119
+ if (((_c = e === null || e === void 0 ? void 0 : e.participant) === null || _c === void 0 ? void 0 : _c.user_name) !== "Vapi Speaker")
120
+ return;
121
+ (_d = this.call) === null || _d === void 0 ? void 0 : _d.sendAppMessage("playable");
122
+ this.emit("call-start");
123
+ }));
124
+ this.call.on("participant-joined", (e) => {
125
+ if (!e || !this.call)
126
+ return;
127
+ subscribeToTracks(e, this.call);
128
+ });
129
+ yield this.call.join({
130
+ url: webCall.webCallUrl,
131
+ subscribeToTracksAutomatically: false,
132
+ });
133
+ this.call.startRemoteParticipantsAudioLevelObserver(100);
134
+ this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
135
+ this.call.updateInputSettings({
136
+ audio: {
137
+ processor: {
138
+ type: "noise-cancellation",
139
+ },
139
140
  },
140
- },
141
- });
142
- }))
143
- .catch((res) => {
144
- console.error(res.error);
145
- this.emit("error", res.error);
146
- this.started = false;
141
+ });
142
+ return webCall;
143
+ }
144
+ catch (e) {
145
+ console.error(e);
146
+ this.emit("error", e);
147
+ this.started = false;
148
+ return null;
149
+ }
147
150
  });
148
151
  }
149
152
  handleRemoteParticipantsAudioLevel(e) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "1.0.219",
3
+ "version": "1.0.221",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { Call, CreateAssistantDTO } from "./api";
1
2
  import DailyIframe, {
2
3
  DailyCall,
3
4
  DailyEventObjectActiveSpeakerChange,
@@ -5,7 +6,6 @@ import DailyIframe, {
5
6
  DailyEventObjectRemoteParticipantsAudioLevel,
6
7
  } from "@daily-co/daily-js";
7
8
 
8
- import { CreateAssistantDTO } from "./api";
9
9
  import EventEmitter from "events";
10
10
  import { client } from "./client";
11
11
 
@@ -102,80 +102,83 @@ export default class Vapi extends VapiEventEmitter {
102
102
  client.setSecurityData(apiToken);
103
103
  }
104
104
 
105
- start(assistant: CreateAssistantDTO | string): void {
105
+ async start(assistant: CreateAssistantDTO | string): Promise<Call | null> {
106
106
  if (this.started) {
107
- return;
107
+ return null;
108
108
  }
109
109
 
110
110
  this.started = true;
111
111
 
112
- client.call
113
- .callControllerCreateWebCall({
114
- assistant: typeof assistant === "string" ? undefined : assistant,
115
- assistantId: typeof assistant === "string" ? assistant : undefined,
116
- })
117
- .then(async ({ data }) => {
118
- const { webCallUrl } = data;
119
-
120
- this.call = DailyIframe.createCallObject({
121
- audioSource: true,
122
- videoSource: false,
123
- });
124
- this.call.iframe()?.style.setProperty("display", "none");
125
-
126
- this.call.on("left-meeting", () => {
127
- this.emit("call-end");
128
- });
129
-
130
- this.call.on("participant-left", (e) => {
131
- if (!e) return;
132
- destroyAudioPlayer(e.participant.session_id);
133
- });
134
-
135
- this.call.on("error", () => {
136
- // Ignore error
137
- });
138
-
139
- this.call.on("track-started", async (e) => {
140
- if (!e || !e.participant) return;
141
- if (e.participant?.local) return;
142
- if (e.track.kind !== "audio") return;
143
-
144
- await buildAudioPlayer(e.track, e.participant.session_id);
145
-
146
- if (e?.participant?.user_name !== "Vapi Speaker") return;
147
- this.call?.sendAppMessage("playable");
148
- this.emit("call-start");
149
- });
150
-
151
- this.call.on("participant-joined", (e) => {
152
- if (!e || !this.call) return;
153
- subscribeToTracks(e, this.call);
154
- });
155
-
156
- await this.call.join({
157
- url: webCallUrl,
158
- subscribeToTracksAutomatically: false,
159
- });
160
-
161
- this.call.startRemoteParticipantsAudioLevelObserver(100);
162
- this.call.on("remote-participants-audio-level", (e) =>
163
- this.handleRemoteParticipantsAudioLevel(e)
164
- );
165
-
166
- this.call.updateInputSettings({
167
- audio: {
168
- processor: {
169
- type: "noise-cancellation",
170
- },
171
- },
172
- });
173
- })
174
- .catch((res) => {
175
- console.error(res.error);
176
- this.emit("error", res.error);
112
+ try {
113
+ const webCall = (
114
+ await client.call.callControllerCreateWebCall({
115
+ assistant: typeof assistant === "string" ? undefined : assistant,
116
+ assistantId: typeof assistant === "string" ? assistant : undefined,
117
+ })
118
+ ).data;
119
+
120
+ this.call = DailyIframe.createCallObject({
121
+ audioSource: true,
122
+ videoSource: false,
123
+ });
124
+ this.call.iframe()?.style.setProperty("display", "none");
125
+
126
+ this.call.on("left-meeting", () => {
127
+ this.emit("call-end");
177
128
  this.started = false;
178
129
  });
130
+
131
+ this.call.on("participant-left", (e) => {
132
+ if (!e) return;
133
+ destroyAudioPlayer(e.participant.session_id);
134
+ });
135
+
136
+ this.call.on("error", () => {
137
+ // Ignore error
138
+ });
139
+
140
+ this.call.on("track-started", async (e) => {
141
+ if (!e || !e.participant) return;
142
+ if (e.participant?.local) return;
143
+ if (e.track.kind !== "audio") return;
144
+
145
+ await buildAudioPlayer(e.track, e.participant.session_id);
146
+
147
+ if (e?.participant?.user_name !== "Vapi Speaker") return;
148
+ this.call?.sendAppMessage("playable");
149
+ this.emit("call-start");
150
+ });
151
+
152
+ this.call.on("participant-joined", (e) => {
153
+ if (!e || !this.call) return;
154
+ subscribeToTracks(e, this.call);
155
+ });
156
+
157
+ await this.call.join({
158
+ url: webCall.webCallUrl,
159
+ subscribeToTracksAutomatically: false,
160
+ });
161
+
162
+ this.call.startRemoteParticipantsAudioLevelObserver(100);
163
+ this.call.on("remote-participants-audio-level", (e) =>
164
+ this.handleRemoteParticipantsAudioLevel(e)
165
+ );
166
+
167
+ this.call.updateInputSettings({
168
+ audio: {
169
+ processor: {
170
+ type: "noise-cancellation",
171
+ },
172
+ },
173
+ });
174
+
175
+ return webCall;
176
+ } catch (e) {
177
+ console.error(e);
178
+ this.emit("error", e);
179
+ this.started = false;
180
+ return null;
181
+ }
179
182
  }
180
183
 
181
184
  private handleRemoteParticipantsAudioLevel(