@vapi-ai/web 1.0.219 → 1.0.220

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,73 @@ 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
+ });
101
+ this.call.on("participant-left", (e) => {
102
+ if (!e)
103
+ return;
104
+ destroyAudioPlayer(e.participant.session_id);
105
+ });
106
+ this.call.on("error", () => {
107
+ // Ignore error
108
+ });
109
+ this.call.on("track-started", (e) => __awaiter(this, void 0, void 0, function* () {
110
+ var _b, _c, _d;
111
+ if (!e || !e.participant)
112
+ return;
113
+ if ((_b = e.participant) === null || _b === void 0 ? void 0 : _b.local)
114
+ return;
115
+ if (e.track.kind !== "audio")
116
+ return;
117
+ yield buildAudioPlayer(e.track, e.participant.session_id);
118
+ if (((_c = e === null || e === void 0 ? void 0 : e.participant) === null || _c === void 0 ? void 0 : _c.user_name) !== "Vapi Speaker")
119
+ return;
120
+ (_d = this.call) === null || _d === void 0 ? void 0 : _d.sendAppMessage("playable");
121
+ this.emit("call-start");
122
+ }));
123
+ this.call.on("participant-joined", (e) => {
124
+ if (!e || !this.call)
125
+ return;
126
+ subscribeToTracks(e, this.call);
127
+ });
128
+ yield this.call.join({
129
+ url: webCall.webCallUrl,
130
+ subscribeToTracksAutomatically: false,
131
+ });
132
+ this.call.startRemoteParticipantsAudioLevelObserver(100);
133
+ this.call.on("remote-participants-audio-level", (e) => this.handleRemoteParticipantsAudioLevel(e));
134
+ this.call.updateInputSettings({
135
+ audio: {
136
+ processor: {
137
+ type: "noise-cancellation",
138
+ },
139
139
  },
140
- },
141
- });
142
- }))
143
- .catch((res) => {
144
- console.error(res.error);
145
- this.emit("error", res.error);
146
- this.started = false;
140
+ });
141
+ return webCall;
142
+ }
143
+ catch (e) {
144
+ console.error(e);
145
+ this.emit("error", e);
146
+ this.started = false;
147
+ return null;
148
+ }
147
149
  });
148
150
  }
149
151
  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.220",
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,82 @@ 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
- },
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");
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: webCall.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",
171
170
  },
172
- });
173
- })
174
- .catch((res) => {
175
- console.error(res.error);
176
- this.emit("error", res.error);
177
- this.started = false;
171
+ },
178
172
  });
173
+
174
+ return webCall;
175
+ } catch (e) {
176
+ console.error(e);
177
+ this.emit("error", e);
178
+ this.started = false;
179
+ return null;
180
+ }
179
181
  }
180
182
 
181
183
  private handleRemoteParticipantsAudioLevel(