6 changed files with 89 additions and 80 deletions
@ -1,42 +1,45 @@
@@ -1,42 +1,45 @@
|
||||
var playerRestartTimer; |
||||
|
||||
async function getStatus() { |
||||
const url = "/status"; |
||||
|
||||
try { |
||||
const response = await fetch(url); |
||||
const status = await response.json(); |
||||
|
||||
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(function () { |
||||
restartPlayer(); |
||||
}, 3000); |
||||
// 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); |
||||
} |
||||
|
||||
app.streamStatus = status.online |
||||
? "Stream is online." |
||||
: "Stream is offline." |
||||
|
||||
const player = videojs('video'); |
||||
if (app.isOnline) { |
||||
player.poster('/thumbnail.jpg'); |
||||
} else { |
||||
// Change this to some kind of offline image.
|
||||
player.poster('/img/logo.png'); |
||||
} |
||||
app.streamStatus = status.online ? MESSAGE_ONLINE : MESSAGE_OFFLINE; |
||||
|
||||
app.viewerCount = status.viewerCount; |
||||
app.sessionMaxViewerCount = status.sessionMaxViewerCount; |
||||
app.overallMaxViewerCount = status.overallMaxViewerCount; |
||||
app.isOnline = status.online; |
||||
setVideoPoster(app.isOnline); |
||||
|
||||
} catch (e) { |
||||
app.streamStatus = "Stream server is offline." |
||||
app.viewerCount = 0 |
||||
} |
||||
|
||||
function handleOffline() { |
||||
const player = videojs(VIDEO_ID); |
||||
player.poster(POSTER_DEFAULT); |
||||
app.streamStatus = MESSAGE_OFFLINE; |
||||
app.viewerCount = 0; |
||||
} |
||||
|
||||
function getStatus() { |
||||
const options = { |
||||
// mode: 'no-cors',
|
||||
} |
||||
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(); |
||||
}); |
||||
} |
Loading…
Reference in new issue