"use strict";function popuplateApiList(){var a=0;$("#api_list").append($("<option />").val(a++).html("Custom request"));for(var b=1;b<apiList.length;b++){var c=JSON.parse(apiList[b]).msg;$("#api_list").append($("<option />").val(a++).html(c))}$("#api_list").change(function(){var a=$("#api_list option:selected").val(),b=apiList[parseInt(a)];$("#message").val(JSON.stringify(JSON.parse(b),null,"    "))}),$("#api_list").change()}function addLog(a,b){b=void 0!==b&&b;var c=loginfos.length,d=$("<p></p>");loginfos.push(a),$(".log").append(d),"connected"==a.type?(d.append($('<span class="glyphicon glyphicon-ok">')),d.append("Connected")):"disconnected"==a.type?(d.append($('<span class="glyphicon glyphicon-remove">')),d.append("Disconnected")):"error"==a.type?(d.append($('<span class="glyphicon glyphicon-remove-sign">')),d.append(a.type)):b?(d.append($('<span class="glyphicon glyphicon-export">')),""==a.type?d.append('Empty "msg"'):d.append(a.type)):(d.append($('<span class="glyphicon glyphicon-import">')),""==a.type?d.append('Empty "msg"'):d.append(a.type)),$(".badge").html(loginfos.length),d.on("click",function(){var a,b=loginfos[c];try{a=JSON.stringify(JSON.parse(b.json),null,"    ")}catch(c){a=b.json}$("#answer").html(a),$("pre code").each(function(a,b){hljs.highlightBlock(b)})})}function clearLog(){loginfos=[],$(".log").html(""),$(".badge").html("0")}var apiList=['{"msg": ""}','{"msg": "param_set", "data": {"flash_screen": false, "keyboard_layout": 155,"knock_enabled": false, "knock_sensitivity": 1,"lock_timeout": 0,"lock_timeout_enabled": false,"offline_mode": false,"screen_brightness": 51, "screensaver": false,"tutorial_enabled": false,"user_interaction_timeout": 0,"user_request_cancel": false}}','{ "msg": "start_memorymgmt" }','{ "msg": "exit_memorymgmt" }','{"msg": "get_credential", "data": {"service": "sub.example.com", "fallback_service": "example.com", "login": "user@example.com", "request_id": "123"}}','{"msg": "set_credential", "data": {"service": "example.com", "login": "user@example.com", "password": "pwd", "description": "added by API"}}','{"msg": "get_random_numbers"}','{"msg": "cancel_request", "data": {"request_id": "123"}}','{"msg": "get_data_node", "data": {"service": "data example", "fallback_service": "data example2", "request_id": "123"}}','{"msg": "set_data_node", "data": {"service": "data example", "request_id": "123", "node_data": "<base64_encoded_data>"}}','{"msg": "show_app"}','{"msg": "start_memcheck"}','{"msg": "get_application_id"}','{"msg": "credential_exists", "data": {"service": "example.com"}}','{"msg": "data_node_exists", "data": {"service": "data example"}}'],ws=new Object,loginfos=[];$(document).ready(function(){popuplateApiList(),$("#btdisconnect").on("click",function(){ws.close()}),$("#btsend").on("click",function(){var a=$("#message").val();if(!("readyState"in ws&&ws.readyState==ws.OPEN))return console.log("sending error"),void addLog({type:"error",msg_id:"",json:"Websocket connection closed"});ws.send(a);var b=JSON.parse(a),c="",d="UNKNOWN!!";b.hasOwnProperty("msg_id")&&(c=b.msg_id),b.hasOwnProperty("msg")&&(d=b.msg),addLog({type:d,msg_id:c,json:a},!0)}),$("#btclear").on("click",function(){clearLog()}),$("#btconnect").on("click",function(){ws=new WebSocket($("#urlinput").val()),ws.onopen=function(a){$("#status_con").removeClass("label-danger"),$("#status_con").addClass("label-success"),$("#status_con").html("Connected"),addLog({type:"connected",msg_id:"",json:"OPEN"})},ws.onclose=function(a){$("#status_con").removeClass("label-success"),$("#status_con").addClass("label-danger"),$("#status_con").html("Disconnected"),addLog({type:"disconnected",msg_id:"",json:"CLOSED"})},ws.onmessage=function(a){console.log(a.data);var b=JSON.parse(a.data),c="",d="UNKNOWN!!";b.hasOwnProperty("msg_id")&&(c=b.msg_id),b.hasOwnProperty("msg")&&(d=b.msg),addLog({type:d,msg_id:c,json:a.data})},ws.onerror=function(a){$("#status_con").removeClass("label-success"),$("#status_con").addClass("label-danger"),$("#status_con").html("Disconnected"),addLog({type:"error",msg_id:"",json:a.data})}})});