summaryrefslogtreecommitdiff
path: root/priv/static/js/widget.js
diff options
context:
space:
mode:
authorhref <href@random.sh>2018-02-02 21:35:46 +0100
committerhref <href@random.sh>2018-02-02 21:35:46 +0100
commitc98ddad3263f6859af3c5c76fa197876743d5ded (patch)
tree9e20617da1089e918e0445162dc9bd8eb54f3459 /priv/static/js/widget.js
parentimport (diff)
sse / embedded player
Diffstat (limited to '')
-rw-r--r--priv/static/js/widget.js57
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 + "&nbsp;<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);
+}