@estuary-ai/sdk 0.1.5 → 0.1.7

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
@@ -9197,6 +9197,8 @@ var AudioPlayer = class {
9197
9197
  sampleRate;
9198
9198
  onEvent;
9199
9199
  audioContext = null;
9200
+ mediaStreamDest = null;
9201
+ audioElement = null;
9200
9202
  queue = [];
9201
9203
  currentSource = null;
9202
9204
  currentMessageId = null;
@@ -9232,6 +9234,16 @@ var AudioPlayer = class {
9232
9234
  }
9233
9235
  dispose() {
9234
9236
  this.clear();
9237
+ if (this.audioElement) {
9238
+ this.audioElement.pause();
9239
+ this.audioElement.srcObject = null;
9240
+ this.audioElement.remove();
9241
+ this.audioElement = null;
9242
+ }
9243
+ if (this.mediaStreamDest) {
9244
+ this.mediaStreamDest.disconnect();
9245
+ this.mediaStreamDest = null;
9246
+ }
9235
9247
  if (this.audioContext) {
9236
9248
  this.audioContext.close().catch(() => {
9237
9249
  });
@@ -9244,8 +9256,20 @@ var AudioPlayer = class {
9244
9256
  return null;
9245
9257
  }
9246
9258
  const AudioCtx = globalThis.AudioContext || globalThis.webkitAudioContext;
9247
- this.audioContext = new AudioCtx({ sampleRate: this.sampleRate });
9248
- return this.audioContext;
9259
+ const ctx = new AudioCtx({ sampleRate: this.sampleRate });
9260
+ this.audioContext = ctx;
9261
+ if (typeof document !== "undefined") {
9262
+ this.mediaStreamDest = ctx.createMediaStreamDestination();
9263
+ const el = document.createElement("audio");
9264
+ el.srcObject = this.mediaStreamDest.stream;
9265
+ el.autoplay = true;
9266
+ el.style.display = "none";
9267
+ document.body.appendChild(el);
9268
+ el.play().catch(() => {
9269
+ });
9270
+ this.audioElement = el;
9271
+ }
9272
+ return ctx;
9249
9273
  }
9250
9274
  playNext() {
9251
9275
  const ctx = this.getAudioContext();
@@ -9268,12 +9292,14 @@ var AudioPlayer = class {
9268
9292
  this.isPlaying = true;
9269
9293
  const source = ctx.createBufferSource();
9270
9294
  source.buffer = buffer;
9271
- source.connect(ctx.destination);
9295
+ source.connect(this.mediaStreamDest ?? ctx.destination);
9272
9296
  this.currentSource = source;
9273
9297
  source.onended = () => {
9274
9298
  this.currentSource = null;
9275
9299
  this.playNext();
9276
9300
  };
9301
+ ctx.resume().catch(() => {
9302
+ });
9277
9303
  source.start();
9278
9304
  }
9279
9305
  };