From 4580ac35568f93f85b97106ea2c0a8f42c62faab Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Wed, 23 Oct 2019 17:22:23 +0300 Subject: [PATCH] desperately trying to fix the player's weirdness --- src/player.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/player.js b/src/player.js index 9ffd071..7867212 100644 --- a/src/player.js +++ b/src/player.js @@ -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'