livestream/static/js/script.js

35 lines
913 B
JavaScript
Raw Normal View History

2023-06-13 00:07:14 +03:00
const WebsocketMessageTypeViewers = 0;
const WebsocketMessageTypeCurrentlyPlaying = 1;
2024-02-24 16:54:27 +02:00
let stream = videojs('livestream');
2023-06-13 00:07:14 +03:00
let wsurl = "";
if (location.protocol === 'https:') {
wsurl = "wss://" + window.location.host + "/ws"
} else {
wsurl = "ws://" + window.location.host + "/ws"
}
let websocket = new WebSocket(wsurl)
websocket.onmessage = (event) => {
let data = JSON.parse(event.data)
switch (data.type) {
case WebsocketMessageTypeViewers:
viewers.innerText = data.message;
break
case WebsocketMessageTypeCurrentlyPlaying:
currently_playing.innerText = data.message
2024-02-24 16:54:27 +02:00
2024-02-24 18:23:07 +02:00
stream.one('error', function() {
2024-02-24 16:54:27 +02:00
stream.src({ type: 'application/dash+xml', src: '/media/stream.mpd' });
2024-02-24 18:23:07 +02:00
stream.play();
console.log("trying again")
})
2024-02-24 16:54:27 +02:00
2023-06-13 00:07:14 +03:00
break
}
};
2024-02-24 16:54:27 +02:00
feather.replace()