@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.js CHANGED
@@ -5170,7 +5170,19 @@ var init_livekit_voice = __esm({
5170
5170
  err
5171
5171
  );
5172
5172
  }
5173
- this.socketManager.emitEvent("livekit_join", { room: tokenData.room });
5173
+ await new Promise((resolve) => {
5174
+ const timeout = setTimeout(() => {
5175
+ this.socketManager.off("livekitConnected", onReady);
5176
+ this.logger.warn("Timed out waiting for livekit_ready, proceeding");
5177
+ resolve();
5178
+ }, 5e3);
5179
+ const onReady = () => {
5180
+ clearTimeout(timeout);
5181
+ resolve();
5182
+ };
5183
+ this.socketManager.once("livekitConnected", onReady);
5184
+ this.socketManager.emitEvent("livekit_join", { room: tokenData.room });
5185
+ });
5174
5186
  this._isActive = true;
5175
5187
  this.logger.debug("LiveKit voice started");
5176
5188
  }
@@ -9319,7 +9331,7 @@ var CharacterClient = class {
9319
9331
  };
9320
9332
 
9321
9333
  // src/audio/audio-player.ts
9322
- var AudioPlayer = class {
9334
+ var AudioPlayer = class _AudioPlayer {
9323
9335
  sampleRate;
9324
9336
  onEvent;
9325
9337
  audioContext = null;
@@ -9331,6 +9343,8 @@ var AudioPlayer = class {
9331
9343
  isPlaying = false;
9332
9344
  _isCleared = false;
9333
9345
  _interruptedMessageId = null;
9346
+ _drainTimer = null;
9347
+ static DRAIN_DELAY_MS = 300;
9334
9348
  constructor(sampleRate, onEvent) {
9335
9349
  this.sampleRate = sampleRate;
9336
9350
  this.onEvent = onEvent;
@@ -9353,6 +9367,7 @@ var AudioPlayer = class {
9353
9367
  this._interruptedMessageId = null;
9354
9368
  }
9355
9369
  this._isCleared = false;
9370
+ this.cancelDrain();
9356
9371
  const ctx = this.getAudioContext();
9357
9372
  if (!ctx) return;
9358
9373
  const pcm16 = base64ToInt16Array(voice.audio);
@@ -9366,6 +9381,7 @@ var AudioPlayer = class {
9366
9381
  }
9367
9382
  clear() {
9368
9383
  this._isCleared = true;
9384
+ this.cancelDrain();
9369
9385
  this.queue.length = 0;
9370
9386
  if (this.currentSource) {
9371
9387
  try {
@@ -9391,6 +9407,7 @@ var AudioPlayer = class {
9391
9407
  this.currentMessageId = null;
9392
9408
  }
9393
9409
  dispose() {
9410
+ this.cancelDrain();
9394
9411
  this.clear();
9395
9412
  if (this.audioElement) {
9396
9413
  this.audioElement.pause();
@@ -9408,6 +9425,25 @@ var AudioPlayer = class {
9408
9425
  this.audioContext = null;
9409
9426
  }
9410
9427
  }
9428
+ /** Schedule a deferred 'complete' event. Cancelled if new chunks arrive. */
9429
+ scheduleDrain() {
9430
+ if (this._drainTimer !== null) return;
9431
+ this._drainTimer = setTimeout(() => {
9432
+ this._drainTimer = null;
9433
+ if (this._isCleared) return;
9434
+ if (this.queue.length === 0 && this.isPlaying && this.currentMessageId) {
9435
+ this.onEvent({ type: "complete", messageId: this.currentMessageId });
9436
+ this.isPlaying = false;
9437
+ this.currentMessageId = null;
9438
+ }
9439
+ }, _AudioPlayer.DRAIN_DELAY_MS);
9440
+ }
9441
+ cancelDrain() {
9442
+ if (this._drainTimer !== null) {
9443
+ clearTimeout(this._drainTimer);
9444
+ this._drainTimer = null;
9445
+ }
9446
+ }
9411
9447
  getAudioContext() {
9412
9448
  if (this.audioContext) return this.audioContext;
9413
9449
  if (typeof AudioContext === "undefined" && typeof globalThis.webkitAudioContext === "undefined") {
@@ -9434,10 +9470,8 @@ var AudioPlayer = class {
9434
9470
  const ctx = this.getAudioContext();
9435
9471
  if (!ctx || this.queue.length === 0) {
9436
9472
  if (this.isPlaying && this.currentMessageId) {
9437
- this.onEvent({ type: "complete", messageId: this.currentMessageId });
9473
+ this.scheduleDrain();
9438
9474
  }
9439
- this.isPlaying = false;
9440
- this.currentMessageId = null;
9441
9475
  return;
9442
9476
  }
9443
9477
  const { buffer, messageId } = this.queue.shift();