-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.html
102 lines (95 loc) · 3.99 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<head>
<script src="https://cdn.bootcdn.net/ajax/libs/hls.js/1.2.1/hls.js"></script>
</head>
<body>
<video controls></video>
<script>
(async function () {
window.VideoTogetherEasyShareMemberSite = true;
const m3u8Url = decodeURIComponent(window.location.hash.substring(1));
setInterval(() => {
if (m3u8Url != decodeURIComponent(window.location.hash.substring(1))) {
window.location.reload();
}
}, 1000)
let playerHtml = await (await fetch('./superplayer.html?x=' + Date.now())).text();
console.log(btoa(playerHtml));
let iframe = document.createElement("iframe");
iframe.style.display = 'none'
iframe.src = "data:text/html;base64," + btoa(playerHtml);
document.body.appendChild(iframe);
// this can be hack, but I think the hack can do nothing in this page
// SEO AD?
// playerHtml = playerHtml.replace('M3U8_URL', m3u8Url.replace(/'/g, ""));
const hlsVideo = document.querySelector("video");
const blobCache = {}
window.blobCache = blobCache;
window.addEventListener("message", e => {
if (e.data.method == "fetchResponse") {
blobCache[e.data.url] = e.data.blob;
}
})
async function superFetch(url) {
return new Promise(async (res, rej) => {
try {
let blob = await (await fetch(url)).blob();
blobCache[url] = blob;
res(blob);
} catch (e) { }
let id;
try {
iframe.contentWindow.postMessage({
method: "fetch",
url: url
}, '*');
id = setInterval(() => {
if (blobCache[url] != undefined) {
res(blobCache[url]);
console.log("id", id);
clearInterval(id);
}
}, 200);
} catch (e) { }
setTimeout(() => {
rej(null);
clearInterval(id);
}, 5000);
});
}
if (Hls.isSupported()) {
var hls = new Hls({
pLoader: class CustomLoader extends Hls.DefaultConfig.loader {
load(context, config, callbacks) {
console.log(context);
super.load(context, config, callbacks);
}
},
fLoader: class CustomFLoader extends Hls.DefaultConfig.loader {
async load(context, config, callbacks) {
try {
let url = await videoTogetherExtension.FetchRemoteRealUrl(context.frag.baseurl, context.frag.sn, context.url);
context.url = URL.createObjectURL(await superFetch(url));
console.log("remote url", url);
} catch (e) { console.error(e, "FetchRemoteRealUrl") }
super.load(context, config, callbacks);
}
},
autoStartLoad: true,
});
hls.on(Hls.Events.ERROR, function (errMes) {
console.error(errMes);
});
hls.attachMedia(hlsVideo);
hls.on(Hls.Events.MEDIA_ATTACHED, function () {
hls.loadSource(m3u8Url);
})
hlsVideo.load();
}
})()
</script>
<style>
video {
width: 100%;
}
</style>
</body>