diff options
Diffstat (limited to 'client/js')
-rw-r--r-- | client/js/radio_emulator.js | 62 |
1 files changed, 34 insertions, 28 deletions
diff --git a/client/js/radio_emulator.js b/client/js/radio_emulator.js index 17691d2..ae78258 100644 --- a/client/js/radio_emulator.js +++ b/client/js/radio_emulator.js @@ -165,24 +165,24 @@ function stopHereAndReflect() function loadShowCallback(json, params) { - const [ list, now_on_sequence, element, hash_of_list ] = params; + const [ list, now_on_sequence, listItem, hash_of_list ] = params; debugLog('loadShowCallback'); debugLog(json); - debugLog(element); + debugLog(listItem); //debugLog(params); - placeholders.currentShowHash.innerText = element.hash; + placeholders.currentShowHash.innerText = listItem.hash; placeholders.artist.innerText = json.artist; placeholders.title.innerText = json.title; setTitleMessage ( "▶️ " + json.artist + " - " + json.title ); debugLog('----------'); - placeholders.showDuration.forEach((elem)=>{elem.innerText = Math.floor(element.duration/1000)}); - placeholders.startsOn.innerText = element.starts_on; - placeholders.playProgress.max = Math.floor(element.duration/1000); + placeholders.showDuration.forEach((element)=>{element.innerText = Math.floor(listItem.duration/1000)}); + placeholders.startsOn.innerText = listItem.starts_on; + placeholders.playProgress.max = Math.floor(listItem.duration/1000); placeholders.showInfo.innerText = JSON.stringify(json, null, 2); audioElement.load(); FetchAudio(`${audioRequest}${json.hash}`, sync_radio); audioElement.type = json.mimetype; - placeholders.currentTime.innerText = Math.floor((now_on_sequence - element.starts_on)/1000); + placeholders.currentTime.innerText = Math.floor((values.now_on_sequence - listItem.starts_on)/1000); audioElement.addEventListener('ended', function(){ placeholders.currentTime.value = 0; FetchJSON(`${listRequest}`, hashCallback, [ new Date().getTime() ]); @@ -234,70 +234,76 @@ function sync_radio() return 0; } +var values = { + delta_time: 0, + min_times_played: 0, + maxTimesPlayed: 0, + Dt: 0, + now_on_sequence: 0 +} + function listCallback(json, params) { debugLog('listCallback'); debugLog(json); debugLog(params); var [ now, hash_of_list ] = params; - var delta_time = now - json.started_on; - var min_times_played = Math.floor( delta_time / json.duration ); - var max_times_to_be_played = delta_time / json.duration; - var Dt = max_times_to_be_played - min_times_played; - var now_on_sequence = Dt * json.duration; + values.delta_time = now - json.started_on; + values.min_times_played = Math.floor( values.delta_time / json.duration ); + values.max_times_to_be_played = values.delta_time / json.duration; + values.Dt = values.max_times_to_be_played - values.min_times_played; + values.now_on_sequence = values.Dt * json.duration; placeholders.listStarted.innerText = json.started_on; placeholders.listHash.innerText = hash_of_list; - placeholders.deltaTime.innerText = delta_time; - placeholders.dt.innerText = Dt; - placeholders.currentTime.innerText = now_on_sequence; + placeholders.deltaTime.innerText = values.delta_time; + placeholders.dt.innerText = values.Dt; + placeholders.currentTime.innerText = values.now_on_sequence; placeholders.listDuration.innerText = json.duration; - placeholders.minTimesPlayed.innerText = min_times_played; - placeholders.maxTimesPlayed.innerText = max_times_to_be_played; + placeholders.minTimesPlayed.innerText = values.min_times_played; + placeholders.maxTimesPlayed.innerText = values.max_times_to_be_played; placeholders.listInfo.innerText = JSON.stringify(json, null, 2); - debugLog(`now_on_sequence: ${now_on_sequence}, Dt: ${Dt}`) + debugLog(`now_on_sequence: ${values.now_on_sequence}, Dt: ${values.Dt}`) previous = { starts_on: -1 }; if ( json.list.length === 1 ) { - FetchJSON(`${jsonRequest}${json.list[0].hash}`, loadShowCallback, [json, now_on_sequence, json.list[0], hash_of_list]); + FetchJSON(`${jsonRequest}${json.list[0].hash}`, loadShowCallback, [json, values.now_on_sequence, json.list[0], hash_of_list]); } else { for ( var i = 0; i < json.list.length - 1; i++) { debugLog("getting there") - if ( now_on_sequence > json.list[i].starts_on && now_on_sequence < json.list[i+1].starts_on ) + if ( values.now_on_sequence > json.list[i].starts_on && values.now_on_sequence < json.list[i+1].starts_on ) { if( i !== 0) { var tmp = document.createElement('pre'); tmp.innerText = JSON.stringify(json.list[i-1], null, 2); - tmp.style = "overflow-x: auto;"; placeholders.previouslyPlayed.append(tmp); } - now_on_sequence = now_on_sequence - json.list[i].starts_on; - debugLog(`now_on_sequence (1updated): ${now_on_sequence}`); - FetchJSON(`${jsonRequest}${json.list[i].hash}`, loadShowCallback, [json, now_on_sequence, json.list[i], hash_of_list]); + values.now_on_sequence = values.now_on_sequence - json.list[i].starts_on; + debugLog(`now_on_sequence (1updated): ${values.now_on_sequence}`); + FetchJSON(`${jsonRequest}${json.list[i].hash}`, loadShowCallback, [json, values.now_on_sequence, json.list[i], hash_of_list]); debugLog('First!'); break; } - else if ( now_on_sequence > json.list[i].starts_on && now_on_sequence > json.list[i+1].starts_on ) + else if ( values.now_on_sequence > json.list[i].starts_on && values.now_on_sequence > json.list[i+1].starts_on ) { i++; if( i !== 0) { var tmp = document.createElement('pre'); tmp.innerText = JSON.stringify(json.list[i-1], null, 2); - tmp.style = "overflow-x: auto;"; placeholders.previouslyPlayed.append(tmp); } //now_on_sequence = now_on_sequence - json.list[i].starts_on; - FetchJSON(`${jsonRequest}${json.list[i].hash}`, loadShowCallback, [json, now_on_sequence, json.list[i], hash_of_list]); + FetchJSON(`${jsonRequest}${json.list[i].hash}`, loadShowCallback, [json, values.now_on_sequence, json.list[i], hash_of_list]); debugLog('Second!'); break; } else { - debugLog(now_on_sequence); + debugLog(values.now_on_sequence); debugLog(json.list[i].starts_on); debugLog(json.list[i-1].starts_on); debugLog('Nothing!'); |