Touchgui/www/js/main.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     1 /*jslint unparam: true */
     3 /* jshint strict: true, -W097, unused:false  */
     4 /*global window, document, d3, $, io, navigator, setTimeout */
     6 //Set the size of the Notifier Circle
     7 $("#notifier_circle").width(0.8 * window.innerWidth);
     8 $("#notifier_circle").height(0.8 * window.innerWidth);
    11 /*
    12 Function: validateIP()
    13 Parameter: none
    14 Description: Attempt to connect to server/Intel IoT platform
    15 */
    16 function validateIP() {
    17     'use strict';
    18     var socket,
    19     //Get values from text fields
    20         ip_addr = $("#ip_address").val(),
    21         port = $("#port").val(),
    22         script = document.createElement("script");
    24     //create script tag for socket.io.js file located on your IoT platform (development board)
    25     script.setAttribute("src", "http://" + ip_addr + ":" + port + "/socket.io/socket.io.js");
    26     document.head.appendChild(script);
    28     //Wait 1 second before connecting
    29     setTimeout(function () {
    30         try {
    31             //Connect to Server
    32             socket = io.connect("http://" + ip_addr + ":" + port);
    34             //Attach a 'connected' event handler to the socket
    35             socket.on("connected", function (message) {
    36                 navigator.notification.alert(
    37                     'Welcome',  // message
    38                     "",                     // callback
    39                     'Hi There!',            // title
    40                     'Ok'                  // buttonName
    41                 );
    42             });
    44             //Set all Back button to not show
    45             $.ui.showBackButton = false;
    46             //Load page with transition
    47             $.ui.loadContent("#main", false, false, "fade");
    49             socket.on("message", function (message) {
    50                 //alert("Is anyone there? "+message);
    51                 if (message === "present") {
    52                     $("#notifier_circle").attr("class", "green");
    53                     //Update log
    54                     $("#feedback_log").append(Date().substr(0, 21) + " Someone is Present!<br>");
    55                     //Prompt user with Cordova notification alert
    56                     navigator.notification.alert(
    57                         'Someone is Present!',  // message
    58                         "",                     // callback
    59                         'Check Your Door',            // title
    60                         'Ok'                  // buttonName
    61                     );
    62                     //Wait 2 seconds then turn back to gray
    63                     setTimeout(function () {
    64                         $("#notifier_circle").attr("class", "gray");
    65                     }, 3000);
    66                 }
    67             });
    68         } catch (e) {
    69             navigator.notification.alert(
    70                 "Server Not Available!",  // message
    71                 "",                     // callback
    72                 'Connection Error!',            // title
    73                 'Ok'                  // buttonName
    74             );
    75         }
    76     }, 1000);
    77 }

mercurial