diff options
author | José Bollo <jose.bollo@iot.bzh> | 2016-04-19 18:02:11 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2016-04-19 18:02:11 +0200 |
commit | 9e3afb8aa598f3e69e2c3723335507c12b4cd1f1 (patch) | |
tree | 97459a101bd4e3291547a42600c4012caf4d1274 /test/AFB.js | |
parent | 46d9538587a3521caa1e3b20bf337a53ed400777 (diff) |
initial event handler
Change-Id: Idb92d6de9904d050b37ef0a5d664e82573ff640d
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'test/AFB.js')
-rw-r--r-- | test/AFB.js | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/test/AFB.js b/test/AFB.js index 309db472..44b1a908 100644 --- a/test/AFB.js +++ b/test/AFB.js @@ -37,12 +37,14 @@ 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) { this.ws = new WebSocket(urlws, [ PROTO1 ]); this.pendings = {}; + this.awaitens = {}; this.counter = 0; this.ws.onopen = onopen.bind(this); this.ws.onerror = onerror.bind(this); @@ -90,6 +92,10 @@ var AFB_websocket; delete this.pendings[id]; } switch (code) { + case EVENT: + var a = this.awaitens[id]; + if (a) + a.forEach(function(handler){handler(ans);}); case RETOK: pend && pend.onsuccess && pend.onsuccess(ans, this); break; @@ -112,9 +118,16 @@ var AFB_websocket; this.ws.send(JSON.stringify(arr)); } + function onevent(api, name, handler) { + var id = api+"/"+name; + var list = this.awaitens[id] || (this.awaitens[id] = []); + list.push(handler); + } + AFB_websocket.prototype = { close: close, - call: call + call: call, + onevent: onevent }; } /*********************************************/ |