Also route hls audio tracks through extension

This commit is contained in:
Jorrin 2024-03-31 20:20:10 +02:00
parent a5694fa430
commit 6a905bf517
2 changed files with 16 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import { ExtensionMakeRequestResponse } from "@/backend/extension/plasmo";
export const RULE_IDS = {
PREPARE_STREAM: 1,
SET_DOMAINS_HLS: 2,
SET_DOMAINS_HLS_AUDIO: 3,
};
// for some reason, about 500 ms is needed after

View File

@ -191,6 +191,21 @@ export function makeVideoElementDisplayInterface(): DisplayInterface {
},
});
});
hls.on(Hls.Events.AUDIO_TRACK_LOADED, async (_, data) => {
const chunkUrlsDomains = data.details.fragments.map(
(v) => new URL(v.url).hostname,
);
const chunkUrls = [...new Set(chunkUrlsDomains)];
await setDomainRule({
ruleId: RULE_IDS.SET_DOMAINS_HLS_AUDIO,
targetDomains: chunkUrls,
requestHeaders: {
...src.preferredHeaders,
...src.headers,
},
});
});
}
});
hls.on(Hls.Events.LEVEL_SWITCHED, () => {