aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-04-19 18:02:11 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2016-04-19 18:02:11 +0200
commit9e3afb8aa598f3e69e2c3723335507c12b4cd1f1 (patch)
tree97459a101bd4e3291547a42600c4012caf4d1274 /test
parent46d9538587a3521caa1e3b20bf337a53ed400777 (diff)
initial event handler
Change-Id: Idb92d6de9904d050b37ef0a5d664e82573ff640d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'test')
-rw-r--r--test/AFB.js15
-rw-r--r--test/hello-world.html1
2 files changed, 15 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
};
}
/*********************************************/
diff --git a/test/hello-world.html b/test/hello-world.html
index 67464ff5..f8e0f54a 100644
--- a/test/hello-world.html
+++ b/test/hello-world.html
@@ -9,5 +9,6 @@
<li><a href="api/hello/pingnull">ping null</a>
<li><a href="api/hello/pingbug">ping bug</a>
<li><a href="api/hello/pingJson?toto&tata&titi=u">ping json</a>
+ <li><a href="api/hello/pingevent?toto&tata&titi=u">ping event</a>
<li><a href="api/hello/none">not a verb</a>
<li><a href="api/none/none">not an api</a>