diff --git a/src/background/ad.replacement.ts b/src/background/ad.replacement.ts index 4fc945b..866cb78 100644 --- a/src/background/ad.replacement.ts +++ b/src/background/ad.replacement.ts @@ -30,7 +30,7 @@ export async function onAdPod(stitchedAd: TwitchStitchedAdData, stream: string) } } - eventHandler.emitContext('updateUrl',{url: await createM3U8Url({stream, usher: usherData})}); + eventHandler.emitContext('updateUrl',{url: await createM3U8Url({stream, usher: usherData}), stream}); } async function createM3U8Url({usher, stream}: {usher: any, stream: string}) { diff --git a/src/context/context-script.ts b/src/context/context-script.ts index 941dfc1..b452f4b 100644 --- a/src/context/context-script.ts +++ b/src/context/context-script.ts @@ -11,10 +11,20 @@ const eventHandler = new ContextEventHandler(); window.addEventListener('playing', () => initWorkerHandler(lazyConnector), true); const throttledReset = throttle(() => resetPlayer(lazyConnector), 5 * 1000); -eventHandler.on('updateUrl', ({url}) => { +eventHandler.on('updateUrl', ({url, stream}) => { const core = getPlayer(lazyConnector)?.props?.mediaPlayerInstance?.core; if(!core) return; + const path = core.getPath(); + if(url === path) return; // same url + + const user = path.match(/\/channel\/hls\/([^.]+).m3u8/)?.[1]; + if(!user) { + console.warn('Attempted to reload but got a bad path:', path); + return; + } + if(user !== stream) return; // other stream -- invalid + core.load(url, ''); signalPlayer('blue'); }); diff --git a/src/context/twitch-player.types.ts b/src/context/twitch-player.types.ts index 916a3ed..72058d5 100644 --- a/src/context/twitch-player.types.ts +++ b/src/context/twitch-player.types.ts @@ -28,6 +28,7 @@ export interface MediaPlayerCore { getVolume(): number; isMuted(): boolean; load(url: string, any: any): void; + getPath(): string; } export interface MediaSinkManager { diff --git a/src/types.ts b/src/types.ts index 1739f45..428a874 100644 --- a/src/types.ts +++ b/src/types.ts @@ -19,7 +19,7 @@ export type MessageMap = { // adPod: AdPod; localStorage: Record; reloadPlayer: {}; - updateUrl: {url: string}; + updateUrl: {url: string, stream: string}; clientId: string; adSkipped: {}; }