diff options
author | Ruben Pollan <meskio@sindominio.net> | 2016-08-04 19:04:09 +0200 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2016-09-01 01:41:16 -0400 |
commit | 50a258d45e851a865801da9d888037b5869a3489 (patch) | |
tree | 39a797a6ffa7b0d90037ce0497621c96e90dcb2f /src/leap/bitmask/core/web/index.html | |
parent | 720ac7cab46f57971c71d2d2aec8235a47a53582 (diff) |
[feat] add web/js core API
Implements http REST API for the core and bitmask.js generic library to
use this API. For events it uses long polling.
- Resolves: #8265
Diffstat (limited to 'src/leap/bitmask/core/web/index.html')
-rw-r--r-- | src/leap/bitmask/core/web/index.html | 73 |
1 files changed, 33 insertions, 40 deletions
diff --git a/src/leap/bitmask/core/web/index.html b/src/leap/bitmask/core/web/index.html index 9490eca8..6ac9b29e 100644 --- a/src/leap/bitmask/core/web/index.html +++ b/src/leap/bitmask/core/web/index.html @@ -2,53 +2,44 @@ <html> <head> <title>Bitmask WebSockets Endpoint</title> + <script src="bitmask.js"></script> <script type="text/javascript"> - var sock = null; var ellog = null; window.onload = function() { - ellog = document.getElementById('log'); - var wsuri; - if (window.location.protocol === "file:") { - wsuri = "ws://127.0.0.1:8080/ws"; - } else { - wsuri = "ws://" + window.location.hostname + ":8080/bitmask"; - } - - if ("WebSocket" in window) { - sock = new WebSocket(wsuri); - } else if ("MozWebSocket" in window) { - sock = new MozWebSocket(wsuri); - } else { - log("Browser does not support WebSocket!"); - window.location = "http://autobahn.ws/unsupportedbrowser"; - } - - if (sock) { - sock.onopen = function() { - log("Connected to " + wsuri); - } - - sock.onclose = function(e) { - log("Connection closed (wasClean = " + e.wasClean + ", code = " + e.code + ", reason = '" + e.reason + "')"); - sock = null; - } + bitmask.events.register("KEYMANAGER_KEY_FOUND", event_handler); + }; - sock.onmessage = function(e) { - log("[res] " + e.data + '\n'); - } - } + function login() { + var email = document.getElementById('email').value; + var password = document.getElementById('password').value; + bitmask.user.auth(email, password).then(function(response) { + log("We are logged in: "); + for (k in response) { + log(" " + k + ": " + response[k]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); }; - function send() { - var msg = document.getElementById('message').value; - if (sock) { - sock.send(msg); - log("[cmd] " + msg); - } else { - log("Not connected."); + function logout() { + bitmask.user.logout().then(function(response) { + log("We are logged out: "); + for (k in response) { + log(" " + k + ": " + response[k]); + } + }, function(error) { + log("Some error ocurred: " + error); + }); + }; + + function event_handler(evnt, content) { + log("Event: " + evnt); + for (i in content) { + log(" " + content[i]); } }; @@ -62,9 +53,11 @@ <h1>Bitmask Control Panel</h1> <noscript>You must enable JavaScript</noscript> <form> - <p>Command: <input id="message" type="text" size="50" maxlength="50" value="status"></p> + <p>Email address: <input id="email" type="text" size="50" maxlength="50" value="user@mail.bitmask.net"></p> + <p>Password: <input id="password" type="password" size="50" maxlength="50" ></p> </form> - <button onclick='send();'>Send Command</button> + <button onclick='login();'>Log In</button> + <button onclick='logout();'>Log Out</button> <pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre> </body> </html> |