mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
fix: keep autoplay fallback from saving mute
(cherry picked from commit f373bb9ce7)
This commit is contained in:
1 parent
0513c7fcd8
commit
d8e5113efd
7 files changed
+96
-10
No files matched your search
@@ -232,7 +232,18 @@ export function createAuthSessionCoordinator(deps) {
|
||||
}
|
||||
|
||||
this.applyAuthenticatedUiState();
|
||||
this.commentController?.refreshAuthState?.();
|
||||
const activeModalVideo =
|
||||
typeof this.videoModal?.getCurrentVideo === "function"
|
||||
? this.videoModal.getCurrentVideo()
|
||||
: this.commentController?.currentVideo || null;
|
||||
if (this.commentController && activeModalVideo) {
|
||||
// Login can reconfigure relay-backed services. Reload the active thread
|
||||
// instead of only enabling its composer so readable comments survive
|
||||
// the transition from guest to authenticated state.
|
||||
this.commentController.load(activeModalVideo);
|
||||
} else {
|
||||
this.commentController?.refreshAuthState?.();
|
||||
}
|
||||
this.updateShareNostrAuthState({ reason: "auth-login" });
|
||||
if (typeof this.refreshUnreadDmIndicator === "function") {
|
||||
void this.refreshUnreadDmIndicator({ reason: "auth-login" });
|
||||
|
||||
@@ -237,7 +237,7 @@ export function createPlaybackCoordinator(deps) {
|
||||
this.log("Autoplay failed:", err);
|
||||
if (!this.modalVideo.muted) {
|
||||
this.log("Falling back to muted autoplay.");
|
||||
this.modalVideo.muted = true;
|
||||
this.playbackService.muteForAutoplayFallback(this.modalVideo);
|
||||
this.modalVideo.play().catch((err2) => {
|
||||
this.log("Muted autoplay also failed:", err2);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
import { userLogger } from "../utils/logger.js";
|
||||
import { PLAYBACK_START_TIMEOUT } from "../constants.js";
|
||||
import { getCurrentVideo, setCurrentVideo } from "../state/appState.js";
|
||||
import {
|
||||
consumeAutoplayFallbackMute,
|
||||
muteForAutoplayFallback,
|
||||
} from "../utils/autoplayPreference.js";
|
||||
import {
|
||||
SimpleEventEmitter,
|
||||
extractWebSeedsFromMagnet,
|
||||
@@ -330,11 +334,17 @@ export class PlaybackService {
|
||||
return;
|
||||
}
|
||||
const storedUnmuted = localStorage.getItem("unmutedAutoplay");
|
||||
const userWantsUnmuted = storedUnmuted === "true";
|
||||
// Sound is the default for an explicit watch action. Browsers may still
|
||||
// reject unmuted autoplay, in which case the coordinator retries muted.
|
||||
// Preserve a viewer's explicit mute choice across subsequent videos.
|
||||
const userWantsUnmuted = storedUnmuted !== "false";
|
||||
videoElement.muted = !userWantsUnmuted;
|
||||
|
||||
if (!videoElement.dataset.autoplayBound) {
|
||||
videoElement.addEventListener("volumechange", () => {
|
||||
if (consumeAutoplayFallbackMute(videoElement)) {
|
||||
return;
|
||||
}
|
||||
localStorage.setItem(
|
||||
"unmutedAutoplay",
|
||||
(!videoElement.muted).toString()
|
||||
@@ -344,6 +354,10 @@ export class PlaybackService {
|
||||
}
|
||||
}
|
||||
|
||||
muteForAutoplayFallback(videoElement) {
|
||||
return muteForAutoplayFallback(videoElement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a set of event listeners ("watchdogs") on the video element to detect
|
||||
* when playback has stalled or failed.
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
const FALLBACK_MUTE_DATASET_KEY = "bitvidAutoplayFallbackMute";
|
||||
|
||||
/**
|
||||
* Mute playback after an unmuted autoplay rejection without recording the
|
||||
* browser-policy fallback as a viewer preference.
|
||||
*/
|
||||
export function muteForAutoplayFallback(videoElement) {
|
||||
if (!videoElement || videoElement.muted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (videoElement.dataset) {
|
||||
videoElement.dataset[FALLBACK_MUTE_DATASET_KEY] = "true";
|
||||
}
|
||||
videoElement.muted = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Consume the marker attached to the next fallback-generated volume change. */
|
||||
export function consumeAutoplayFallbackMute(videoElement) {
|
||||
if (videoElement?.dataset?.[FALLBACK_MUTE_DATASET_KEY] !== "true") {
|
||||
return false;
|
||||
}
|
||||
|
||||
delete videoElement.dataset[FALLBACK_MUTE_DATASET_KEY];
|
||||
return true;
|
||||
}
|
||||
+2
-1
@@ -30,6 +30,7 @@ import {
|
||||
waitForActiveController as waitForActiveControllerHelper,
|
||||
} from "./webtorrentHelpers.js";
|
||||
import { devLogger, userLogger } from "./utils/logger.js";
|
||||
import { muteForAutoplayFallback } from "./utils/autoplayPreference.js";
|
||||
import { emit } from "./embedDiagnostics.js";
|
||||
|
||||
const DEFAULT_PROBE_TRACKERS = Object.freeze([...WSS_TRACKERS]);
|
||||
@@ -561,7 +562,7 @@ export class TorrentClient {
|
||||
return;
|
||||
}
|
||||
this.log(`Retrying with muted autoplay (${context} path).`);
|
||||
videoElement.muted = true;
|
||||
muteForAutoplayFallback(videoElement);
|
||||
videoElement.play().catch((err2) => {
|
||||
this.log(`Muted autoplay also failed (${context} path):`, err2);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user