2020-06-19 06:46:00 +03:00
|
|
|
var playerRestartTimer;
|
|
|
|
|
2020-06-18 02:35:47 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
function handleStatus(status) {
|
|
|
|
clearTimeout(playerRestartTimer);
|
|
|
|
if (!app.isOnline && status.online) {
|
|
|
|
// The stream was offline, but now it's online. Force start of playback after an arbitrary delay to make sure the stream has actual data ready to go.
|
|
|
|
playerRestartTimer = setTimeout(restartPlayer, 3000);
|
|
|
|
}
|
2020-06-19 06:46:00 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
app.streamStatus = status.online ? MESSAGE_ONLINE : MESSAGE_OFFLINE;
|
2020-06-18 02:35:47 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
app.viewerCount = status.viewerCount;
|
|
|
|
app.sessionMaxViewerCount = status.sessionMaxViewerCount;
|
|
|
|
app.overallMaxViewerCount = status.overallMaxViewerCount;
|
|
|
|
app.isOnline = status.online;
|
|
|
|
setVideoPoster(app.isOnline);
|
2020-06-18 02:35:47 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
}
|
2020-06-26 07:56:43 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
function handleOffline() {
|
|
|
|
const player = videojs(VIDEO_ID);
|
|
|
|
player.poster(POSTER_DEFAULT);
|
|
|
|
app.streamStatus = MESSAGE_OFFLINE;
|
|
|
|
app.viewerCount = 0;
|
|
|
|
}
|
2020-06-18 02:35:47 +03:00
|
|
|
|
2020-07-05 11:08:22 +03:00
|
|
|
function getStatus() {
|
|
|
|
const options = {
|
|
|
|
// mode: 'no-cors',
|
2020-06-18 02:35:47 +03:00
|
|
|
}
|
2020-07-05 11:08:22 +03:00
|
|
|
fetch(URL_STATUS, options)
|
|
|
|
.then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error(`Network response was not ok ${response.ok}`);
|
|
|
|
}
|
|
|
|
return response.json();
|
|
|
|
})
|
|
|
|
.then(json => {
|
|
|
|
handleStatus(json);
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
handleOffline();
|
|
|
|
});
|
|
|
|
}
|