Skip to content

Commit

Permalink
Fix: flv/m3u8 cors
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Oct 7, 2023
1 parent 96f6cfb commit 981c834
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/components/Player.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,21 @@ watch(
const playFlv = (player: HTMLMediaElement, url: string, art: any) => {
if (mpegts.isSupported()) {
const flv = mpegts.createPlayer(
{ type: "flv", url },
{
headers: {
Authorization: url.startsWith(window.location.origin) ? localStorage.token : ""
let flv: mpegts.Player
if (url.startsWith(window.location.origin) && localStorage.token) {
flv = mpegts.createPlayer(
{ type: "flv", url },
{
headers: {
Authorization: localStorage.token
}
}
}
);
);
} else {
flv = mpegts.createPlayer(
{ type: "flv", url }
);
}
flv.attachMediaElement(player);
flv.load();
Expand Down Expand Up @@ -132,7 +139,9 @@ const playM2ts = (player: HTMLMediaElement, url: string, art: any) => {
const playM3u8Config = {
xhrSetup: function (xhr: XMLHttpRequest, url: string): void | Promise<void> {
// xhr.open("GET", url, true);
xhr.setRequestHeader('Authorization', url.startsWith(window.location.origin) ? localStorage.token : "");
if (url.startsWith(window.location.origin) && localStorage.token) {
xhr.setRequestHeader('Authorization', localStorage.token);
}
},
};
Expand Down

0 comments on commit 981c834

Please sign in to comment.