diff --git a/socialdragon/assets/js/app.js b/socialdragon/assets/js/app.js index 8df8012..f4d4e90 100644 --- a/socialdragon/assets/js/app.js +++ b/socialdragon/assets/js/app.js @@ -87,7 +87,10 @@ var app = new Vue({ } }) -var exampleSocket = new WebSocket("ws://127.0.0.1:8000/ws"); +// Construct websocket url +var loc = window.location; +var ws_url = ((loc.protocol === "https:") ? "wss://" : "ws://") + loc.host + "/ws"; +var exampleSocket = new WebSocket(ws_url); exampleSocket.onopen = function (event) { console.log("WS: Connection open!"); console.log("Proto: " + exampleSocket.protocol); diff --git a/socialdragon/templates/index.html b/socialdragon/templates/index.html index 9d8e970..83a0a8f 100755 --- a/socialdragon/templates/index.html +++ b/socialdragon/templates/index.html @@ -104,6 +104,7 @@ function connectWebSocket(url) { webSocket.onmessage = function(event) { console.log("WebSocket: Received Message"); + console.log(event.data); handleMessage(event.data); } @@ -135,10 +136,31 @@ function handleMessage(message) { } function addItem(item) { - queue.push(item); - archive.push(item); - if (archive.length > 5) { - archive.shift(); + var exists = 0; + for (var i in queue) { + if (queue.hasOwnProperty(i)) { + if (queue[i]["ID"] === item["ID"]) { + exists = 1; + } + } + } + if (exists === 0) { + queue.push(item); + } + + exists = 0; + for (var i in archive) { + if (archive.hasOwnProperty(i)) { + if (archive[i]["ID"] === item["ID"]) { + exists = 1; + } + } + } + if (exists === 0) { + archive.push(item); + if (archive.length > 5) { + archive.shift(); + } } }