@vindral/web-sdk 4.5.1-26-gf419005e4 → 4.5.1-28-g9cc413f1

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.
@@ -1,5 +1,5 @@
1
1
  import { n as e, t } from "./BsfwXDui.js";
2
- import { _ as n, a as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as ee, n as d, o as te, p as ne, r as re, s as ie, t as ae, u as oe, v as se } from "./BR0DDziv.js";
2
+ import { _ as n, a as r, c as i, d as a, f as o, g as s, h as c, i as l, l as u, m as ee, n as d, o as te, p as ne, r as re, s as ie, t as ae, u as oe, v as se } from "./viWJT_nb.js";
3
3
  import { F as ce } from "./BBVSf5AB.js";
4
4
  import { i as f, n as p, r as m, t as h } from "./DSw1XhvD.js";
5
5
  import { c as le, n as ue, t as de } from "./BOdyvABa.js";
package/cast-sender.d.ts CHANGED
@@ -332,6 +332,9 @@ interface Options {
332
332
  * This enables platform media features such as fullscreen and picture-in-picture
333
333
  * for non-MSE playback by routing the canvas output through a `<video>` element.
334
334
  *
335
+ * On iOS the audio then plays from its own element, so it continues in the background and under
336
+ * lock. After an extended pause from the lock screen, reopening Safari may be required to resume.
337
+ *
335
338
  * Disabled by default.
336
339
  */
337
340
  streamToMediaElementEnabled?: boolean;
package/core.d.ts CHANGED
@@ -428,6 +428,9 @@ export interface Options {
428
428
  * This enables platform media features such as fullscreen and picture-in-picture
429
429
  * for non-MSE playback by routing the canvas output through a `<video>` element.
430
430
  *
431
+ * On iOS the audio then plays from its own element, so it continues in the background and under
432
+ * lock. After an extended pause from the lock screen, reopening Safari may be required to resume.
433
+ *
431
434
  * Disabled by default.
432
435
  */
433
436
  streamToMediaElementEnabled?: boolean;
@@ -1654,6 +1657,7 @@ export declare class Vindral extends Emitter<PublicVindralEvents> {
1654
1657
  * the page is visible, so a hidden pause is a stop there. Reads the decoder in use.
1655
1658
  */
1656
1659
  private hiddenPauseIsStop;
1660
+ private usesSplitCanvasAudio;
1657
1661
  private isWebKitCanvasPath;
1658
1662
  private holdsDecoyWhilePaused;
1659
1663
  private streamsToMediaElement;
package/core.js CHANGED
@@ -1,3 +1,3 @@
1
- import { t as e } from "./BR0DDziv.js";
1
+ import { t as e } from "./viWJT_nb.js";
2
2
  import { a as t, c as n, d as r, f as i, i as a, l as o, n as s, o as c, r as l, s as u } from "./BBVSf5AB.js";
3
3
  export { s as AUTHENTICATION_EXPIRED_CODE, l as AUTHENTICATION_FAILED_CODE, a as CHANNEL_NOT_FOUND_CODE, t as CHANNEL_NOT_LIVE_CODE, c as CONNECTION_FAILED_AFTER_RETRIES_CODE, u as CONNECTION_FAILED_CODE, n as DISCONNECTED_BY_EDGE, o as INACTIVITY_CODE, r as NO_INCOMING_DATA, e as Vindral, i as VindralError };
package/legacy.d.ts CHANGED
@@ -431,6 +431,9 @@ export interface Options {
431
431
  * This enables platform media features such as fullscreen and picture-in-picture
432
432
  * for non-MSE playback by routing the canvas output through a `<video>` element.
433
433
  *
434
+ * On iOS the audio then plays from its own element, so it continues in the background and under
435
+ * lock. After an extended pause from the lock screen, reopening Safari may be required to resume.
436
+ *
434
437
  * Disabled by default.
435
438
  */
436
439
  streamToMediaElementEnabled?: boolean;
@@ -1669,6 +1672,7 @@ export declare class Vindral extends Emitter<PublicVindralEvents> {
1669
1672
  * the page is visible, so a hidden pause is a stop there. Reads the decoder in use.
1670
1673
  */
1671
1674
  private hiddenPauseIsStop;
1675
+ private usesSplitCanvasAudio;
1672
1676
  private isWebKitCanvasPath;
1673
1677
  private holdsDecoyWhilePaused;
1674
1678
  private streamsToMediaElement;
package/legacy.es.js CHANGED
@@ -4522,7 +4522,7 @@ var Pl = class e extends Kt {
4522
4522
  this.element.muted = this._userProvidedMuted, this._play().catch(S);
4523
4523
  }), p(this, "play", () => {
4524
4524
  this.element.muted = this._userProvidedMuted, this._play().catch((e) => {
4525
- if (e instanceof Error) {
4525
+ if (e instanceof Error && e.name !== "AbortError") {
4526
4526
  let t = new U("Media Play Error", {
4527
4527
  source: e,
4528
4528
  isFatal: !1,
@@ -10459,10 +10459,10 @@ var ex = 5, tx = 40, nx = 1, rx = 5, ix = (e) => {
10459
10459
  m();
10460
10460
  var ux, dx = class {
10461
10461
  constructor(e) {
10462
- p(this, "emitter", void 0), p(this, "isVisibleCount", 0), p(this, "isHiddenCount", 0), p(this, "isOnlineCount", 0), p(this, "isOfflineCount", 0), p(this, "isActive", document.visibilityState === "visible"), p(this, "unload", () => {
10463
- document.removeEventListener("visibilitychange", this.onVisibilityChanged), window.removeEventListener("pageshow", this.onPageShow), window.removeEventListener("pagehide", this.onPageHide), window.removeEventListener("online", this.onOnline), window.removeEventListener("offline", this.onOffline);
10462
+ p(this, "emitter", void 0), p(this, "isVisibleCount", 0), p(this, "isHiddenCount", 0), p(this, "isOnlineCount", 0), p(this, "isOfflineCount", 0), p(this, "isActive", document.visibilityState === "visible"), p(this, "isBehindAnotherApp", !1), p(this, "unload", () => {
10463
+ this.emitter.off("fullscreen app switch", this.onFullscreenAppSwitch), window.removeEventListener("focus", this.onVisibilityChanged), document.removeEventListener("visibilitychange", this.onVisibilityChanged), window.removeEventListener("pageshow", this.onPageShow), window.removeEventListener("pagehide", this.onPageHide), window.removeEventListener("online", this.onOnline), window.removeEventListener("offline", this.onOffline);
10464
10464
  }), p(this, "load", () => {
10465
- document.addEventListener("visibilitychange", this.onVisibilityChanged), window.addEventListener("pageshow", this.onPageShow), window.addEventListener("pagehide", this.onPageHide), window.addEventListener("online", this.onOnline), window.addEventListener("offline", this.onOffline);
10465
+ this.emitter.on("fullscreen app switch", this.onFullscreenAppSwitch), window.addEventListener("focus", this.onVisibilityChanged), document.addEventListener("visibilitychange", this.onVisibilityChanged), window.addEventListener("pageshow", this.onPageShow), window.addEventListener("pagehide", this.onPageHide), window.addEventListener("online", this.onOnline), window.addEventListener("offline", this.onOffline);
10466
10466
  }), p(this, "unsuspend", () => {}), p(this, "getStatistics", () => {
10467
10467
  var e, t, n, r, i;
10468
10468
  return {
@@ -10479,9 +10479,11 @@ var ux, dx = class {
10479
10479
  navigatorDownlink: (i = navigator.connection) == null ? void 0 : i.downlink
10480
10480
  };
10481
10481
  }), p(this, "onOnline", () => this.isOnlineCount++), p(this, "onOffline", () => this.isOfflineCount++), p(this, "onPageShow", (e) => {
10482
- this.emitter.emit("pageshow", e), this.setIsActive(document.visibilityState === "visible");
10482
+ this.emitter.emit("pageshow", e), this.onVisibilityChanged();
10483
10483
  }), p(this, "onPageHide", (e) => this.emitter.emit("pagehide", e)), p(this, "onVisibilityChanged", () => {
10484
- this.setIsActive(document.visibilityState === "visible");
10484
+ this.isBehindAnotherApp = !1, this.setIsActive(this.isVisible);
10485
+ }), p(this, "onFullscreenAppSwitch", () => {
10486
+ this.isBehindAnotherApp = !0, this.setIsActive(!1);
10485
10487
  }), p(this, "setIsActive", (e) => {
10486
10488
  e !== this.isActive && (this.emitter.emit("page active", e), e ? this.isVisibleCount++ : this.isHiddenCount++), this.isActive = e;
10487
10489
  }), this.emitter = e;
@@ -10490,7 +10492,7 @@ var ux, dx = class {
10490
10492
  return navigator.onLine;
10491
10493
  }
10492
10494
  get isVisible() {
10493
- return document.visibilityState === "visible";
10495
+ return document.visibilityState === "visible" && !this.isBehindAnotherApp;
10494
10496
  }
10495
10497
  };
10496
10498
  ux = dx, p(dx, "create", (e) => new ux(e)), H(), m(), B();
@@ -10739,11 +10741,13 @@ var Sx, Cx = 150, wx = 400, Tx = (e) => e === void 0 ? 5 : e <= Cx ? 1 : e <= wx
10739
10741
  })), p(this, "suspend", () => {
10740
10742
  this.setGain(0);
10741
10743
  }), p(this, "unsuspend", () => {
10742
- var e;
10743
10744
  if (this.setGain(this._volume), !Qe()) {
10744
10745
  this.resume().catch(this.onUnsuspendFailure);
10745
10746
  return;
10746
10747
  }
10748
+ this.restartContext();
10749
+ }), p(this, "restartContext", () => {
10750
+ var e;
10747
10751
  this.ignoreSuspendCalls = !!this.audio, (e = this.audio) == null || e.suspend().then(N(function* () {
10748
10752
  yield a.resume(), a.ignoreSuspendCalls = !1;
10749
10753
  })).catch(this.onUnsuspendFailure);
@@ -10823,7 +10827,11 @@ var Sx, Cx = 150, wx = 400, Tx = (e) => e === void 0 ? 5 : e <= Cx ? 1 : e <= wx
10823
10827
  return (e = this.audio) == null || e.unload(), this.audio = new xx(), this.audio.on("state", (e) => {
10824
10828
  this.logger.info("AudioContext state change", { state: e }), e === "running" && (this._muted = this._userProvidedMuted, this.setGain(this._volume)), !this.ignoreSuspendCalls && this.emit("state change", e);
10825
10829
  }), this.audio.on("stuck", () => {
10826
- this.reInitWhenStuck && (this.logger.info("Re-init audio context"), this.setupContext(), this.resume().catch(S), this.emit("stuck"));
10830
+ if (!this.reInitWhenStuck) {
10831
+ this.restartContext();
10832
+ return;
10833
+ }
10834
+ this.logger.info("Re-init audio context"), this.setupContext(), this.resume().catch(S), this.emit("stuck");
10827
10835
  }), (t = this.gainNode) == null || t.disconnect(), this.gainNode = this.audio.createGain(), this.setGain(this._volume), this.startTime = this.audio.currentTime, (n = this.splitter) == null || n.disconnect(), this.splitter = this.audio.createSplitter(), this.audio;
10828
10836
  }), p(this, "setGain", (e) => {
10829
10837
  this.gainNode && (this.gainNode.gain.value = this._muted ? 0 : e);
@@ -11233,30 +11241,49 @@ var Fx, Ix = [
11233
11241
  };
11234
11242
  Fx = zx, p(zx, "create", (e, t, n) => new Fx(e, t, n)), p(zx, "isSupported", () => typeof navigator < "u" && "mediaSession" in navigator && typeof MediaMetadata < "u"), Bi(), H(), m(), B();
11235
11243
  var Bx, Vx = class {
11236
- constructor(e, t, n, r, { muted: i, volume: a, type: o, poster: s, offscreenCanvas: c, bufferTime: l, backgroundPlaybackEnabled: u }) {
11237
- p(this, "logger", void 0), p(this, "emitter", void 0), p(this, "mediaElement", void 0), p(this, "audioPlayer", void 0), p(this, "videoPlayer", void 0), p(this, "pool", void 0), p(this, "isDisconnected", !0), p(this, "_userProvidedMuted", !1), p(this, "timers", new Zn()), p(this, "offscreenCanvas", void 0), p(this, "videoTrack", void 0), p(this, "canvasCaptureTracks", []), p(this, "backgroundPlaybackEnabled", void 0), p(this, "nativeTracksByLanguage", /* @__PURE__ */ new Map()), p(this, "nativeCuesByLanguage", /* @__PURE__ */ new Map()), p(this, "lastCanvasCueTexts", []), p(this, "isIOSNativeFullscreen", !1), p(this, "isSyncingNativeTextTracks", !1), p(this, "renderCanvasSubtitlesInNativeFullscreen", (() => {
11244
+ constructor(e, t, n, r, { muted: i, volume: a, type: o, poster: s, offscreenCanvas: c, bufferTime: l, backgroundPlaybackEnabled: u, splitAudio: d }) {
11245
+ if (p(this, "logger", void 0), p(this, "emitter", void 0), p(this, "mediaElement", void 0), p(this, "sound", void 0), p(this, "wantsPlay", void 0), p(this, "audioPlayer", void 0), p(this, "videoPlayer", void 0), p(this, "pool", void 0), p(this, "isDisconnected", !0), p(this, "_userProvidedMuted", !1), p(this, "timers", new Zn()), p(this, "offscreenCanvas", void 0), p(this, "videoTrack", void 0), p(this, "canvasCaptureTracks", []), p(this, "backgroundPlaybackEnabled", void 0), p(this, "nativeTracksByLanguage", /* @__PURE__ */ new Map()), p(this, "nativeCuesByLanguage", /* @__PURE__ */ new Map()), p(this, "lastCanvasCueTexts", []), p(this, "isIOSNativeFullscreen", !1), p(this, "isSyncingNativeTextTracks", !1), p(this, "renderCanvasSubtitlesInNativeFullscreen", (() => {
11238
11246
  let e = at().platform;
11239
11247
  return e.isIOS && e.iosVersion <= 16;
11240
11248
  })()), p(this, "volumeState", void 0), p(this, "textTracks", new Ax()), p(this, "reset", () => {}), p(this, "load", () => {
11241
- this.mediaElement.load(), this.emitter.on("decoded frame", this.onDecodedFrame), this.emitter.on("flush buffers", this.flushBuffers), this.emitter.on("ios-hack: reset size", this.resetCanvasSize), this.emitter.on("enter picture in picture", this.onEnterIOSHack), this.emitter.on("exit picture in picture", this.onExitIOSHack), this.element().element.textTracks.addEventListener("change", this.onNativeTextTrackChange), this.element().element.addEventListener("webkitendfullscreen", this.onExitIOSHack), this.element().element.addEventListener("webkitbeginfullscreen", this.onEnterIOSHack), this.videoPlayer.load(), this.timers.setInterval(this.syncNativeTextTracks, 100);
11249
+ this.mediaElement.load(), this.sound && (this.sound.load(), document.body.appendChild(this.sound.element), this.mediaElement.element.addEventListener("pause", this.onVideoPause), this.mediaElement.element.addEventListener("play", this.onVideoPlay), window.addEventListener("focus", this.onWindowFocus)), this.emitter.on("decoded frame", this.onDecodedFrame), this.emitter.on("flush buffers", this.flushBuffers), this.emitter.on("ios-hack: reset size", this.resetCanvasSize), this.emitter.on("enter picture in picture", this.onEnterIOSHack), this.emitter.on("exit picture in picture", this.onExitIOSHack), this.element().element.textTracks.addEventListener("change", this.onNativeTextTrackChange), this.element().element.addEventListener("webkitendfullscreen", this.onExitIOSHack), this.element().element.addEventListener("webkitbeginfullscreen", this.onEnterIOSHack), this.videoPlayer.load(), this.timers.setInterval(this.syncNativeTextTracks, 100);
11242
11250
  }), p(this, "unload", () => {
11243
11251
  this.emitter.off("target buffer time", this.onTargetBufferTime), this.emitter.off("decoded frame", this.onDecodedFrame), this.emitter.off("flush buffers", this.flushBuffers), this.emitter.off("ios-hack: reset size", this.resetCanvasSize), this.emitter.off("enter picture in picture", this.onEnterIOSHack), this.emitter.off("exit picture in picture", this.onExitIOSHack), this.element().element.textTracks.removeEventListener("change", this.onNativeTextTrackChange), this.element().element.removeEventListener("webkitendfullscreen", this.onExitIOSHack), this.element().element.removeEventListener("webkitbeginfullscreen", this.onEnterIOSHack);
11244
11252
  for (let e of this.nativeTracksByLanguage.keys()) this.clearNativeCues(e);
11245
- this.nativeTracksByLanguage.clear(), this.nativeCuesByLanguage.clear(), this.mediaElement.unload(), this.timers.unload(), this.audioPlayer.unload(), this.videoPlayer.unload();
11253
+ this.nativeTracksByLanguage.clear(), this.nativeCuesByLanguage.clear(), this.sound && (this.mediaElement.element.removeEventListener("pause", this.onVideoPause), this.mediaElement.element.removeEventListener("play", this.onVideoPlay), window.removeEventListener("focus", this.onWindowFocus), this.sound.pause(), this.sound.element.srcObject = null, this.sound.unload(), this.sound.element.remove()), this.mediaElement.unload(), this.timers.unload(), this.audioPlayer.unload(), this.videoPlayer.unload();
11246
11254
  }), p(this, "suspend", () => {
11247
11255
  this.videoPlayer.suspend(), this.audioPlayer.suspend();
11248
11256
  }), p(this, "unsuspend", () => {
11249
11257
  this.videoPlayer.unsuspend(), this.audioPlayer.unsuspend();
11250
- }), p(this, "element", () => this.mediaElement), p(this, "getStatistics", () => z(z({}, this.videoPlayer.getStatistics()), {}, { audioContextState: this.audioPlayer.contextState })), p(this, "activateAudioPlayer", () => (this.isDisconnected && this.connectStreams(), this.audioPlayer.play())), p(this, "flushBuffers", () => {
11258
+ }), p(this, "element", () => this.mediaElement), p(this, "elements", () => this.sound ? [this.mediaElement, this.sound] : [this.mediaElement]), p(this, "getStatistics", () => z(z({}, this.videoPlayer.getStatistics()), {}, { audioContextState: this.audioPlayer.contextState })), p(this, "activateAudioPlayer", () => (this.isDisconnected && this.connectStreams(), this.audioPlayer.play())), p(this, "flushBuffers", () => {
11251
11259
  this.audioPlayer.flushBuffer();
11252
11260
  }), p(this, "onTargetBufferTime", (e) => {
11253
11261
  this.audioPlayer.bufferTime = e;
11254
11262
  }), p(this, "resetCanvasSize", () => {
11255
11263
  this.videoPlayer.resetSize();
11264
+ }), p(this, "onVideoPause", () => {
11265
+ this.mediaElement.element.paused && (this.emitPlaybackState(), this.wantsPlay && this.timers.setTimeout(this.isIOSNativeFullscreen ? this.reportFullscreenPause : this.restartVideoIfWanted, 400));
11266
+ }), p(this, "onVideoPlay", () => {
11267
+ if (!this.mediaElement.element.paused) {
11268
+ if (!this.wantsPlay) {
11269
+ this.isIOSNativeFullscreen ? this.emitter.emit("native control", "play") : this.mediaElement.pause();
11270
+ return;
11271
+ }
11272
+ this.emitPlaybackState();
11273
+ }
11256
11274
  }), p(this, "onEnterIOSHack", () => {
11257
11275
  this.isIOSNativeFullscreen = !0, this.mediaElement._iosHackEnterPiPMode();
11258
11276
  }), p(this, "onExitIOSHack", () => {
11259
- this.isIOSNativeFullscreen = !1, this.clearCanvasCues(), this.mediaElement._iosHackExitPiPMode();
11277
+ this.isIOSNativeFullscreen = !1, this.clearCanvasCues(), this.mediaElement._iosHackExitPiPMode(), this.sound && this.restartVideoIfWanted();
11278
+ }), p(this, "reportFullscreenPause", () => {
11279
+ !this.isIOSNativeFullscreen || !this.wantsPlay || !this.mediaElement.element.paused || (St(this.mediaElement.element) === "picture-in-picture" || document.hasFocus() ? this.emitter.emit("native control", "pause") : this.emitter.emit("fullscreen app switch"));
11280
+ }), p(this, "onWindowFocus", () => {
11281
+ this.isIOSNativeFullscreen && this.wantsPlay && this.mediaElement.element.paused && this.mediaElement.tryPlay();
11282
+ }), p(this, "lastPlaybackState", void 0), p(this, "emitPlaybackState", () => {
11283
+ let e = this.isPaused ? "paused" : "playing";
11284
+ e !== this.lastPlaybackState && (this.lastPlaybackState = e, this.emitter.emit("media element state", e));
11285
+ }), p(this, "restartVideoIfWanted", () => {
11286
+ this.wantsPlay && this.mediaElement.element.paused && !this.isIOSNativeFullscreen && document.visibilityState === "visible" && this.mediaElement.tryPlay();
11260
11287
  }), p(this, "onDecodedFrame", (e) => {
11261
11288
  try {
11262
11289
  this.audioPlayer.onDecodedFrame(e);
@@ -11275,10 +11302,10 @@ var Bx, Vx = class {
11275
11302
  this.logger.info(`Connecting streams using ${this.offscreenCanvas ? "OffscreenCanvas" : "VideoPlayer"} canvas (${e.width}x${e.height})`);
11276
11303
  let t = this.videoTrack ? [this.videoTrack] : e.captureStream().getTracks(), n = this.canvasCaptureTracks;
11277
11304
  this.canvasCaptureTracks = this.videoTrack ? [] : t;
11278
- let r = this.audioPlayer.useMediaStreamDestination().stream, i = [...t, ...r.getTracks()];
11305
+ let r = this.audioPlayer.useMediaStreamDestination().stream, i = this.sound ? t : [...t, ...r.getTracks()];
11279
11306
  this.logger.info(`Video tracks: ${t.length} (${this.videoTrack ? "worker track" : "canvas capture"}), Audio tracks: ${r.getTracks().length}`);
11280
11307
  for (let e of n) e.stop();
11281
- this.mediaElement.element.srcObject = new MediaStream(i), this.isDisconnected = !1;
11308
+ this.mediaElement.element.srcObject = new MediaStream(i), this.sound && this.sound.element.srcObject !== r && (this.sound.element.srcObject = r), this.isDisconnected = !1;
11282
11309
  }), p(this, "setVideoTrack", (e) => {
11283
11310
  this.videoTrack !== e && (this.videoTrack = e, this.reconnectCanvasStream());
11284
11311
  }), p(this, "setOffscreenCanvas", (e) => {
@@ -11354,43 +11381,48 @@ var Bx, Vx = class {
11354
11381
  }), p(this, "applyVisibilityMutePolicy", () => {
11355
11382
  if (!this.audioPlayer.isContextRunning) return;
11356
11383
  let e = document.visibilityState === "hidden";
11357
- this.mediaElement.muted = this._userProvidedMuted || e && !this.backgroundPlaybackEnabled;
11384
+ this.soundElement.muted = this._userProvidedMuted || e && !this.backgroundPlaybackEnabled;
11358
11385
  }), this.logger = t, this.emitter = e, this.pool = n, this._userProvidedMuted = i, this.offscreenCanvas = c, this.backgroundPlaybackEnabled = u == null ? !1 : u, this.emitter.on("target buffer time", this.onTargetBufferTime), this.mediaElement = new Pl({
11359
11386
  poster: s,
11360
11387
  type: o,
11361
- muted: i,
11388
+ muted: d ? !0 : i,
11362
11389
  volume: a,
11363
11390
  autoplay: !1,
11364
11391
  logger: this.logger.createContext("MediaElement")
11365
- }), this.mediaElement.on("volume state", (e) => {
11392
+ }), d && (this.sound = new Pl({
11393
+ type: "audio",
11394
+ muted: i,
11395
+ volume: a,
11396
+ autoplay: !1,
11397
+ logger: this.logger.createContext("SoundElement")
11398
+ }), this.sound.element.style.display = "none", this.sound.element.setAttribute("aria-hidden", "true")), this.soundElement.on("volume state", (e) => {
11366
11399
  this.updateVolumeState(), !e.isMuted && !this.audioPlayer.isContextRunning && this.activateAudioPlayer().catch(S), e.isMuted || (this._userProvidedMuted = !1);
11367
- }), this.mediaElement.on("media element state", (e) => {
11368
- e === "paused" && this.audioPlayer.flushBuffer(), this.audioPlayer.sinkPaused = e === "paused", this.emitter.emit("media element state", e);
11369
- }), this.audioPlayer = Ex.create(this.logger.createContext("AudioPlayerModule"), r, {
11400
+ }), this.soundElement.on("media element state", (e) => {
11401
+ e === "paused" && this.audioPlayer.flushBuffer(), this.audioPlayer.sinkPaused = e === "paused", this.emitPlaybackState();
11402
+ }), this.sound) for (let e of this.elements()) e.on("needs user input", (e) => this.emitter.emit("needs user input", e)), e.on("error", (e) => this.emitter.emit("error", e));
11403
+ this.audioPlayer = Ex.create(this.logger.createContext("AudioPlayerModule"), r, {
11370
11404
  muted: !1,
11371
11405
  reInitWhenStuck: !1,
11372
11406
  bufferTime: l
11373
- }), this.audioPlayer.on("stuck", () => {
11374
- this.isDisconnected = !0;
11375
11407
  }), this.audioPlayer.on("state change", (e) => {
11376
- e === "suspended" || e === "interrupted" ? this.mediaElement.muted = !0 : e === "running" && this.applyVisibilityMutePolicy(), this.updateVolumeState();
11408
+ e === "suspended" || e === "interrupted" ? this.soundElement.muted = !0 : e === "running" && this.applyVisibilityMutePolicy(), this.updateVolumeState();
11377
11409
  }), this.videoPlayer = Ox.create(this.logger.createContext("VideoPlayerModule"), this.audioPlayer, this.pool, this.mediaElement.element, () => this.reconnectCanvasStream(), this.onVideoPlayerError);
11378
11410
  }
11379
11411
  get volume() {
11380
- return this.mediaElement.volume;
11412
+ return this.soundElement.volume;
11381
11413
  }
11382
11414
  set volume(e) {
11383
- this.mediaElement.volume = e;
11415
+ this.soundElement.volume = e;
11384
11416
  }
11385
11417
  get muted() {
11386
- return this.mediaElement.muted || this.audioPlayer.muted;
11418
+ return this.soundElement.muted || this.audioPlayer.muted;
11387
11419
  }
11388
11420
  get userMuted() {
11389
- return this.audioPlayer.isContextRunning ? this.mediaElement.muted : this._userProvidedMuted;
11421
+ return this.audioPlayer.isContextRunning ? this.soundElement.muted : this._userProvidedMuted;
11390
11422
  }
11391
11423
  set muted(e) {
11392
11424
  let t = this.muted;
11393
- this._userProvidedMuted = e, this.mediaElement.muted = e, !e && t && this.activateAudioPlayer().catch(S);
11425
+ this._userProvidedMuted = e, this.soundElement.muted = e, !e && t && this.activateAudioPlayer().catch(S);
11394
11426
  }
11395
11427
  get currentTime() {
11396
11428
  return this.audioPlayer.currentTime;
@@ -11411,7 +11443,11 @@ var Bx, Vx = class {
11411
11443
  return this.mediaElement.totalSeekTime;
11412
11444
  }
11413
11445
  get isPaused() {
11414
- return this.mediaElement.isPaused;
11446
+ return this.sound ? this.wantsPlay === !1 || this.sound.isPaused && this.mediaElement.element.paused : this.mediaElement.isPaused;
11447
+ }
11448
+ get isPlayingAsRequested() {
11449
+ let e = this.soundElement.element;
11450
+ return !this.wantsPlay || !e.paused && e.muted === this._userProvidedMuted;
11415
11451
  }
11416
11452
  get isSeeking() {
11417
11453
  return this.mediaElement.isSeeking;
@@ -11420,16 +11456,23 @@ var Bx, Vx = class {
11420
11456
  return this.audioPlayer.audioNode;
11421
11457
  }
11422
11458
  play() {
11423
- let e = this._userProvidedMuted;
11459
+ var e;
11460
+ this.wantsPlay = !0;
11461
+ let t = this._userProvidedMuted;
11424
11462
  return this.activateAudioPlayer().catch(() => {
11425
- e || this.emitter.emit("needs user input", {
11463
+ t || this.emitter.emit("needs user input", {
11426
11464
  forAudio: !0,
11427
11465
  forVideo: !1
11428
11466
  });
11429
- }), this.mediaElement.play();
11467
+ }), (e = this.sound) == null || e.play(), this.mediaElement.play();
11430
11468
  }
11431
11469
  pause() {
11432
- this.mediaElement.pause();
11470
+ var e;
11471
+ this.wantsPlay = !1, (e = this.sound) == null || e.pause(), this.mediaElement.pause();
11472
+ }
11473
+ get soundElement() {
11474
+ var e;
11475
+ return (e = this.sound) == null ? this.mediaElement : e;
11433
11476
  }
11434
11477
  get canvasCuesEnabled() {
11435
11478
  return this.renderCanvasSubtitlesInNativeFullscreen && !this.offscreenCanvas;
@@ -12802,11 +12845,11 @@ var CS, wS = {
12802
12845
  CS = ES, p(ES, "create", (e, t, n, r) => new CS(e, t, n, r)), H(), m();
12803
12846
  var DS, OS = class {
12804
12847
  constructor(e, t, n) {
12805
- p(this, "logger", void 0), p(this, "element", void 0), p(this, "documentState", void 0), p(this, "timers", new Zn()), p(this, "unload", () => {
12848
+ p(this, "logger", void 0), p(this, "elements", void 0), p(this, "documentState", void 0), p(this, "timers", new Zn()), p(this, "unload", () => {
12806
12849
  this.timers.unload();
12807
12850
  }), p(this, "unpause", () => {
12808
- this.element.userHasProvidedInput && this.element.isPaused && this.documentState.isVisible && this.documentState.isOnline && (this.logger.debug("Unpause video"), this.element.tryPlay());
12809
- }), this.logger = e, this.element = t, this.documentState = n, this.timers.setInterval(this.unpause, 100);
12851
+ if (!(!this.documentState.isVisible || !this.documentState.isOnline)) for (let e of this.elements) e.userHasProvidedInput && e.isPaused && (this.logger.debug("Unpause media element"), e.tryPlay());
12852
+ }), this.logger = e, this.elements = t, this.documentState = n, this.timers.setInterval(this.unpause, 100);
12810
12853
  }
12811
12854
  };
12812
12855
  //#endregion
@@ -13397,7 +13440,7 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
13397
13440
  let e = this.modules.canvasModule instanceof Vx ? !0 : void 0;
13398
13441
  return z({
13399
13442
  uptime: this.uptime,
13400
- version: "4.5.1-26-gf419005e4",
13443
+ version: "4.5.1-28-g9cc413f1",
13401
13444
  clientId: this.clientId,
13402
13445
  sessionId: this.sessionId,
13403
13446
  channelId: this.channelId,
@@ -13464,7 +13507,7 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
13464
13507
  l && this.logger.warn("Option mseEnabled is deprecated and will be removed in a future release. Use decoders instead (e.g. decoders: [\"wasm\"])."), l && !u && t.mseEnabled === !1 && this.options.set("decoders", ["wasm"]);
13465
13508
  let d = eS.create(this.emitter, this.logger.createContext("PictureInPictureModule")), f = this.options.get("mediaSessionEnabled") ? zx.create(this.emitter, this.logger.createContext("MediaSessionModule"), {
13466
13509
  metadata: this.options.get("mediaSessionMetadata"),
13467
- decoy: this.willUseMediaSource() ? void 0 : Zl.create(this.logger.createContext("AudioFocusDecoy"), this.yieldToInterruption),
13510
+ decoy: this.willUseMediaSource() || this.usesSplitCanvasAudio() ? void 0 : Zl.create(this.logger.createContext("AudioFocusDecoy"), this.yieldToInterruption),
13468
13511
  isMuted: () => this.playbackSource.userMuted,
13469
13512
  isHidden: () => !this.modules.documentState.isVisible,
13470
13513
  isSinkPaused: () => this.isMediaElementPaused,
@@ -13496,7 +13539,7 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
13496
13539
  logger: this.logger.createContext("MediaElement"),
13497
13540
  poster: x
13498
13541
  });
13499
- e.on("buffer state", (e) => this.onMediaElementBufferState(e, te)), e.on("needs user input", (e) => this.emitter.emit("needs user input", e)), e.on("volume state", (e) => this.emitter.emit("volume state", e)), e.on("media element state", (e) => this.onMediaElementState(e)), this.element = e.element, this.playbackSource = e, Va.isSupported() && this.encryptedMediaExtensions.attach(e.element), te = Kx.create(this.logger.createContext("MseModule"), this.emitter, this.element), this.options.get("pauseSupportEnabled") || (ne = OS.create(this.logger.createContext("UnpauseModule"), e, b)), this.options.get("pictureInPictureEnabled") && this.emitter.emit("add picture in picture listener", { element: e.element });
13542
+ e.on("buffer state", (e) => this.onMediaElementBufferState(e, te)), e.on("needs user input", (e) => this.emitter.emit("needs user input", e)), e.on("volume state", (e) => this.emitter.emit("volume state", e)), e.on("media element state", (e) => this.onMediaElementState(e)), this.element = e.element, this.playbackSource = e, Va.isSupported() && this.encryptedMediaExtensions.attach(e.element), te = Kx.create(this.logger.createContext("MseModule"), this.emitter, this.element), this.options.get("pauseSupportEnabled") || (ne = OS.create(this.logger.createContext("UnpauseModule"), [e], b)), this.options.get("pictureInPictureEnabled") && this.emitter.emit("add picture in picture listener", { element: e.element });
13500
13543
  } else if (this.streamsToMediaElement()) {
13501
13544
  let e = Vx.create(this.emitter, this.logger.createContext("ModernCanvasModule"), this.pool, this, {
13502
13545
  type: this.options.get("media") === "audio" ? "audio" : "video",
@@ -13505,11 +13548,12 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
13505
13548
  poster: x,
13506
13549
  offscreenCanvas: this.offscreenCanvasElement,
13507
13550
  bufferTime: this.options.get("minBufferTime"),
13508
- backgroundPlaybackEnabled: this.isBackgroundPlayEnabled(this.channelId)
13509
- }), t = e.element();
13510
- this.element = t.element, this.playbackSource = e, ie = e;
13511
- let n = this.browser.platform.isIOS && this.browser.platform.iosVersion <= 15;
13512
- this.options.get("pictureInPictureEnabled") && !n && this.emitter.emit("add picture in picture listener", { element: this.element }), this.options.get("pauseSupportEnabled") || (ne = OS.create(this.logger.createContext("UnpauseModule"), t, b));
13551
+ backgroundPlaybackEnabled: this.isBackgroundPlayEnabled(this.channelId),
13552
+ splitAudio: this.usesSplitCanvasAudio()
13553
+ });
13554
+ this.element = e.element().element, this.playbackSource = e, ie = e;
13555
+ let t = this.browser.platform.isIOS && this.browser.platform.iosVersion <= 15;
13556
+ this.options.get("pictureInPictureEnabled") && !t && this.emitter.emit("add picture in picture listener", { element: this.element }), this.options.get("pauseSupportEnabled") || (ne = OS.create(this.logger.createContext("UnpauseModule"), e.elements(), b));
13513
13557
  } else {
13514
13558
  let e;
13515
13559
  e = Px.create(this.emitter, this.logger.createContext("LegacyCanvasModule"), this.pool, this, this.options.get("muted") || this.options.get("media") === "video", this.options.get("volume"), () => {
@@ -13565,9 +13609,11 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
13565
13609
  }), this.emitter.on("exit picture in picture", () => {
13566
13610
  var e;
13567
13611
  return (e = this.modules.decoder) == null ? void 0 : e.setVideoRenderingEnabled(this.modules.documentState.isVisible);
13568
- }), this.emitter.on("media session: request play", () => this.fromNativeControls("play")), this.emitter.on("media session: request pause", () => this.fromNativeControls("pause")), this.emitter.on("media session: request stop", () => this.fromNativeControls("pause")), this.emitter.on("page active", (e) => {
13612
+ }), this.emitter.on("media session: request play", () => this.fromNativeControls("play")), this.emitter.on("media session: request pause", () => this.fromNativeControls("pause")), this.emitter.on("media session: request stop", () => this.fromNativeControls("pause")), this.emitter.on("native control", (e) => {
13613
+ this.options.get("pauseSupportEnabled") && this.fromNativeControls(e);
13614
+ }), this.emitter.on("page active", (e) => {
13569
13615
  var t, n;
13570
- if ((t = this.modules.decoder) == null || t.setVideoRenderingEnabled(this.isVideoOnScreen(e)), e) this.clearInactivityDisconnect(), this.isUserPaused || (this.logger.debug("Unsuspending"), this.unsuspend());
13616
+ if ((t = this.modules.decoder) == null || t.setVideoRenderingEnabled(this.isVideoOnScreen(e)), e) this.clearInactivityDisconnect(), this.isUserPaused || (this.logger.debug("Unsuspending"), this.unsuspend(), this.usesSplitCanvasAudio() && this.playbackSource.isPlayingAsRequested === !1 && (this.logger.debug("Playing again after show"), this.play()));
13571
13617
  else if (this.clearVisiblePauseDisconnect(), this.logger.debug("Suspending"), this.suspend(), this.shouldAllowBackgroundPlayback(this.channelId)) {
13572
13618
  var r, i, a;
13573
13619
  (r = this.modules.decoder) == null || r.enableBackgroundTimers(), this.modules.connection.unsuspend(), this.modules.sync.unsuspend(), (i = this.modules.decoder) == null || i.unsuspend(), (a = this.modules.canvasModule) == null || a.unsuspend(), this.scheduleInactivityDisconnect();
@@ -14120,6 +14166,9 @@ var YS = 1e4, XS = 1280 * 720, ZS = /* @__PURE__ */ new WeakMap(), QS = /* @__PU
14120
14166
  resolvedDecoder(e) {
14121
14167
  return LS(this.options.get("decoders", e), this.browser.supportsMediaSource, this.options.get("drm"));
14122
14168
  }
14169
+ usesSplitCanvasAudio() {
14170
+ return !this.willUseMediaSource() && this.options.get("streamToMediaElementEnabled") && kt(this.browser) && this.options.get("media") !== "audio" && this.options.get("media") !== "video" && this.browser.platform.isIOS;
14171
+ }
14123
14172
  isWebKitCanvasPath() {
14124
14173
  return !this.willUseMediaSource() && this.browser.platform.isWebKit;
14125
14174
  }