diff --git a/src/mixer/state.ts b/src/mixer/state.ts index 0e7b604..fb96026 100644 --- a/src/mixer/state.ts +++ b/src/mixer/state.ts @@ -382,6 +382,13 @@ export const load = ( } } + // If somehow we've managed to re-load the channel without ending tracklisting. + // This could happen if they paused it at the end, or if Wavesurfer forgot somehow. + const tracklistItemID = getState().mixer.players[player].tracklistItemID; + if (tracklistItemID !== -1) { + dispatch(BroadcastState.tracklistEnd(tracklistItemID)); + } + // Can't really load a ghost, it'll break setting cues etc. Do nothing. if (item.type === "ghost") { return; diff --git a/src/showplanner/Player.tsx b/src/showplanner/Player.tsx index 543bd0f..03bee9e 100644 --- a/src/showplanner/Player.tsx +++ b/src/showplanner/Player.tsx @@ -16,6 +16,7 @@ import * as ShowPlanState from "../showplanner/state"; import { HHMMTosec, secToHHMM, timestampToHHMM } from "../lib/utils"; import ProModeButtons from "./ProModeButtons"; import { VUMeter } from "../optionsMenu/helpers/VUMeter"; +import * as BroadcastState from "../broadcast/state"; import * as api from "../api"; import { AppThunk } from "../store"; import { @@ -24,6 +25,7 @@ import { PLAYER_COUNT, PLAYER_ID_PREVIEW, } from "../mixer/audio"; +import { useBeforeunload } from "react-beforeunload"; export const USE_REAL_GAIN_VALUE = false; @@ -269,6 +271,15 @@ export function Player({ omit(b, "timeCurrent", "timeRemaining") ) ); + + useBeforeunload((event) => { + console.log("Checking player " + id + " for un-ended tracklists."); + const tracklistItemID = playerState.tracklistItemID; + if (tracklistItemID !== -1) { + dispatch(BroadcastState.tracklistEnd(tracklistItemID)); + } + }); + const settings = useSelector((state: RootState) => state.settings); const customOutput = settings.channelOutputIds[id] !== INTERNAL_OUTPUT_ID; const dispatch = useDispatch();