Improve queue and websocket address
This commit is contained in:
parent
6e482a2220
commit
b68b824b06
|
@ -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) {
|
exampleSocket.onopen = function (event) {
|
||||||
console.log("WS: Connection open!");
|
console.log("WS: Connection open!");
|
||||||
console.log("Proto: " + exampleSocket.protocol);
|
console.log("Proto: " + exampleSocket.protocol);
|
||||||
|
|
|
@ -104,6 +104,7 @@ function connectWebSocket(url) {
|
||||||
|
|
||||||
webSocket.onmessage = function(event) {
|
webSocket.onmessage = function(event) {
|
||||||
console.log("WebSocket: Received Message");
|
console.log("WebSocket: Received Message");
|
||||||
|
console.log(event.data);
|
||||||
handleMessage(event.data);
|
handleMessage(event.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,11 +136,32 @@ function handleMessage(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function addItem(item) {
|
function addItem(item) {
|
||||||
|
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);
|
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);
|
archive.push(item);
|
||||||
if (archive.length > 5) {
|
if (archive.length > 5) {
|
||||||
archive.shift();
|
archive.shift();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayNewSnap() {
|
function displayNewSnap() {
|
||||||
|
|
Loading…
Reference in a new issue