diff options
author | elijah <elijah@riseup.net> | 2017-04-24 00:53:41 -0700 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2017-04-24 11:12:26 +0200 |
commit | 9d301349ab434dc744546918fe026d50485a0797 (patch) | |
tree | 802bec24bb446c9ed3af11f7ccfcd9793250b070 /ui/app/lib | |
parent | 2976cf11e451f1086d98eae20bdfb0fffa87abb0 (diff) |
[feat] usable vpn ui
Diffstat (limited to 'ui/app/lib')
-rw-r--r-- | ui/app/lib/bitmask.js | 36 | ||||
-rw-r--r-- | ui/app/lib/event_logger.js | 2 |
2 files changed, 26 insertions, 12 deletions
diff --git a/ui/app/lib/bitmask.js b/ui/app/lib/bitmask.js index 1fdce43..9d77224 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 fac1a51..283d243 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) { |