Fix connection indicator

This commit is contained in:
Yohann D'ANELLO 2020-11-09 16:48:05 +01:00
parent 5ad8a69c4c
commit 28ef6a5526
2 changed files with 9 additions and 8 deletions

View File

@ -52,23 +52,26 @@ export function initViewerPage(stream, viewersCounterRefreshPeriod, posterUrl) {
} }
] ]
}); });
player.on("stateChanged", function (prevstate, newstate) { player.on("stateChanged", function (data) {
if (newstate === "loading") { if (data.newstate === "loading") {
document.getElementById("connectionIndicator").style.fill = '#ffc107' document.getElementById("connectionIndicator").style.fill = '#ffc107'
} }
if (newstate === "ready" || newstate === "play") { if (data.newstate === "playing") {
document.getElementById("connectionIndicator").style.fill = '#28a745' document.getElementById("connectionIndicator").style.fill = '#28a745'
} }
if (data.newstate === "idle") {
document.getElementById("connectionIndicator").style.fill = '#dc3545'
}
}) })
player.on("error", function (error) { player.on("error", function (error) {
document.getElementById("connectionIndicator").style.fill = '#dc3545' document.getElementById("connectionIndicator").style.fill = '#dc3545'
if (error.code === 501 || error.code === 406) { if (error.code === 501 || error.code === 406) {
// Clear messages // Clear messages
const errorMsg = document.getElementsByClassName("op-message-text")[0] const errorMsg = document.getElementsByClassName("op-message-text")[0]
//errorMsg.textContent = "" errorMsg.textContent = ""
const warningIcon = document.getElementsByClassName("op-message-icon")[0] const warningIcon = document.getElementsByClassName("op-message-icon")[0]
//warningIcon.textContent = "" warningIcon.textContent = ""
// Reload in 30s // Reload in 30s
setTimeout(function () { setTimeout(function () {
@ -99,6 +102,4 @@ export function initViewerPage(stream, viewersCounterRefreshPeriod, posterUrl) {
break; break;
} }
}); });
return player;
} }

View File

@ -50,6 +50,6 @@
"{{$value}}", "{{$value}}",
{{end}} {{end}}
] ]
let player = initViewerPage(stream, /*stunServers,*/ viewersCounterRefreshPeriod, {{.Cfg.PlayerPoster}}) initViewerPage(stream, /*stunServers,*/ viewersCounterRefreshPeriod, {{.Cfg.PlayerPoster}})
</script> </script>
{{end}} {{end}}