diff --git a/index.html b/index.html
index 003b436..99e5222 100644
--- a/index.html
+++ b/index.html
@@ -34,10 +34,7 @@ var player = document.getElementById('player');
var rng = Math.floor(Math.random() * 10000);
player.src = player.src + '?nocache=' + rng;
-var url = 'wss://radio.anarchyplanet.org/ws';
-var ws = new WebSocket(url);
-
-ws.onmessage = function(msg){
+function update(msg) {
document.title = msg.data + " - APR";
var hist = document.getElementById("history");
@@ -47,8 +44,33 @@ ws.onmessage = function(msg){
if(hist.childElementCount >= 10) {
hist.removeChild(hist.lastChild);
}
+};
+
+function connect() {
+ console.log('connecting');
+
+ var url = 'wss://radio.anarchyplanet.org/ws';
+ var ws = new WebSocket(url);
+
+ ws.onmessage = function(e) {
+ update(e);
+ };
+
+ ws.onclose = function(e) {
+ setTimeout(connect, 1000);
+ };
+
+ ws.onerror = function(e) {
+ ws.close();
+ };
+
+ console.log(ws);
}
+
+connect();
+
+