@estuary-ai/sdk 0.1.29 → 0.1.31

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/index.mjs CHANGED
@@ -27166,7 +27166,19 @@ var init_livekit_voice = __esm({
27166
27166
  err
27167
27167
  );
27168
27168
  }
27169
- this.socketManager.emitEvent("livekit_join", { room: tokenData.room });
27169
+ await new Promise((resolve) => {
27170
+ const timeout = setTimeout(() => {
27171
+ this.socketManager.off("livekitConnected", onReady);
27172
+ this.logger.warn("Timed out waiting for livekit_ready, proceeding");
27173
+ resolve();
27174
+ }, 5e3);
27175
+ const onReady = () => {
27176
+ clearTimeout(timeout);
27177
+ resolve();
27178
+ };
27179
+ this.socketManager.once("livekitConnected", onReady);
27180
+ this.socketManager.emitEvent("livekit_join", { room: tokenData.room });
27181
+ });
27170
27182
  this._isActive = true;
27171
27183
  this.logger.debug("LiveKit voice started");
27172
27184
  }
@@ -31159,7 +31171,7 @@ var CharacterClient = class {
31159
31171
  };
31160
31172
 
31161
31173
  // src/audio/audio-player.ts
31162
- var AudioPlayer = class {
31174
+ var AudioPlayer = class _AudioPlayer {
31163
31175
  sampleRate;
31164
31176
  onEvent;
31165
31177
  audioContext = null;
@@ -31171,6 +31183,8 @@ var AudioPlayer = class {
31171
31183
  isPlaying = false;
31172
31184
  _isCleared = false;
31173
31185
  _interruptedMessageId = null;
31186
+ _drainTimer = null;
31187
+ static DRAIN_DELAY_MS = 300;
31174
31188
  constructor(sampleRate, onEvent) {
31175
31189
  this.sampleRate = sampleRate;
31176
31190
  this.onEvent = onEvent;
@@ -31193,6 +31207,7 @@ var AudioPlayer = class {
31193
31207
  this._interruptedMessageId = null;
31194
31208
  }
31195
31209
  this._isCleared = false;
31210
+ this.cancelDrain();
31196
31211
  const ctx = this.getAudioContext();
31197
31212
  if (!ctx) return;
31198
31213
  const pcm16 = base64ToInt16Array(voice.audio);
@@ -31206,6 +31221,7 @@ var AudioPlayer = class {
31206
31221
  }
31207
31222
  clear() {
31208
31223
  this._isCleared = true;
31224
+ this.cancelDrain();
31209
31225
  this.queue.length = 0;
31210
31226
  if (this.currentSource) {
31211
31227
  try {
@@ -31231,6 +31247,7 @@ var AudioPlayer = class {
31231
31247
  this.currentMessageId = null;
31232
31248
  }
31233
31249
  dispose() {
31250
+ this.cancelDrain();
31234
31251
  this.clear();
31235
31252
  if (this.audioElement) {
31236
31253
  this.audioElement.pause();
@@ -31248,6 +31265,25 @@ var AudioPlayer = class {
31248
31265
  this.audioContext = null;
31249
31266
  }
31250
31267
  }
31268
+ /** Schedule a deferred 'complete' event. Cancelled if new chunks arrive. */
31269
+ scheduleDrain() {
31270
+ if (this._drainTimer !== null) return;
31271
+ this._drainTimer = setTimeout(() => {
31272
+ this._drainTimer = null;
31273
+ if (this._isCleared) return;
31274
+ if (this.queue.length === 0 && this.isPlaying && this.currentMessageId) {
31275
+ this.onEvent({ type: "complete", messageId: this.currentMessageId });
31276
+ this.isPlaying = false;
31277
+ this.currentMessageId = null;
31278
+ }
31279
+ }, _AudioPlayer.DRAIN_DELAY_MS);
31280
+ }
31281
+ cancelDrain() {
31282
+ if (this._drainTimer !== null) {
31283
+ clearTimeout(this._drainTimer);
31284
+ this._drainTimer = null;
31285
+ }
31286
+ }
31251
31287
  getAudioContext() {
31252
31288
  if (this.audioContext) return this.audioContext;
31253
31289
  if (typeof AudioContext === "undefined" && typeof globalThis.webkitAudioContext === "undefined") {
@@ -31274,10 +31310,8 @@ var AudioPlayer = class {
31274
31310
  const ctx = this.getAudioContext();
31275
31311
  if (!ctx || this.queue.length === 0) {
31276
31312
  if (this.isPlaying && this.currentMessageId) {
31277
- this.onEvent({ type: "complete", messageId: this.currentMessageId });
31313
+ this.scheduleDrain();
31278
31314
  }
31279
- this.isPlaying = false;
31280
- this.currentMessageId = null;
31281
31315
  return;
31282
31316
  }
31283
31317
  const { buffer, messageId } = this.queue.shift();