-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 1.14 KB
/
index.js
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
var host = window.location.host;
const urlParams = new URLSearchParams(window.location.search);
const socket = new WebSocket(`wss://${host}/msg`);
socket.addEventListener('open', function (event) {
var hostReq = { Host: urlParams.get('key') };
socket.send(JSON.stringify(hostReq));
document.getElementById("status").innerHTML = "Connected."
});
document.getElementById("play-button").addEventListener('click', function () {
var vtt = document.getElementById("vtt-url").value;
if (vtt == "") {
vtt = null;
}
var playReq = { Play: [
document.getElementById("stream-url").value,
vtt,
document.getElementById("seek-str").value,
Number(document.getElementById("offset-secs").value)
]};
socket.send(JSON.stringify(playReq));
});
document.getElementById("pause-button").addEventListener('click', function () {
var pauseReq = "Pause";
socket.send(JSON.stringify(pauseReq));
});
socket.addEventListener('close', (event) => {
document.getElementById("status").innerHTML =
"⚠️ Connection closed. Refresh page?"
});
setInterval(function() { socket.send("ping") }, 5000 );