From 48cf938b8a0a049bc437d43382d072633a04bd81 Mon Sep 17 00:00:00 2001 From: Michael Pivato Date: Sun, 27 Jan 2019 23:44:03 +1030 Subject: [PATCH] Add code for video connecting and capturing, as well as some swarm issues. --- Web/js/areyousatisfied.js | 66 ++++++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/Web/js/areyousatisfied.js b/Web/js/areyousatisfied.js index 2916eed..6ad0e7d 100644 --- a/Web/js/areyousatisfied.js +++ b/Web/js/areyousatisfied.js @@ -1,12 +1,16 @@ //var msgpack = require("msgpack-lite"); // Assuming paho mqtt library is included. -host = "172.16.13.128"; +host = "172.16.13.130"; client = new Paho.MQTT.Client(host, port=1884, "2343"); client.onMessageArrived = onMessage; client.onConnectionLost = onConnectionLost; -client.connect({onSuccess: onConnect}); + +function connectToSwarmn(){ + // Only connect when person is ready. + client.connect({onSuccess: onConnect}); +} function onConnect(){ alert("Client Connected"); @@ -26,10 +30,58 @@ function onConnectionLost(responseObject){ } function onMessage(message){ + alert("message received"); + // Working. messageb = message.payloadBytes; - - if(message.payloadBytes = 1){ - // Sent checking ready command. - + var messageD = msgpack.decode(message.payloadBytes) + console.log(messageD) + if(messageD["type"] == "reqvote"){ + console.log("Received vote message"); + submit_vote(); } -} \ No newline at end of file +} + +function send_connect(){ + var buffer = msgpack.encode({"type":"connect", "sender":client.clientId, "data":{}}); + message = new Paho.MQTT.Message(buffer); + message.destinationName = "Demo"; + + client.publish(message); +} + +function submit_vote(){ + // Capture the image. + // Perform recognition on the image. + // Send vote back to commander. +} + +function capture_image(){ + +} + +(function(){ + var height=320; + var width=0; + var streaming=false; + + var video = null; + var canvas = null; + var photo = null; + var startbutton = null; + + function startUp(){ + video = document.getElementById('video'); + canvas = document.getElementById('canvas'); + photo = document.getElementById('photo'); + startbutton = document.getElementById('startbutton'); + + navigator.mediaDevices.getUserMedia({ video: true, audio: false }) + .then(function(stream) { + video.srcObject = stream; + video.play(); + }) + .catch(function(err) { + console.log("An error occurred! " + err); + }); + } +}) \ No newline at end of file