diff options
Diffstat (limited to 'priv/static/js/widget.js')
-rw-r--r-- | priv/static/js/widget.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/priv/static/js/widget.js b/priv/static/js/widget.js index e69de29..e1a5603 100644 --- a/priv/static/js/widget.js +++ b/priv/static/js/widget.js @@ -0,0 +1,57 @@ +window.onload=function() { + + soundManager.setup({ + url: "/swf/", + preferFlash: false, + onready: function() { + window.soundPlayer = soundManager.createSound({ + id: 'radio', + url: 'http://91.121.59.45:8089/stream', + stream: true, + autoPlay: false, + usePolicyFile: true, + preferFlash: false, + autoStart: false + }) + + var playButton = document.getElementById("state"); + playButton.onclick = function() { + if (window.playerPlaying) { + console.log("should stop") + window.soundPlayer.stop(); + window.playerPlaying = false; + playButton.innerHTML = "▶"; + } else { + console.log("should start"); + window.soundPlayer.start(); + window.playerPlaying = true; + playButton.innerHTML = "⏸"; + } + } + + }, + ontimeout: function() { + console.log("soundmanager timeout") + } +}); + +window.evtSource = new EventSource("/api/icecast.sse"); +window.icecastStats = {}; +window.evtSource.addEventListener('icecast', function(e) { + var data = JSON.parse(e.data).icecast; + document.getElementById("np").innerHTML = data.np; + document.getElementById("genre").innerHTML = data.genre + " <span>en direct</span>"; + + player = document.getElementById("player"); + if (data.live != window.icecastStats.live) { + if (data.live) { + player.classList = ["live"]; + console.log("is live"); + } else { + player.classList = ["autodj"]; + console.log("stopped live"); + } + } + window.icecastStats = data; +}, false); +} |