@vapi-ai/web 1.0.83 → 1.0.84
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/player.d.ts +3 -2
- package/dist/player.js +33 -21
- package/package.json +1 -1
- package/player.ts +26 -22
package/dist/player.d.ts
CHANGED
|
@@ -9,8 +9,9 @@ export declare class ContinuousPlayer extends EventEmitter {
|
|
|
9
9
|
start(): void;
|
|
10
10
|
playChunk(audioData: ArrayBuffer): void;
|
|
11
11
|
private appendNextChunk;
|
|
12
|
-
private
|
|
12
|
+
private performBufferOperation;
|
|
13
13
|
private removeBuffer;
|
|
14
14
|
private resetTimestampOffset;
|
|
15
|
-
|
|
15
|
+
private abortBuffer;
|
|
16
|
+
clear(): Promise<void>;
|
|
16
17
|
}
|
package/dist/player.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
@@ -42,20 +51,20 @@ class ContinuousPlayer extends events_1.default {
|
|
|
42
51
|
}
|
|
43
52
|
callback();
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (this.sourceBuffer
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
operation();
|
|
54
|
+
performBufferOperation(operation) {
|
|
55
|
+
return new Promise((resolve) => {
|
|
56
|
+
if (!this.sourceBuffer) {
|
|
57
|
+
resolve();
|
|
58
|
+
return;
|
|
54
59
|
}
|
|
55
|
-
|
|
60
|
+
this.sourceBuffer.addEventListener("updateend", () => resolve(), {
|
|
61
|
+
once: true,
|
|
62
|
+
});
|
|
63
|
+
operation();
|
|
64
|
+
});
|
|
56
65
|
}
|
|
57
66
|
removeBuffer() {
|
|
58
|
-
this.
|
|
67
|
+
return this.performBufferOperation(() => {
|
|
59
68
|
if (!this.sourceBuffer)
|
|
60
69
|
return;
|
|
61
70
|
while (this.sourceBuffer.buffered.length > 0) {
|
|
@@ -64,22 +73,25 @@ class ContinuousPlayer extends events_1.default {
|
|
|
64
73
|
});
|
|
65
74
|
}
|
|
66
75
|
resetTimestampOffset() {
|
|
67
|
-
this.
|
|
76
|
+
return this.performBufferOperation(() => {
|
|
68
77
|
if (!this.sourceBuffer)
|
|
69
78
|
return;
|
|
70
79
|
this.sourceBuffer.timestampOffset = 0;
|
|
71
80
|
});
|
|
72
81
|
}
|
|
82
|
+
abortBuffer() {
|
|
83
|
+
return this.performBufferOperation(() => {
|
|
84
|
+
if (!this.sourceBuffer)
|
|
85
|
+
return;
|
|
86
|
+
this.sourceBuffer.abort();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
73
89
|
clear() {
|
|
74
|
-
|
|
75
|
-
this.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
this.removeBuffer();
|
|
80
|
-
this.resetTimestampOffset();
|
|
81
|
-
});
|
|
82
|
-
}
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
yield this.removeBuffer();
|
|
92
|
+
yield this.abortBuffer();
|
|
93
|
+
yield this.resetTimestampOffset();
|
|
94
|
+
});
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
exports.ContinuousPlayer = ContinuousPlayer;
|
package/package.json
CHANGED
package/player.ts
CHANGED
|
@@ -58,20 +58,23 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
58
58
|
callback();
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
private
|
|
62
|
-
|
|
63
|
-
if (this.sourceBuffer
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
});
|
|
67
|
-
} else {
|
|
68
|
-
operation();
|
|
61
|
+
private performBufferOperation(operation: () => void) {
|
|
62
|
+
return new Promise<void>((resolve) => {
|
|
63
|
+
if (!this.sourceBuffer) {
|
|
64
|
+
resolve();
|
|
65
|
+
return;
|
|
69
66
|
}
|
|
70
|
-
|
|
67
|
+
|
|
68
|
+
this.sourceBuffer.addEventListener("updateend", () => resolve(), {
|
|
69
|
+
once: true,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
operation();
|
|
73
|
+
});
|
|
71
74
|
}
|
|
72
75
|
|
|
73
|
-
private removeBuffer()
|
|
74
|
-
this.
|
|
76
|
+
private removeBuffer() {
|
|
77
|
+
return this.performBufferOperation(() => {
|
|
75
78
|
if (!this.sourceBuffer) return;
|
|
76
79
|
while (this.sourceBuffer.buffered.length > 0) {
|
|
77
80
|
this.sourceBuffer.remove(0, this.sourceBuffer.buffered.end(0));
|
|
@@ -79,22 +82,23 @@ export class ContinuousPlayer extends EventEmitter {
|
|
|
79
82
|
});
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
private resetTimestampOffset()
|
|
83
|
-
this.
|
|
85
|
+
private resetTimestampOffset() {
|
|
86
|
+
return this.performBufferOperation(() => {
|
|
84
87
|
if (!this.sourceBuffer) return;
|
|
85
88
|
this.sourceBuffer.timestampOffset = 0;
|
|
86
89
|
});
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
92
|
+
private abortBuffer() {
|
|
93
|
+
return this.performBufferOperation(() => {
|
|
94
|
+
if (!this.sourceBuffer) return;
|
|
95
|
+
this.sourceBuffer.abort();
|
|
96
|
+
});
|
|
97
|
+
}
|
|
93
98
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
+
async clear() {
|
|
100
|
+
await this.removeBuffer();
|
|
101
|
+
await this.abortBuffer();
|
|
102
|
+
await this.resetTimestampOffset();
|
|
99
103
|
}
|
|
100
104
|
}
|