summaryrefslogtreecommitdiff
path: root/ui/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/lib')
-rw-r--r--ui/app/lib/bitmask.js36
-rw-r--r--ui/app/lib/event_logger.js2
2 files changed, 26 insertions, 12 deletions
diff --git a/ui/app/lib/bitmask.js b/ui/app/lib/bitmask.js
index 1fdce433..9d772242 100644
--- a/ui/app/lib/bitmask.js
+++ b/ui/app/lib/bitmask.js
@@ -90,10 +90,12 @@ var bitmask = function(){
if (api_token) {
call(['events', 'poll']).then(function(response) {
if (response !== null) {
- var evnt = response[0];
+ var event = response[0];
var content = response[1];
- if (evnt in event_handlers) {
- event_handlers[evnt](evnt, content);
+ if (event in event_handlers) {
+ Object.values(event_handlers[event]).forEach(function(handler) {
+ handler(event, content);
+ })
}
}
event_polling();
@@ -401,24 +403,36 @@ var bitmask = function(){
/**
* Register func for an event
*
- * @param {string} evnt The event to register
+ * @param {string} event The event to register
+ * @param {string} name The unique name for the callback
* @param {function} func The function that will be called on each event.
* It has to be like: function(event, content) {}
* Where content will be a list of strings.
*/
- register: function(evnt, func) {
- event_handlers[evnt] = func;
- return call(['events', 'register', evnt])
+ register: function(event, name, func) {
+ event_handlers[event] = event_handlers[event] || {}
+ if (event_handlers[event][name]) {
+ return null;
+ } else {
+ event_handlers[event][name] = func;
+ return call(['events', 'register', event])
+ }
},
/**
* Unregister from an event
*
- * @param {string} evnt The event to unregister
+ * @param {string} event The event to unregister
+ * @param {string} name The unique name of the callback to remove
*/
- unregister: function(evnt) {
- delete event_handlers[evnt];
- return call(['events', 'unregister', evnt])
+ unregister: function(event, name) {
+ event_handlers[event] = event_handlers[event] || {}
+ delete event_handlers[event][name]
+ if (Object.keys(event_handlers[event]).length == 0) {
+ return call(['events', 'unregister', event]);
+ } else {
+ return null;
+ }
}
}
};
diff --git a/ui/app/lib/event_logger.js b/ui/app/lib/event_logger.js
index fac1a510..283d2434 100644
--- a/ui/app/lib/event_logger.js
+++ b/ui/app/lib/event_logger.js
@@ -59,7 +59,7 @@ export default class EventLogger {
this.logEvent = this.logEvent.bind(this)
for (let event of EVENTS) {
console.log('register event ' + event)
- bitmask.events.register(event, this.logEvent)
+ bitmask.events.register(event, 'logger ' + event, this.logEvent)
}
}
logEvent(event, msg) {