Add code for video connecting and capturing, as well as some swarm issues.

This commit is contained in:
Michael Pivato
2019-01-27 23:44:03 +10:30
parent a3d04aad3d
commit 48cf938b8a

View File

@@ -1,12 +1,16 @@
//var msgpack = require("msgpack-lite"); //var msgpack = require("msgpack-lite");
// Assuming paho mqtt library is included. // 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 = new Paho.MQTT.Client(host, port=1884, "2343");
client.onMessageArrived = onMessage; client.onMessageArrived = onMessage;
client.onConnectionLost = onConnectionLost; client.onConnectionLost = onConnectionLost;
function connectToSwarmn(){
// Only connect when person is ready.
client.connect({onSuccess: onConnect}); client.connect({onSuccess: onConnect});
}
function onConnect(){ function onConnect(){
alert("Client Connected"); alert("Client Connected");
@@ -26,10 +30,58 @@ function onConnectionLost(responseObject){
} }
function onMessage(message){ function onMessage(message){
alert("message received");
// Working.
messageb = message.payloadBytes; messageb = message.payloadBytes;
var messageD = msgpack.decode(message.payloadBytes)
if(message.payloadBytes = 1){ console.log(messageD)
// Sent checking ready command. if(messageD["type"] == "reqvote"){
console.log("Received vote message");
submit_vote();
} }
} }
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);
});
}
})