desperately trying to fix the player's weirdness

This commit is contained in:
Evert Prants 2019-10-23 17:22:23 +03:00
parent 5d1db70545
commit 4580ac3556
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
1 changed files with 8 additions and 5 deletions

View File

@ -28,6 +28,7 @@ let vidReady = false
let shouldHide = true
let inFullscreen = false
let errored = false
let live = false
let ws
function GET (url, istext) {
@ -81,7 +82,7 @@ function viewersCount (res) {
viewers.innerHTML = res.length + ' watching'
}
function handleWebSocket (live) {
function handleWebSocket () {
if (!live && ws) {
ws.onerror = ws.onopen = ws.onclose = null
ws.close()
@ -89,13 +90,14 @@ function handleWebSocket (live) {
return
}
if (ws) return
if (!live) return
ws = new WebSocket(`ws${location.protocol.indexOf('s') !== -1 ? 's' : ''}://${location.host}`)
ws.onerror = function(e) {
console.error('Socket errored, retrying..', e)
handleWebSocket(false)
setTimeout(() => handleWebSocket(vidReady), 5000)
ws.close()
ws = null
setTimeout(() => handleWebSocket(), 5000)
}
ws.onopen = function() {
@ -116,11 +118,12 @@ function handleWebSocket (live) {
ws.onclose = function() {
console.error('Socket died, retrying..')
ws = null
setTimeout(() => handleWebSocket(vidReady), 5000)
setTimeout(() => handleWebSocket(), 5000)
}
}
function liveStatus (status) {
live = status
if (status) {
lstat.innerHTML = 'live now'
lstat.className = 'badge live'