X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=test%2FAFB.js;h=8fccdb04e8fd863f27f704a6fe324e6ff615a56b;hb=fe9601cbf6bbebe9464bfbde2efd0ec278b3e243;hp=59e68abcbdd78660902f488c4ce2e5e150626c42;hpb=e0ee638f2fed216a0b1b0d497d586917c805816e;p=src%2Fapp-framework-binder.git diff --git a/test/AFB.js b/test/AFB.js index 59e68abc..8fccdb04 100644 --- a/test/AFB.js +++ b/test/AFB.js @@ -1,5 +1,5 @@ /* - * Copyright (C) 2017 "IoT.bzh" + * Copyright (C) 2017, 2018 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -21,7 +21,7 @@ if (typeof base != "object") var initial = { base: base.base || "api", - token: base.token || initialtoken || "hello", + token: base.token || initialtoken || "HELLO", host: base.host || window.location.host, url: base.url || undefined }; @@ -105,8 +105,7 @@ var AFB_websocket; function onclose(event) { for (var id in this.pendings) { - var ferr = this.pendings[id].onerror; - ferr && ferr(null, this); + try { this.pendings[id][1](); } catch (x) {/*TODO?*/} } this.pendings = {}; this.onclose && this.onclose(); @@ -131,8 +130,7 @@ var AFB_websocket; if (id in pendings) { var p = pendings[id]; delete pendings[id]; - var f = p[offset]; - f(ans); + try { p[offset](ans); } catch (x) {/*TODO?*/} } } @@ -166,12 +164,18 @@ var AFB_websocket; this.onabort = function(){}; } - function call(method, request) { + function call(method, request, callid) { return new Promise((function(resolve, reject){ var id, arr; - do { - id = String(this.counter = 4095 & (this.counter + 1)); - } while (id in this.pendings); + if (callid) { + id = String(callid); + if (id in this.pendings) + throw new Error("pending callid("+id+") exists"); + } else { + 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);