michael@0: /*jslint unparam: true */ michael@0: michael@0: /* jshint strict: true, -W097, unused:false */ michael@0: /*global window, document, d3, $, io, navigator, setTimeout */ michael@0: michael@0: //Set the size of the Notifier Circle michael@0: $("#notifier_circle").width(0.8 * window.innerWidth); michael@0: $("#notifier_circle").height(0.8 * window.innerWidth); michael@0: michael@0: michael@0: /* michael@0: Function: validateIP() michael@0: Parameter: none michael@0: Description: Attempt to connect to server/Intel IoT platform michael@0: */ michael@0: function validateIP() { michael@0: 'use strict'; michael@0: var socket, michael@0: //Get values from text fields michael@0: ip_addr = $("#ip_address").val(), michael@0: port = $("#port").val(), michael@0: script = document.createElement("script"); michael@0: michael@0: //create script tag for socket.io.js file located on your IoT platform (development board) michael@0: script.setAttribute("src", "http://" + ip_addr + ":" + port + "/socket.io/socket.io.js"); michael@0: document.head.appendChild(script); michael@0: michael@0: //Wait 1 second before connecting michael@0: setTimeout(function () { michael@0: try { michael@0: //Connect to Server michael@0: socket = io.connect("http://" + ip_addr + ":" + port); michael@0: michael@0: //Attach a 'connected' event handler to the socket michael@0: socket.on("connected", function (message) { michael@0: navigator.notification.alert( michael@0: 'Welcome', // message michael@0: "", // callback michael@0: 'Hi There!', // title michael@0: 'Ok' // buttonName michael@0: ); michael@0: }); michael@0: michael@0: //Set all Back button to not show michael@0: $.ui.showBackButton = false; michael@0: //Load page with transition michael@0: $.ui.loadContent("#main", false, false, "fade"); michael@0: michael@0: socket.on("message", function (message) { michael@0: //alert("Is anyone there? "+message); michael@0: if (message === "present") { michael@0: $("#notifier_circle").attr("class", "green"); michael@0: //Update log michael@0: $("#feedback_log").append(Date().substr(0, 21) + " Someone is Present!
"); michael@0: //Prompt user with Cordova notification alert michael@0: navigator.notification.alert( michael@0: 'Someone is Present!', // message michael@0: "", // callback michael@0: 'Check Your Door', // title michael@0: 'Ok' // buttonName michael@0: ); michael@0: //Wait 2 seconds then turn back to gray michael@0: setTimeout(function () { michael@0: $("#notifier_circle").attr("class", "gray"); michael@0: }, 3000); michael@0: } michael@0: }); michael@0: } catch (e) { michael@0: navigator.notification.alert( michael@0: "Server Not Available!", // message michael@0: "", // callback michael@0: 'Connection Error!', // title michael@0: 'Ok' // buttonName michael@0: ); michael@0: } michael@0: }, 1000); michael@0: }