diff options
Diffstat (limited to 'll-auth-binding/htdocs')
-rw-r--r-- | ll-auth-binding/htdocs/AFB-websock.js | 174 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/CMakeLists.txt | 43 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/IdentityBinding.js | 88 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/IdentityBinding2.js | 96 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/auth.html | 38 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/auth2.html | 27 | ||||
-rw-r--r-- | ll-auth-binding/htdocs/index.html | 12 |
7 files changed, 0 insertions, 478 deletions
diff --git a/ll-auth-binding/htdocs/AFB-websock.js b/ll-auth-binding/htdocs/AFB-websock.js deleted file mode 100644 index 08a7ffe..0000000 --- a/ll-auth-binding/htdocs/AFB-websock.js +++ /dev/null @@ -1,174 +0,0 @@ -AFB = function(base, initialtoken){ - -var urlws = "ws://"+window.location.host+"/"+base; -var urlhttp = "http://"+window.location.host+"/"+base; - -/*********************************************/ -/**** ****/ -/**** AFB_context ****/ -/**** ****/ -/*********************************************/ -var AFB_context; -{ - var UUID = undefined; - var TOKEN = initialtoken; - - var context = function(token, uuid) { - this.token = token; - this.uuid = uuid; - } - - context.prototype = { - get token() {return TOKEN;}, - set token(tok) {if(tok) TOKEN=tok;}, - get uuid() {return UUID;}, - set uuid(id) {if(id) UUID=id;} - }; - - AFB_context = new context(); -} -/*********************************************/ -/**** ****/ -/**** AFB_websocket ****/ -/**** ****/ -/*********************************************/ -var AFB_websocket; -{ - var CALL = 2; - var RETOK = 3; - var RETERR = 4; - var EVENT = 5; - - var PROTO1 = "x-afb-ws-json1"; - - AFB_websocket = function(onopen, onabort) { - var u = urlws; - if (AFB_context.token) { - u = u + '?x-afb-token=' + AFB_context.token; - if (AFB_context.uuid) - u = u + '&x-afb-uuid=' + AFB_context.uuid; - } - this.ws = new WebSocket(u, [ PROTO1 ]); - this.pendings = {}; - this.awaitens = {}; - this.counter = 0; - this.ws.onopen = onopen.bind(this); - this.ws.onerror = onerror.bind(this); - this.ws.onclose = onclose.bind(this); - this.ws.onmessage = onmessage.bind(this); - this.onopen = onopen; - this.onabort = onabort; - this.onclose = onabort; - } - - function onerror(event) { - var f = this.onabort; - if (f) { - delete this.onopen; - delete this.onabort; - f && f(this); - } - this.onerror && this.onerror(this); - } - - function onopen(event) { - var f = this.onopen; - delete this.onopen; - delete this.onabort; - f && f(this); - } - - function onclose(event) { - for (var id in this.pendings) { - var ferr = this.pendings[id].onerror; - ferr && ferr(null, this); - } - this.pendings = {}; - this.onclose && this.onclose(); - } - - function fire(awaitens, name, data) { - var a = awaitens[name]; - if (a) - a.forEach(function(handler){handler(data);}); - var i = name.indexOf("/"); - if (i >= 0) { - a = awaitens[name.substring(0,i)]; - if (a) - a.forEach(function(handler){handler(data);}); - } - a = awaitens["*"]; - if (a) - a.forEach(function(handler){handler(data);}); - } - - function reply(pendings, id, ans, offset) { - if (id in pendings) { - var p = pendings[id]; - delete pendings[id]; - var f = p[offset]; - f(ans); - } - } - - function onmessage(event) { - var obj = JSON.parse(event.data); - var code = obj[0]; - var id = obj[1]; - var ans = obj[2]; - AFB_context.token = obj[3]; - switch (code) { - case RETOK: - reply(this.pendings, id, ans, 0); - break; - case RETERR: - reply(this.pendings, id, ans, 1); - break; - case EVENT: - default: - fire(this.awaitens, id, ans); - break; - } - } - - function close() { - this.ws.close(); - this.onabort(); - } - - function call(method, request) { - return new Promise((function(resolve, reject){ - var id, arr; - do { - id = String(this.counter = 4095 & (this.counter + 1)); - } while (id in this.pendings); - this.pendings[id] = [ resolve, reject ]; - arr = [CALL, id, method, request ]; - if (AFB_context.token) arr.push(AFB_context.token); - this.ws.send(JSON.stringify(arr)); - }).bind(this)); - } - - function onevent(name, handler) { - var id = name; - var list = this.awaitens[id] || (this.awaitens[id] = []); - list.push(handler); - } - - AFB_websocket.prototype = { - close: close, - call: call, - onevent: onevent - }; -} -/*********************************************/ -/**** ****/ -/**** ****/ -/**** ****/ -/*********************************************/ -return { - context: AFB_context, - ws: AFB_websocket -}; -}; - diff --git a/ll-auth-binding/htdocs/CMakeLists.txt b/ll-auth-binding/htdocs/CMakeLists.txt deleted file mode 100644 index 5bdb47f..0000000 --- a/ll-auth-binding/htdocs/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -########################################################################### -# Copyright 2015, 2016, 2017 IoT.bzh -# -# author: Fulup Ar Foll <fulup@iot.bzh> -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -########################################################################### - - - -################################################## -# HTML Testing Files -################################################## -PROJECT_TARGET_ADD(www_test) - - file(GLOB SOURCE_FILES "*.html" "*.js" "*.jpg") - - add_custom_target(${TARGET_NAME} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ) - - add_custom_command( - DEPENDS ${SOURCE_FILES} - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - COMMAND mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - COMMAND cp -r ${SOURCE_FILES} ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ) - - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - LABELS "HTDOCS" - OUTPUT_NAME ${TARGET_NAME} - ) diff --git a/ll-auth-binding/htdocs/IdentityBinding.js b/ll-auth-binding/htdocs/IdentityBinding.js deleted file mode 100644 index 4d0d98f..0000000 --- a/ll-auth-binding/htdocs/IdentityBinding.js +++ /dev/null @@ -1,88 +0,0 @@ - var afb = new AFB("api", "mysecret"); - var ws; - var evtidx=0; - - function getParameterByName(name, url) { - if (!url) { - url = window.location.href; - } - name = name.replace(/[\[\]]/g, "\\$&"); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); - } - - // default soundcard is "PCH" - var devid=getParameterByName("devid"); - if (!devid) devid="hw:0"; - - var sndname=getParameterByName("sndname"); - if (!sndname) sndname="PCH"; - - var quiet=getParameterByName("quiet"); - if (!quiet) quiet="99"; - - function init() { - ws = new afb.ws(onopen, onabort); - } - - function onopen() { - document.getElementById("main").style.visibility = "visible"; - document.getElementById("connected").innerHTML = "Binder WS Active"; - document.getElementById("connected").style.background = "lightgreen"; - ws.onevent("*", gotevent); - } - - function onabort() { - document.getElementById("main").style.visibility = "hidden"; - document.getElementById("connected").innerHTML = "Connected Closed"; - document.getElementById("connected").style.background = "red"; - - } - - function replyok(obj) { - console.log("replyok:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj); - } - - function replyerr(obj) { - console.log("replyerr:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj); - } - - function gotevent(obj) { - console.log("gotevent:" + JSON.stringify(obj)); - document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj); - - document.getElementById("message").innerHTML = ""; - - if (obj.event == "ll-auth/login") { - document.getElementById("userid").innerHTML = obj.data.user; - document.getElementById("device").innerHTML = obj.data.device; - } - - if (obj.event == "ll-auth/logout") { - document.getElementById("userid").innerHTML = ""; - document.getElementById("device").innerHTML = ""; - } - - if (obj.event == "ll-auth/failed") { - document.getElementById("message").innerHTML = obj.data.message; - } - } - - function send(message) { - var api = document.getElementById("api").value; - var verb = document.getElementById("verb").value; - document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")"; - ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr); - } - - - function callbinder(api, verb, query) { - console.log ("subscribe api="+api+" verb="+verb+" query=" +query); - document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")"; - ws.call(api+"/"+verb, query).then(replyok, replyerr); - } diff --git a/ll-auth-binding/htdocs/IdentityBinding2.js b/ll-auth-binding/htdocs/IdentityBinding2.js deleted file mode 100644 index 695b872..0000000 --- a/ll-auth-binding/htdocs/IdentityBinding2.js +++ /dev/null @@ -1,96 +0,0 @@ - var afb = new AFB("api", "mysecret"); - var ws; - var evtidx=0; - - function getParameterByName(name, url) { - if (!url) { - url = window.location.href; - } - name = name.replace(/[\[\]]/g, "\\$&"); - var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), - results = regex.exec(url); - if (!results) return null; - if (!results[2]) return ''; - return decodeURIComponent(results[2].replace(/\+/g, " ")); - } - - // default soundcard is "PCH" - var devid=getParameterByName("devid"); - if (!devid) devid="hw:0"; - - var sndname=getParameterByName("sndname"); - if (!sndname) sndname="PCH"; - - var quiet=getParameterByName("quiet"); - if (!quiet) quiet="99"; - - function init() { - ws = new afb.ws(onopen, onabort); - } - - function onopen() { - document.getElementById("background").style.background = "lightgray"; - document.getElementById("main").style.visibility = "visible"; - callbinder("ll-auth", "getuser", ""); - ws.onevent("*", gotevent); - } - - function onabort() { - document.getElementById("background").style.background = "IndianRed"; - } - - function replyok(obj) { - console.log("replyok:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj); - - document.getElementById("usertitle").innerHTML = "A valid user is logged in"; - document.getElementById("userid").innerHTML = obj.response.user; - document.getElementById("userdevice").innerHTML = obj.response.device; - document.getElementById("background").style.background = "lightgreen"; - } - - function replyerr(obj) { - console.log("replyerr:" + JSON.stringify(obj)); - document.getElementById("output").innerHTML = "ERROR: "+JSON.stringify(obj); - } - - function gotevent(obj) { - console.log("gotevent:" + JSON.stringify(obj)); - document.getElementById("outevt").innerHTML = (evtidx++) +": "+JSON.stringify(obj); - - document.getElementById("question").innerHTML = ""; - document.getElementById("output").innerHTML = ""; - document.getElementById("message").innerHTML = ""; - - if (obj.event == "ll-auth/login") { - document.getElementById("usertitle").innerHTML = "A valid user is logged in"; - document.getElementById("userid").innerHTML = obj.data.user; - document.getElementById("userdevice").innerHTML = obj.data.device; - document.getElementById("background").style.background = "lightgreen"; - } - - if (obj.event == "ll-auth/logout") { - document.getElementById("usertitle").innerHTML = "No user"; - document.getElementById("userid").innerHTML = ""; - document.getElementById("userdevice").innerHTML = ""; - document.getElementById("background").style.background = "lightgray"; - } - - if (obj.event == "ll-auth/failed") { - document.getElementById("message").innerHTML = obj.data.message; - } - } - - function send(message) { - var api = document.getElementById("api").value; - var verb = document.getElementById("verb").value; - document.getElementById("question").innerHTML = "subscribe: "+api+"/"+verb + " (" + JSON.stringify(message) +")"; - ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr); - } - - - function callbinder(api, verb, query) { - console.log ("subscribe api="+api+" verb="+verb+" query=" +query); - document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")"; - ws.call(api+"/"+verb, query).then(replyok, replyerr); - } diff --git a/ll-auth-binding/htdocs/auth.html b/ll-auth-binding/htdocs/auth.html deleted file mode 100644 index ac48ff9..0000000 --- a/ll-auth-binding/htdocs/auth.html +++ /dev/null @@ -1,38 +0,0 @@ -<html> - <head> - <title>ll-auth-binding test</title> - <script type="text/javascript" src="AFB-websock.js"></script> - <script type="text/javascript" src="IdentityBinding.js"></script> - </head> - - <body onload="init();"> - <h1>Identity Binding</h1> - <button id="connected" onclick="init()">Binder WS Fail</button> - <br> - <ol> - <!-- - <li><button onclick="callbinder('ll-auth','login', {})">login</button></li> - <li><button onclick="callbinder('ll-auth','logout', {})">logout</button></li> - --> - <li><button onclick="callbinder('ll-auth','getuser', {})">get user</button></li> - </ol> - <br> - <div> - </div> - <h2>User:</h2> - <ol> - <li>id: <span id="userid"></span></li> - <li>device: <span id="device"></span></li> - </ol> - <div id="message" style="color:red;"></div> - <br/> - <div id="main" style="visibility:hidden"> - <h2>Debug: </h2> - <ol> - <li>Question <div id="question"></div></li> - <li>Response <div id="output"></div></li> - <li>Events: <div id="outevt"></div></li> - </ol> - </div> - </body> -</html> diff --git a/ll-auth-binding/htdocs/auth2.html b/ll-auth-binding/htdocs/auth2.html deleted file mode 100644 index 356be1c..0000000 --- a/ll-auth-binding/htdocs/auth2.html +++ /dev/null @@ -1,27 +0,0 @@ -<html> - <head> - <title>ll-auth-binding test</title> - <script type="text/javascript" src="AFB-websock.js"></script> - <script type="text/javascript" src="IdentityBinding2.js"></script> - </head> - - <body onload="init();" id="background"> - <!--<button onclick="init()">Refresh</button>--> - <div> - <h1 id="usertitle">No user</h1> - <ul> - <li>User Id : <span id="userid"></span></li> - <li>Device : <span id="userdevice"></span></li> - </ul> - </div> - <div id="message" style="color:red;"></div> - <div id="main" style="visibility:hidden"> - <h2>Debug: </h2> - <ol> - <li>Question <div id="question"></div></li> - <li>Response <div id="output"></div></li> - <li>Events: <div id="outevt"></div></li> - </ol> - </div> - </body> -</html> diff --git a/ll-auth-binding/htdocs/index.html b/ll-auth-binding/htdocs/index.html deleted file mode 100644 index 1c90ae5..0000000 --- a/ll-auth-binding/htdocs/index.html +++ /dev/null @@ -1,12 +0,0 @@ -<html> - <head> - <title>Identity Binding tests</title> - </head> - <body> - <h1>Identity Binding tests</h1> - <ol> - <li><a href="auth.html">Auth</a></li> - <li><a href="auth2.html">Auth2</a></li> - </ol> - </body> -</html> |