forked from thehig/arconai-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.ejs
91 lines (79 loc) · 2.91 KB
/
stream.ejs
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><%- name %> - Arconai Stream</title>
<style>
.video-container {
display: none;
}
</style>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-142410619-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-142410619-1');
</script>
<%- referenceScripts %>
</head>
<body>
<noscript>This page requires Javascript</noscript>
<div>
<h3>You should be redirected to <em><%- name %></em> in a moment</h3>
<div id="targetUrl" />
</div>
<div class="video-container">
<video id="stream_player" class="stream-player video-js vjs-default-skin vjs-16-9 vjs-big-play-centered" autoplay
controls preload="none" width="640" height="264">
<source id="stream_player_src" src="" type="application/x-mpegURL">
</video>
<%- inlineScripts %>
</div>
<script>
(function (doc) {
var count = 0, maxCount = 100, interval = 300,
targetDiv = document.getElementById("targetUrl"),
newAnchorTag = document.createElement('a')
stopRedirecting = !!document.getElementById("source-href");
// *Try* not to rerun the reload trigger if the user has back-nav'd to this page
// this gives the user a chance to either A) click the link or B) copy the URL
if (stopRedirecting) return;
searchForSource = setInterval(function () {
if (stopRedirecting) return;
try {
if (++count > maxCount) {
clearInterval(searchForSource);
alert('Unable to locate stream source within ~' + (maxCount * interval / 1000) + ' seconds');
return;
}
// Get the videojs player
if (!videojs || !videojs.getAllPlayers) return;
let players = videojs.getAllPlayers();
if (!players || players.length === 0) return;
let player = players[0];
// Get the cache source
let source = player.cache_.src;
if (!source) return;
// At this point we have the source, so stop looping
clearInterval(searchForSource);
setTimeout(function () {
if (stopRedirecting) return;
// Add the newAnchorTag to the DOM with the source URL
// https://stackoverflow.com/questions/42320019/creating-anchor-tags-dynamically-in-html-using-javascript
newAnchorTag.innerText = source;
newAnchorTag.id = "source-href"
newAnchorTag.setAttribute('href', source);
targetDiv.appendChild(newAnchorTag);
console.log('Redirecting to', source);
window.open(source);
}, 750);
} catch (e) {
// no-op
}
}, interval);
})(this);
</script>
</body>
</html>