Implement Queue for Socialwall frontend

This commit is contained in:
Marvin Scholz 2017-05-12 14:04:36 +02:00
parent 429210c5b6
commit 6b31de0620

View file

@ -79,17 +79,36 @@
<div style="clear:both"></div>
<script type="text/javascript">
var exampleSocket = new WebSocket("ws://192.168.2.108:8000/ws");
var queue = [];
var exampleSocket = new WebSocket("ws://Marvins-MacBook-Pro.local:8000/ws");
exampleSocket.onopen = function (event) {
console.log("WS: Connection open!");
console.log("Proto: " + exampleSocket.protocol);
exampleSocket.send("Here's some text that the server is urgently awaiting!");
console.log("WS: Connection open");
};
exampleSocket.onmessage = function (event) {
console.log("WS: Received message");
IT = JSON.parse(event.data);
document.getElementById("snapwall_image").src = IT["Path"];
if (IT["State"] === 1) {
queue.push(IT);
}
console.log(event.data);
}
function displayNewSnap() {
var item = queue.shift();
if (item) {
document.getElementById("snapwall_image").src = item["Path"];
}
}
setInterval(function() {
displayNewSnap();
}, 7000); // 7 seconds
/* TODO: Load initial approved images to be able to show
* something, even when reloading
*/
</script>
<script type="text/javascript">