Kiwano API Sample Code Javascript

(Open console, F12 or Ctrl-Shift-I, to see more details... )


Connect to API:

Sample call to Kiwano API:



Get a proxy:
$.ajax({    url :  "http://getproxy.hybridearth.net",
            dataType: 'jsonp',
            success: function(data){ proxyurl = data.url; }          });                


Connecting to Kiwano API websocket:
    wsuri = proxyurl+"/?urlid=http%3A%2F%2Fhybridearth.net%2Fu%2Fanonymous&iid=1382712527819&lat=47.213782&lng=-1.542338";
    if      ("WebSocket" in window)    { connection = new WebSocket(wsuri);     }
    else if ("MozWebSocket" in window) { connection = new MozWebSocket(wsuri);  }
    else { console.log("Browser does not support WebSocket!");   return false;  }
    
    connection.onopen = function(){      console.log('Connection open');    };    
    connection.onclose = function(){     console.log('Connection closed');    };
    connection.onerror = function(err){  console.log('Error detected:', err);    };
    connection.onmessage = function(e){  console.log("notification from kiwano:",e.data);     };