Mercurial > hg > thermostat-ng > web-gateway
view services/commands/src/main/resources/agent.html @ 252:1428b14f642f
[commands] Implement Keycloak support.
Reviewed-by: jkang
Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-September/024853.html
author | Severin Gehwolf <sgehwolf@redhat.com> |
---|---|
date | Tue, 05 Sep 2017 16:29:38 +0200 |
parents | 2d924d7904a7 |
children | 51841a9b5f81 |
line wrap: on
line source
<?xml version="1.0" encoding="UTF-8"?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Thermostat Commands Agent (HTML Receiver)</title> <style type="text/css"><![CDATA[ input#cmd-chan { width: 410px } #console-container { width: 400px; } #console { border: 1px solid #CCCCCC; border-right-color: #999999; border-bottom-color: #999999; height: 170px; overflow-y: scroll; padding: 5px; width: 100%; } #console p { padding: 0; margin: 0; } ]]></style> <script type="application/javascript"> //<![CDATA[ var CmdChan = {}; var Response = {}; Response.asJson = (function(sequence, resp) { var r = {}; r.type = 100; r.sequence = sequence; r.payload = {}; r.payload.respType = resp; return JSON.stringify(r); }); var Msg = {}; Msg.fromRequest = (function(rawMsg) { var jsonObj = JSON.parse(rawMsg); Msg.sequence = jsonObj.sequence; Msg.payload = jsonObj.payload; }); CmdChan.socket = null; CmdChan.getTokenParam = (function(variable) { var query = window.location.search.substring(1); var vars = query.split("&"); for (var i=0;i<vars.length;i++) { var pair = vars[i].split("="); if (pair[0] == variable) { return pair[1]; } } return null; }); CmdChan.connect = (function(host) { if ('WebSocket' in window) { CmdChan.socket = new WebSocket(host); } else if ('MozWebSocket' in window) { CmdChan.socket = new MozWebSocket(host); } else { Console.log('Error: WebSocket is not supported by this browser.'); return; } CmdChan.socket.onopen = function () { Console.log('Info: WebSocket connection opened.'); }; CmdChan.socket.onclose = function () { Console.log('Info: WebSocket closed.'); }; CmdChan.socket.onmessage = function (message) { var data = JSON.parse(message.data); var payload = data.payload; var requestArguments = {} for (var key in payload) { // Check for an actual key, and not a prototype value if (payload.hasOwnProperty(key)) { requestArguments[escapeHtml(key)] = escapeHtml(payload[key]); } } // Print message to screen data.payload = requestArguments; Console.log('Got: ' + JSON.stringify(data)); // parse message Msg.fromRequest(message.data); // send the always-ok reply CmdChan.socket.send(Response.asJson(Msg.sequence, 'OK')); Console.log('Info: OK reply sent.'); }; }); CmdChan.initialize = function() { var query_string = ""; var token = CmdChan.getTokenParam("access_token"); if (token != null) { query_string = "?access_token=" + token; } if (window.location.protocol == 'http:') { CmdChan.connect('ws://' + window.location.host + '/commands/v1/systems/ignored_system/agents/testAgent' + query_string); } else { CmdChan.connect('wss://' + window.location.host + '/commands/v1/systems/ignored_system/agents/testAgent' + query_string); } }; var Console = {}; Console.log = (function(message) { var console = document.getElementById('console'); var p = document.createElement('p'); p.style.wordWrap = 'break-word'; p.innerHTML = message; console.appendChild(p); while (console.childNodes.length > 25) { console.removeChild(console.firstChild); } console.scrollTop = console.scrollHeight; }); CmdChan.initialize(); document.addEventListener("DOMContentLoaded", function() { // Remove elements with "noscript" class - <noscript> is not allowed in XHTML var noscripts = document.getElementsByClassName("noscript"); for (var i = 0; i < noscripts.length; i++) { noscripts[i].parentNode.removeChild(noscripts[i]); } }, false); var escapeHtml = function(unsafeStr) { return unsafeStr.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"); } //]]> </script> </head> <body> <div class="noscript"><h2 style="color: #ff0000">Seems your browser doesn't support Javascript! Websockets rely on Javascript being enabled. Please enable Javascript and reload this page!</h2></div> <div> <p> Thermostat Commands: Agent Receiver </p> <div id="console-container"> <div id="console"/> </div> </div> </body> </html>