@vapi-ai/web 2.2.0 → 2.2.1

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
@@ -43,6 +43,7 @@ export default class Vapi extends VapiEventEmitter {
43
43
  private speakingTimeout;
44
44
  private dailyCallConfig;
45
45
  private dailyCallObject;
46
+ private hasEmittedCallEndedStatus;
46
47
  constructor(apiToken: string, apiBaseUrl?: string, dailyCallConfig?: Pick<DailyAdvancedConfig, 'avoidEval' | 'alwaysIncludeMicInPermissionPrompt'>, dailyCallObject?: Pick<DailyFactoryOptions, 'audioSource'>);
47
48
  private cleanup;
48
49
  private isMobileDevice;
package/dist/vapi.js CHANGED
@@ -62,6 +62,7 @@ class Vapi extends VapiEventEmitter {
62
62
  speakingTimeout = null;
63
63
  dailyCallConfig = {};
64
64
  dailyCallObject = {};
65
+ hasEmittedCallEndedStatus = false;
65
66
  constructor(apiToken, apiBaseUrl, dailyCallConfig, dailyCallObject) {
66
67
  super();
67
68
  client_1.client.baseUrl = apiBaseUrl ?? 'https://api.vapi.ai';
@@ -114,6 +115,14 @@ class Vapi extends VapiEventEmitter {
114
115
  this.call.iframe()?.style.setProperty('display', 'none');
115
116
  this.call.on('left-meeting', () => {
116
117
  this.emit('call-end');
118
+ if (!this.hasEmittedCallEndedStatus) {
119
+ this.emit('message', {
120
+ type: 'status-update',
121
+ status: 'ended',
122
+ 'endedReason': 'customer-ended-call',
123
+ });
124
+ this.hasEmittedCallEndedStatus = true;
125
+ }
117
126
  if (isVideoRecordingEnabled) {
118
127
  this.call?.stopRecording();
119
128
  }
@@ -241,6 +250,9 @@ class Vapi extends VapiEventEmitter {
241
250
  try {
242
251
  const parsedMessage = JSON.parse(e.data);
243
252
  this.emit('message', parsedMessage);
253
+ if (parsedMessage.type === 'status-update' && parsedMessage.status === 'ended') {
254
+ this.hasEmittedCallEndedStatus = true;
255
+ }
244
256
  }
245
257
  catch (parseError) {
246
258
  console.log('Error parsing message data: ', parseError);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vapi-ai/web",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "",
5
5
  "main": "dist/vapi.js",
6
6
  "types": "dist/vapi.d.ts",
package/vapi.ts CHANGED
@@ -152,6 +152,8 @@ export default class Vapi extends VapiEventEmitter {
152
152
  private dailyCallConfig: DailyAdvancedConfig = {};
153
153
  private dailyCallObject: DailyFactoryOptions = {};
154
154
 
155
+ private hasEmittedCallEndedStatus: boolean = false;
156
+
155
157
  constructor(
156
158
  apiToken: string,
157
159
  apiBaseUrl?: string,
@@ -232,6 +234,14 @@ export default class Vapi extends VapiEventEmitter {
232
234
 
233
235
  this.call.on('left-meeting', () => {
234
236
  this.emit('call-end');
237
+ if (!this.hasEmittedCallEndedStatus) {
238
+ this.emit('message', {
239
+ type: 'status-update',
240
+ status: 'ended',
241
+ 'endedReason': 'customer-ended-call',
242
+ });
243
+ this.hasEmittedCallEndedStatus = true;
244
+ }
235
245
  if (isVideoRecordingEnabled) {
236
246
  this.call?.stopRecording();
237
247
  }
@@ -379,6 +389,9 @@ export default class Vapi extends VapiEventEmitter {
379
389
  try {
380
390
  const parsedMessage = JSON.parse(e.data);
381
391
  this.emit('message', parsedMessage);
392
+ if (parsedMessage.type === 'status-update' && parsedMessage.status === 'ended') {
393
+ this.hasEmittedCallEndedStatus = true;
394
+ }
382
395
  } catch (parseError) {
383
396
  console.log('Error parsing message data: ', parseError);
384
397
  }