Skip to content

Commit

Permalink
Merge pull request #3 from Nerixyz/reloading-bug
Browse files Browse the repository at this point in the history
Fix Reloading Bug
  • Loading branch information
Nerixyz authored Apr 2, 2021
2 parents f1ca82f + 6281a71 commit 009f640
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/background/ad.replacement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}) {
Expand Down
12 changes: 11 additions & 1 deletion src/context/context-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ const eventHandler = new ContextEventHandler<MessageMap>();
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');
});
Expand Down
1 change: 1 addition & 0 deletions src/context/twitch-player.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export interface MediaPlayerCore {
getVolume(): number;
isMuted(): boolean;
load(url: string, any: any): void;
getPath(): string;
}

export interface MediaSinkManager {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export type MessageMap = {
// adPod: AdPod;
localStorage: Record<string, string | number | boolean>;
reloadPlayer: {};
updateUrl: {url: string};
updateUrl: {url: string, stream: string};
clientId: string;
adSkipped: {};
}
Expand Down

0 comments on commit 009f640

Please sign in to comment.