From c2e54a0d7edae670cb772c08d7c0b98b13c1b0fc Mon Sep 17 00:00:00 2001 From: knalli Date: Sun, 14 Dec 2014 22:28:54 +0100 Subject: [PATCH] Release 0.10.0 --- CHANGELOG.md | 12 + dist/angular-vertxbus.js | 869 ++++++++++---------- dist/angular-vertxbus.min.js | 2 +- dist/requirejs/angular-vertxbus.js | 1206 +++++++++++++++------------- 4 files changed, 1099 insertions(+), 990 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc3fb7..ec5145c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ + +## 0.10.0 (2014-12-14) + +No functional modifications. + +* update internal dependencies and tooling (CoffeeScript 1.8) +* improve debugging using more fn.displayName + +#### Package + +* provide support range AngularJS 1.2 - 1.3 + ## v0.9.0 (2014-11-23) diff --git a/dist/angular-vertxbus.js b/dist/angular-vertxbus.js index 25a0ffe..78200fb 100644 --- a/dist/angular-vertxbus.js +++ b/dist/angular-vertxbus.js @@ -1,9 +1,12 @@ -/*! angular-vertxbus - v0.9.0 - 2014-11-23 +/*! angular-vertxbus - v0.10.0 - 2014-12-14 * http://github.com/knalli/angular-vertxbus * Copyright (c) 2014 ; Licensed */ -(function () { +(function() { var __hasProp = {}.hasOwnProperty; + angular.module('knalli.angular-vertxbus', ['ng']); + + /* An AngularJS wrapper for projects using the VertX Event Bus @@ -16,8 +19,9 @@ * sockjsStateInterval (default 10000 ms): defines the check interval of the underlayling SockJS connection * sockjsReconnectInterval (default 10000 ms): defines the wait time for a reconnect after a disconnect has been recognized * sockjsOptions (default {}): optional SockJS options (new SockJS(url, undefined, options)) - */ - angular.module('knalli.angular-vertxbus').provider('vertxEventBus', function () { + */ + + angular.module('knalli.angular-vertxbus').provider('vertxEventBus', function() { var CONSTANTS, DEFAULT_OPTIONS, options; CONSTANTS = { MODULE: 'angular-vertxbus', @@ -27,7 +31,7 @@ enabled: true, debugEnabled: false, prefix: 'vertx-eventbus.', - urlServer: '' + location.protocol + '//' + location.hostname + ':' + (location.port || 80), + urlServer: "" + location.protocol + "//" + location.hostname + ":" + (location.port || 80), urlPath: '/eventbus', reconnectEnabled: true, sockjsStateInterval: 10000, @@ -36,76 +40,87 @@ messageBuffer: 0 }; options = angular.extend({}, DEFAULT_OPTIONS); - this.enable = function (value) { + this.enable = function(value) { if (value == null) { value = DEFAULT_OPTIONS.enabled; } options.enabled = value === true; return this; }; - this.useDebug = function (value) { + this.enable.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.enable"; + this.useDebug = function(value) { if (value == null) { value = DEFAULT_OPTIONS.debugEnabled; } options.debugEnabled = value === true; return this; }; - this.usePrefix = function (value) { + this.useDebug.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useDebug"; + this.usePrefix = function(value) { if (value == null) { value = DEFAULT_OPTIONS.prefix; } options.prefix = value; return this; }; - this.useUrlServer = function (value) { + this.usePrefix.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.usePrefix"; + this.useUrlServer = function(value) { if (value == null) { value = DEFAULT_OPTIONS.urlServer; } options.urlServer = value; return this; }; - this.useUrlPath = function (value) { + this.useUrlServer.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useUrlServer"; + this.useUrlPath = function(value) { if (value == null) { value = DEFAULT_OPTIONS.urlPath; } options.urlPath = value; return this; }; - this.useReconnect = function (value) { + this.useUrlPath.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useUrlPath"; + this.useReconnect = function(value) { if (value == null) { value = DEFAULT_OPTIONS.reconnectEnabled; } options.reconnectEnabled = value; return this; }; - this.useSockJsStateInterval = function (value) { + this.useReconnect.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useReconnect"; + this.useSockJsStateInterval = function(value) { if (value == null) { value = DEFAULT_OPTIONS.sockjsStateInterval; } options.sockjsStateInterval = value; return this; }; - this.useSockJsReconnectInterval = function (value) { + this.useSockJsStateInterval.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsStateInterval"; + this.useSockJsReconnectInterval = function(value) { if (value == null) { value = DEFAULT_OPTIONS.sockjsReconnectInterval; } options.sockjsReconnectInterval = value; return this; }; - this.useSockJsOptions = function (value) { + this.useSockJsReconnectInterval.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsReconnectInterval"; + this.useSockJsOptions = function(value) { if (value == null) { value = DEFAULT_OPTIONS.sockjsOptions; } options.sockjsOptions = value; return this; }; - this.useMessageBuffer = function (value) { + this.useSockJsOptions.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsOptions"; + this.useMessageBuffer = function(value) { if (value == null) { value = DEFAULT_OPTIONS.messageBuffer; } options.messageBuffer = value; return this; }; + this.useMessageBuffer.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useMessageBuffer"; + /* A stub representing the VertX Event Bus (core functionality) @@ -123,99 +138,101 @@ Furthermore, the stub supports theses extra APIs: - recconnect() - */ - this.$get = [ - '$timeout', - function ($timeout) { - var EventBus_, connect, debugEnabled, enabled, eventBus, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, stub, url, urlPath, urlServer, _ref; - _ref = angular.extend({}, DEFAULT_OPTIONS, options), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions; - stub = null; - EventBus_ = typeof vertx !== 'undefined' && vertx !== null ? vertx.EventBus : void 0; - if (enabled && EventBus_) { - url = '' + urlServer + urlPath; - if (debugEnabled) { - console.debug('[VertX EventBus] Enabled: connecting \'' + url + '\''); - } - eventBus = null; - connect = function () { - eventBus = new EventBus_(url, void 0, sockjsOptions); - eventBus.onopen = function () { - if (debugEnabled) { - console.debug('[VertX EventBus] Connected'); - } - if (typeof stub.onopen === 'function') { - stub.onopen(); - } - }; - eventBus.onclose = function () { - if (debugEnabled) { - console.debug('[VertX EventBus] Reconnect in ' + sockjsReconnectInterval + 'ms'); - } - if (typeof stub.onclose === 'function') { - stub.onclose(); - } - if (reconnectEnabled) { - $timeout(connect, sockjsReconnectInterval); - } - }; + */ + this.$get = ['$timeout', function($timeout) { + var EventBusOriginal, EventBusStub, connect, debugEnabled, enabled, eventBus, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, url, urlPath, urlServer, _ref; + _ref = angular.extend({}, DEFAULT_OPTIONS, options), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions; + EventBusStub = null; + EventBusOriginal = typeof vertx !== "undefined" && vertx !== null ? vertx.EventBus : void 0; + if (enabled && EventBusOriginal) { + url = "" + urlServer + urlPath; + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Enabled: connecting '" + url + "'"); + } + eventBus = null; + connect = function() { + eventBus = new EventBusOriginal(url, void 0, sockjsOptions); + eventBus.onopen = function() { + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Connected"); + } + if (typeof EventBusStub.onopen === 'function') { + EventBusStub.onopen(); + } }; - connect(); - stub = { - reconnect: function () { - return eventBus.close(); - }, - close: function () { - return eventBus.close(); - }, - login: function (username, password, replyHandler) { - return eventBus.login(username, password, replyHandler); - }, - send: function (address, message, replyHandler) { - return eventBus.send(address, message, replyHandler); - }, - publish: function (address, message) { - return eventBus.publish(address, message); - }, - registerHandler: function (address, handler) { - var deconstructor; - eventBus.registerHandler(address, handler); - /* and return the deregister callback*/ - deconstructor = function () { - stub.unregisterHandler(address, handler); - }; - deconstructor.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.registerHandler (deconstructor)'; - return deconstructor; - }, - unregisterHandler: function (address, handler) { - return eventBus.unregisterHandler(address, handler); - }, - readyState: function () { - return eventBus.readyState(); - }, - EventBus: EventBus_, - getOptions: function () { - return angular.extend({}, options); + eventBus.onclose = function() { + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Reconnect in " + sockjsReconnectInterval + "ms"); + } + if (typeof EventBusStub.onclose === 'function') { + EventBusStub.onclose(); + } + if (reconnectEnabled) { + $timeout(connect, sockjsReconnectInterval); } }; - stub.reconnect.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.reconnect'; - stub.close.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.close'; - stub.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.login'; - stub.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.send'; - stub.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.publish'; - stub.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.registerHandler'; - stub.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.unregisterHandler'; - stub.readyState.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.readyState'; - stub.getOptions.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.getOptions'; - } else { - if (debugEnabled) { - console.debug('[VertX EventBus] Disabled'); + }; + connect(); + EventBusStub = { + reconnect: function() { + return eventBus.close(); + }, + close: function() { + return eventBus.close(); + }, + login: function(username, password, replyHandler) { + return eventBus.login(username, password, replyHandler); + }, + send: function(address, message, replyHandler) { + return eventBus.send(address, message, replyHandler); + }, + publish: function(address, message) { + return eventBus.publish(address, message); + }, + registerHandler: function(address, handler) { + var deconstructor; + eventBus.registerHandler(address, handler); + + /* and return the deregister callback */ + deconstructor = function() { + EventBusStub.unregisterHandler(address, handler); + }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.registerHandler (deconstructor)"; + return deconstructor; + }, + unregisterHandler: function(address, handler) { + return eventBus.unregisterHandler(address, handler); + }, + readyState: function() { + return eventBus.readyState(); + }, + + /* expose current used internal instance of actual EventBus */ + EventBus: EventBusOriginal, + getOptions: function() { + return angular.extend({}, options); } + }; + EventBusStub.reconnect.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.reconnect"; + EventBusStub.close.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.close"; + EventBusStub.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.login"; + EventBusStub.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.send"; + EventBusStub.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.publish"; + EventBusStub.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.registerHandler"; + EventBusStub.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.unregisterHandler"; + EventBusStub.readyState.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.readyState"; + EventBusStub.getOptions.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.getOptions"; + } else { + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Disabled"); } - return stub; } - ]; - this.$get.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': initializer'; + return EventBusStub; + }]; + this.$get.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": Factory.get"; }); + + /* A service utilitzing an underlaying Vertx Event Bus @@ -234,9 +251,10 @@ }); Note the additional configuration of the module itself. - */ - angular.module('knalli.angular-vertxbus').provider('vertxEventBusService', function () { - var CONSTANTS, DEFAULT_OPTIONS, MessageQueueHolder, SimpleMap, options; + */ + + angular.module('knalli.angular-vertxbus').provider('vertxEventBusService', function() { + var CONSTANTS, DEFAULT_OPTIONS, Queue, SimpleMap, options; CONSTANTS = { MODULE: 'angular-vertxbus', COMPONENT: 'service' @@ -246,40 +264,63 @@ loginBlockForSession: false, skipUnauthorizeds: true }; - MessageQueueHolder = function () { - function MessageQueueHolder(maxSize) { + + /* + Simple queue implementation + + FIFO: #push() + #first() + LIFO: #push() + #last() + */ + Queue = (function() { + function Queue(maxSize) { this.maxSize = maxSize != null ? maxSize : 10; this.items = []; } - MessageQueueHolder.prototype.push = function (item) { + + Queue.prototype.push = function(item) { this.items.push(item); return this.recalibrateBufferSize(); }; - MessageQueueHolder.prototype.recalibrateBufferSize = function () { + + Queue.prototype.recalibrateBufferSize = function() { while (this.items.length > this.maxSize) { this.first(); } return this; }; - MessageQueueHolder.prototype.last = function () { + + Queue.prototype.last = function() { return this.items.pop(); }; - MessageQueueHolder.prototype.first = function () { + + Queue.prototype.first = function() { return this.items.shift(0); }; - MessageQueueHolder.prototype.size = function () { + + Queue.prototype.size = function() { return this.items.length; }; - return MessageQueueHolder; - }(); - SimpleMap = function () { + + return Queue; + + })(); + + /* + Simple Map implementation + + This implementation allows usage of non serializable keys for values. + */ + SimpleMap = (function() { SimpleMap.prototype.keys = null; + SimpleMap.prototype.values = null; + function SimpleMap() { this.keys = []; this.values = []; } - SimpleMap.prototype.put = function (key, value) { + + SimpleMap.prototype.put = function(key, value) { var idx; idx = this._indexForKey(key); if (idx > -1) { @@ -290,366 +331,374 @@ } return this; }; - SimpleMap.prototype._indexForKey = function (key) { - var i, k, _i, _len, _ref; - _ref = this.keys; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - k = _ref[i]; - if (key === k) { - return i; - } - } - return -1; - }; - SimpleMap.prototype._indexForValue = function (value) { - var i, v, _i, _len, _ref; - _ref = this.values; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - v = _ref[i]; - if (value === v) { - return i; - } + + SimpleMap.prototype.get = function(key) { + var idx; + idx = this._indexForKey(key); + if (idx > -1) { + return this.values[idx]; } - return -1; }; - SimpleMap.prototype.containsKey = function (key) { + + SimpleMap.prototype.containsKey = function(key) { var idx; idx = this._indexForKey(key); return idx > -1; }; - SimpleMap.prototype.containsValue = function (value) { + + SimpleMap.prototype.containsValue = function(value) { var idx; idx = this._indexForValue(value); return idx > -1; }; - SimpleMap.prototype.get = function (key) { - var idx; - idx = this._indexForKey(key); - if (idx > -1) { - return this.values[idx]; - } - return void 0; - }; - SimpleMap.prototype.remove = function (key) { + + SimpleMap.prototype.remove = function(key) { var idx; idx = this._indexForKey(key); if (idx > -1) { this.keys[idx] = void 0; this.values[idx] = void 0; } - return void 0; }; - SimpleMap.prototype.clear = function () { + + SimpleMap.prototype.clear = function() { this.keys = []; this.values = []; return this; }; + + SimpleMap.prototype._indexForKey = function(key) { + var i, k, _i, _len, _ref; + _ref = this.keys; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + k = _ref[i]; + if (key === k) { + return i; + } + } + return -1; + }; + + SimpleMap.prototype._indexForValue = function(value) { + var i, v, _i, _len, _ref; + _ref = this.values; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + v = _ref[i]; + if (value === v) { + return i; + } + } + return -1; + }; + return SimpleMap; - }(); + + })(); options = angular.extend({}, DEFAULT_OPTIONS); - this.requireLogin = function (value) { + this.requireLogin = function(value) { if (value == null) { value = options.loginRequired; } options.loginRequired = value; return this; }; - this.requireLogin.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': requireLogin'; - this.blockForSession = function (value) { + this.requireLogin.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.requireLogin"; + this.blockForSession = function(value) { if (value == null) { value = options.loginBlockForSession; } options.loginBlockForSession = value; return this; }; - this.blockForSession.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': blockForSession'; - this.skipUnauthorizeds = function (value) { + this.blockForSession.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.blockForSession"; + this.skipUnauthorizeds = function(value) { if (value == null) { value = options.skipUnauthorizeds; } options.skipUnauthorizeds = value; return this; }; - this.skipUnauthorizeds.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': skipUnauthorizeds'; - this.$get = [ - '$rootScope', - '$q', - '$interval', - '$timeout', - 'vertxEventBus', - function ($rootScope, $q, $interval, $timeout, vertxEventBus) { - var connectionIntervalCheck, connectionState, debugEnabled, enabled, ensureOpenAuthConnection, ensureOpenConnection, fnWrapperMap, loginPromise, messageBuffer, messageQueueHolder, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; - _ref = (vertxEventBus != null ? vertxEventBus.getOptions() : void 0) || {}, enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions, messageBuffer = _ref.messageBuffer; - connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0; - validSession = false; - loginPromise = null; - messageQueueHolder = new MessageQueueHolder(messageBuffer); - fnWrapperMap = new SimpleMap(); - if (enabled && vertxEventBus) { - vertxEventBus.onopen = function () { - var address, callback, callbacks, fn, _i, _len, _ref2; - wrapped.getConnectionState(true); - $rootScope.$broadcast('' + prefix + 'system.connected'); - _ref2 = wrapped.handlers; - for (address in _ref2) { - if (!__hasProp.call(_ref2, address)) - continue; - callbacks = _ref2[address]; - for (_i = 0, _len = callbacks.length; _i < _len; _i++) { - callback = callbacks[_i]; - util.registerHandler(address, callback); + this.skipUnauthorizeds.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.skipUnauthorizeds"; + this.$get = ['$rootScope', '$q', '$interval', '$timeout', 'vertxEventBus', function($rootScope, $q, $interval, $timeout, vertxEventBus) { + var connectionIntervalCheck, connectionState, debugEnabled, deconstructors, enabled, ensureOpenAuthConnection, ensureOpenConnection, loginPromise, messageBuffer, messageQueue, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; + _ref = (vertxEventBus != null ? vertxEventBus.getOptions() : void 0) || {}, enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions, messageBuffer = _ref.messageBuffer; + connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0; + validSession = false; + loginPromise = null; + messageQueue = new Queue(messageBuffer); + deconstructors = new SimpleMap(); + if (enabled && vertxEventBus) { + vertxEventBus.onopen = function() { + var address, callback, callbacks, fn, _i, _len, _ref2; + wrapped.getConnectionState(true); + $rootScope.$broadcast("" + prefix + "system.connected"); + _ref2 = wrapped.handlers; + for (address in _ref2) { + if (!__hasProp.call(_ref2, address)) continue; + callbacks = _ref2[address]; + for (_i = 0, _len = callbacks.length; _i < _len; _i++) { + callback = callbacks[_i]; + util.registerHandler(address, callback); + } + } + $rootScope.$digest(); + if (messageBuffer && messageQueue.size()) { + while (messageQueue.size()) { + fn = messageQueue.first(); + if (typeof fn === 'function') { + fn(); } } $rootScope.$digest(); - if (messageBuffer && messageQueueHolder.size()) { - while (messageQueueHolder.size()) { - fn = messageQueueHolder.first(); - if (typeof fn === 'function') { - fn(); - } + } + }; + vertxEventBus.onclose = function() { + wrapped.getConnectionState(true); + return $rootScope.$broadcast("" + prefix + "system.disconnected"); + }; + vertxEventBus.onclose.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": 'onclose' handler"; + } + ensureOpenConnection = function(fn) { + if (wrapped.getConnectionState() === vertxEventBus.EventBus.OPEN) { + fn(); + return true; + } else if (messageBuffer) { + messageQueue.push(fn); + return true; + } + return false; + }; + ensureOpenConnection.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenConnection"; + ensureOpenAuthConnection = function(fn) { + var wrapFn; + if (!options.loginRequired) { + return ensureOpenConnection(fn); + } else { + wrapFn = function() { + if (validSession) { + fn(); + return true; + } else { + if (debugEnabled) { + console.debug("[Vert.x EB Service] Message was not sent because login is required"); } - $rootScope.$digest(); + return false; } }; - vertxEventBus.onclose = function () { - wrapped.getConnectionState(true); - return $rootScope.$broadcast('' + prefix + 'system.disconnected'); - }; - vertxEventBus.onclose.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': \'onclose\' handler'; + wrapFn.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenAuthConnection function wrapper"; + return ensureOpenConnection(wrapFn); } - ensureOpenConnection = function (fn) { - if (wrapped.getConnectionState() === vertxEventBus.EventBus.OPEN) { - fn(); - return true; - } else if (messageBuffer) { - messageQueueHolder.push(fn); - return true; + }; + ensureOpenAuthConnection.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenAuthConnection"; + util = { + registerHandler: function(address, callback) { + var deconstructor; + if (typeof callback !== 'function') { + return; } - return false; - }; - ensureOpenConnection.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenConnection'; - ensureOpenAuthConnection = function (fn) { - var wrapFn; - if (!options.loginRequired) { - return ensureOpenConnection(fn); - } else { - wrapFn = function () { - if (validSession) { - fn(); - return true; - } else { - if (debugEnabled) { - console.debug('[VertX EB Service] Message was not sent because login is required'); - } - return false; - } - }; - wrapFn.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenAuthConnection function wrapper'; - return ensureOpenConnection(wrapFn); + if (debugEnabled) { + console.debug("[Vert.x EB Service] Register handler for " + address); } - }; - ensureOpenAuthConnection.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenAuthConnection'; - util = { - registerHandler: function (address, callback) { - var deconstructor; - if (typeof callback !== 'function') { - return; - } - if (debugEnabled) { - console.debug('[VertX EB Service] Register handler for ' + address); - } - if (fnWrapperMap.containsKey(callback)) { - return fnWrapperMap.get(callback); - } - deconstructor = function (message, replyTo) { - callback(message, replyTo); - return $rootScope.$digest(); - }; - deconstructor.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.registerHandler (deconstructor)'; - fnWrapperMap.put(callback, deconstructor); - return vertxEventBus.registerHandler(address, fnWrapperMap.get(callback)); - }, - unregisterHandler: function (address, callback) { - if (typeof callback !== 'function') { - return; - } - if (debugEnabled) { - console.debug('[VertX EB Service] Unregister handler for ' + address); - } - vertxEventBus.unregisterHandler(address, fnWrapperMap.get(callback)); - fnWrapperMap.remove(callback); - }, - send: function (address, message, timeout) { - var deferred, dispatched, next; - if (timeout == null) { - timeout = 10000; - } - deferred = $q.defer(); - next = function () { - vertxEventBus.send(address, message, function (reply) { - if (deferred) { - return deferred.resolve(reply); - } - }); + if (deconstructors.containsKey(callback)) { + return deconstructors.get(callback); + } + deconstructor = function(message, replyTo) { + callback(message, replyTo); + $rootScope.$digest(); + }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.registerHandler (deconstructor)"; + deconstructors.put(callback, deconstructor); + return vertxEventBus.registerHandler(address, deconstructors.get(callback)); + }, + unregisterHandler: function(address, callback) { + if (typeof callback !== 'function') { + return; + } + if (debugEnabled) { + console.debug("[Vert.x EB Service] Unregister handler for " + address); + } + vertxEventBus.unregisterHandler(address, deconstructors.get(callback)); + deconstructors.remove(callback); + }, + send: function(address, message, timeout) { + var deferred, dispatched, next; + if (timeout == null) { + timeout = 10000; + } + deferred = $q.defer(); + next = function() { + vertxEventBus.send(address, message, function(reply) { if (deferred) { - return $timeout(function () { - return deferred.reject(); - }, timeout); + return deferred.resolve(reply); } - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.send (ensureOpenAuthConnection callback)'; - dispatched = ensureOpenAuthConnection(next); - if (deferred && !dispatched) { - deferred.reject(); - } - return deferred != null ? deferred.promise : void 0; - }, - publish: function (address, message) { - var dispatched, next; - next = function () { - return vertxEventBus.publish(address, message); - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.publish (ensureOpenAuthConnection callback)'; - dispatched = ensureOpenAuthConnection(next); - return dispatched; - }, - login: function (username, password, timeout) { - var deferred, next; - if (timeout == null) { - timeout = 5000; + }); + if (deferred) { + return $timeout((function() { + return deferred.reject(); + }), timeout); } - deferred = $q.defer(); - next = function (reply) { - if ((reply != null ? reply.status : void 0) === 'ok') { - deferred.resolve(reply); - return $rootScope.$broadcast('' + prefix + 'system.login.succeeded', { status: reply != null ? reply.status : void 0 }); - } else { - deferred.reject(reply); - return $rootScope.$broadcast('' + prefix + 'system.login.failed', { status: reply != null ? reply.status : void 0 }); - } - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.login (callback)'; - vertxEventBus.login(username, password, next); - $timeout(function () { - return deferred.reject(); - }, timeout); - return deferred.promise; + }; + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.send (ensureOpenAuthConnection callback)"; + dispatched = ensureOpenAuthConnection(next); + if (deferred && !dispatched) { + deferred.reject(); } - }; - util.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.registerHandler'; - util.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.unregisterHandler'; - util.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.send'; - util.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.publish'; - util.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.login'; - wrapped = { - handlers: {}, - registerHandler: function (address, callback) { - var unregisterFn; - if (!wrapped.handlers[address]) { - wrapped.handlers[address] = []; - } - wrapped.handlers[address].push(callback); - unregisterFn = null; - if (connectionState === vertxEventBus.EventBus.OPEN) { - unregisterFn = util.registerHandler(address, callback); + return deferred != null ? deferred.promise : void 0; + }, + publish: function(address, message) { + var dispatched, next; + next = function() { + return vertxEventBus.publish(address, message); + }; + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.publish (ensureOpenAuthConnection callback)"; + dispatched = ensureOpenAuthConnection(next); + return dispatched; + }, + login: function(username, password, timeout) { + var deferred, next; + if (timeout == null) { + timeout = 5000; + } + deferred = $q.defer(); + next = function(reply) { + if ((reply != null ? reply.status : void 0) === 'ok') { + deferred.resolve(reply); + return $rootScope.$broadcast("" + prefix + "system.login.succeeded", { + status: reply != null ? reply.status : void 0 + }); + } else { + deferred.reject(reply); + return $rootScope.$broadcast("" + prefix + "system.login.failed", { + status: reply != null ? reply.status : void 0 + }); } - /* and return the deregister callback*/ - return function () { - var index; - if (unregisterFn) { - unregisterFn(); - } - if (wrapped.handlers[address]) { - index = wrapped.handlers[address].indexOf(callback); - if (index > -1) { - wrapped.handlers[address].splice(index, 1); - } - } - }; - }, - unregisterHandler: function (address, callback) { + }; + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.login (callback)"; + vertxEventBus.login(username, password, next); + $timeout((function() { + return deferred.reject(); + }), timeout); + return deferred.promise; + } + }; + util.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.registerHandler"; + util.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.unregisterHandler"; + util.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.send"; + util.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.publish"; + util.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.login"; + wrapped = { + handlers: {}, + registerHandler: function(address, callback) { + var deconstructor, unregisterFn; + if (!wrapped.handlers[address]) { + wrapped.handlers[address] = []; + } + wrapped.handlers[address].push(callback); + unregisterFn = null; + if (connectionState === vertxEventBus.EventBus.OPEN) { + unregisterFn = util.registerHandler(address, callback); + } + + /* and return the deregister callback */ + deconstructor = function() { var index; + if (unregisterFn) { + unregisterFn(); + } if (wrapped.handlers[address]) { index = wrapped.handlers[address].indexOf(callback); if (index > -1) { wrapped.handlers[address].splice(index, 1); } } - if (connectionState === vertxEventBus.EventBus.OPEN) { - return util.unregisterHandler(address, callback); - } - }, - send: function (address, message, timeout) { - if (timeout == null) { - timeout = 10000; + }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.registerHandler (deconstructor)"; + return deconstructor; + }, + unregisterHandler: function(address, callback) { + var index; + if (wrapped.handlers[address]) { + index = wrapped.handlers[address].indexOf(callback); + if (index > -1) { + wrapped.handlers[address].splice(index, 1); } - return util.send(address, message, timeout); - }, - publish: function (address, message) { - return util.publish(address, message); - }, - getConnectionState: function (immediate) { - if (vertxEventBus != null ? vertxEventBus.EventBus : void 0) { - if (enabled) { - if (immediate) { - connectionState = vertxEventBus.readyState(); - } - } else { - connectionState = vertxEventBus.EventBus.CLOSED; + } + if (connectionState === vertxEventBus.EventBus.OPEN) { + return util.unregisterHandler(address, callback); + } + }, + send: function(address, message, timeout) { + if (timeout == null) { + timeout = 10000; + } + return util.send(address, message, timeout); + }, + publish: function(address, message) { + return util.publish(address, message); + }, + getConnectionState: function(immediate) { + if (vertxEventBus != null ? vertxEventBus.EventBus : void 0) { + if (enabled) { + if (immediate) { + connectionState = vertxEventBus.readyState(); } } else { - connectionState = 3; + connectionState = vertxEventBus.EventBus.CLOSED; } - return connectionState; - }, - isValidSession: function () { - return validSession; - }, - login: function (username, password) { - return util.login(username, password).then(function (reply) { - validSession = true; - return reply; - })['catch'](function (reply) { - validSession = false; - return reply; - }); + } else { + connectionState = 3; } - }; - wrapped.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.registerHandler'; - wrapped.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.unregisterHandler'; - wrapped.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.send'; - wrapped.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.publish'; - wrapped.getConnectionState.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.getConnectionState'; - wrapped.isValidSession.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.isValidSession'; - wrapped.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.login'; - connectionIntervalCheck = function () { - return wrapped.getConnectionState(true); - }; - connectionIntervalCheck.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': periodic connection check'; - $interval(connectionIntervalCheck, sockjsStateInterval); - /* building and exposing the actual service API*/ - return { - on: wrapped.registerHandler, - addListener: wrapped.registerHandler, - un: wrapped.unregisterHandler, - removeListener: wrapped.unregisterHandler, - send: wrapped.send, - publish: wrapped.publish, - emit: wrapped.publish, - readyState: wrapped.getConnectionState, - isEnabled: function () { - return enabled; - }, - getBufferCount: function () { - return messageQueueHolder.size(); - }, - isValidSession: function () { - return validSession; - }, - login: wrapped.login - }; - } - ]; - this.$get.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': initializer'; + return connectionState; + }, + isValidSession: function() { + return validSession; + }, + login: function(username, password) { + return util.login(username, password).then(function(reply) { + validSession = true; + return reply; + })["catch"](function(reply) { + validSession = false; + return reply; + }); + } + }; + wrapped.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.registerHandler"; + wrapped.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.unregisterHandler"; + wrapped.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.send"; + wrapped.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.publish"; + wrapped.getConnectionState.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.getConnectionState"; + wrapped.isValidSession.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.isValidSession"; + wrapped.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.login"; + connectionIntervalCheck = function() { + return wrapped.getConnectionState(true); + }; + connectionIntervalCheck.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": periodic connection check"; + $interval(connectionIntervalCheck, sockjsStateInterval); + + /* building and exposing the actual service API */ + return { + on: wrapped.registerHandler, + addListener: wrapped.registerHandler, + un: wrapped.unregisterHandler, + removeListener: wrapped.unregisterHandler, + send: wrapped.send, + publish: wrapped.publish, + emit: wrapped.publish, + readyState: wrapped.getConnectionState, + isEnabled: function() { + return enabled; + }, + getBufferCount: function() { + return messageQueue.size(); + }, + isValidSession: function() { + return validSession; + }, + login: wrapped.login + }; + }]; + this.$get.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": Factory.get"; }); -}.call(this)); \ No newline at end of file + +}).call(this); diff --git a/dist/angular-vertxbus.min.js b/dist/angular-vertxbus.min.js index 920e1a5..f4d4605 100644 --- a/dist/angular-vertxbus.min.js +++ b/dist/angular-vertxbus.min.js @@ -1 +1 @@ -(function(){var a={}.hasOwnProperty;angular.module("knalli.angular-vertxbus",["ng"]),angular.module("knalli.angular-vertxbus").provider("vertxEventBus",function(){var a,b,c;a={MODULE:"angular-vertxbus",COMPONENT:"wrapper"},b={enabled:!0,debugEnabled:!1,prefix:"vertx-eventbus.",urlServer:""+location.protocol+"//"+location.hostname+":"+(location.port||80),urlPath:"/eventbus",reconnectEnabled:!0,sockjsStateInterval:1e4,sockjsReconnectInterval:1e4,sockjsOptions:{},messageBuffer:0},c=angular.extend({},b),this.enable=function(a){return null==a&&(a=b.enabled),c.enabled=a===!0,this},this.useDebug=function(a){return null==a&&(a=b.debugEnabled),c.debugEnabled=a===!0,this},this.usePrefix=function(a){return null==a&&(a=b.prefix),c.prefix=a,this},this.useUrlServer=function(a){return null==a&&(a=b.urlServer),c.urlServer=a,this},this.useUrlPath=function(a){return null==a&&(a=b.urlPath),c.urlPath=a,this},this.useReconnect=function(a){return null==a&&(a=b.reconnectEnabled),c.reconnectEnabled=a,this},this.useSockJsStateInterval=function(a){return null==a&&(a=b.sockjsStateInterval),c.sockjsStateInterval=a,this},this.useSockJsReconnectInterval=function(a){return null==a&&(a=b.sockjsReconnectInterval),c.sockjsReconnectInterval=a,this},this.useSockJsOptions=function(a){return null==a&&(a=b.sockjsOptions),c.sockjsOptions=a,this},this.useMessageBuffer=function(a){return null==a&&(a=b.messageBuffer),c.messageBuffer=a,this},this.$get=["$timeout",function(d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return s=angular.extend({},b,c),h=s.enabled,g=s.debugEnabled,j=s.prefix,r=s.urlServer,q=s.urlPath,k=s.reconnectEnabled,n=s.sockjsStateInterval,m=s.sockjsReconnectInterval,l=s.sockjsOptions,o=null,e="undefined"!=typeof vertx&&null!==vertx?vertx.EventBus:void 0,h&&e?(p=""+r+q,g&&console.debug("[VertX EventBus] Enabled: connecting '"+p+"'"),i=null,f=function(){i=new e(p,void 0,l),i.onopen=function(){g&&console.debug("[VertX EventBus] Connected"),"function"==typeof o.onopen&&o.onopen()},i.onclose=function(){g&&console.debug("[VertX EventBus] Reconnect in "+m+"ms"),"function"==typeof o.onclose&&o.onclose(),k&&d(f,m)}},f(),o={reconnect:function(){return i.close()},close:function(){return i.close()},login:function(a,b,c){return i.login(a,b,c)},send:function(a,b,c){return i.send(a,b,c)},publish:function(a,b){return i.publish(a,b)},registerHandler:function(b,c){var d;return i.registerHandler(b,c),d=function(){o.unregisterHandler(b,c)},d.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.registerHandler (deconstructor)",d},unregisterHandler:function(a,b){return i.unregisterHandler(a,b)},readyState:function(){return i.readyState()},EventBus:e,getOptions:function(){return angular.extend({},c)}},o.reconnect.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.reconnect",o.close.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.close",o.login.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.login",o.send.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.send",o.publish.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.publish",o.registerHandler.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.registerHandler",o.unregisterHandler.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.unregisterHandler",o.readyState.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.readyState",o.getOptions.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusWrapper.getOptions"):g&&console.debug("[VertX EventBus] Disabled"),o}],this.$get.displayName=""+a.MODULE+"/"+a.COMPONENT+": initializer"}),angular.module("knalli.angular-vertxbus").provider("vertxEventBusService",function(){var b,c,d,e,f;b={MODULE:"angular-vertxbus",COMPONENT:"service"},c={loginRequired:!1,loginBlockForSession:!1,skipUnauthorizeds:!0},d=function(){function a(a){this.maxSize=null!=a?a:10,this.items=[]}return a.prototype.push=function(a){return this.items.push(a),this.recalibrateBufferSize()},a.prototype.recalibrateBufferSize=function(){for(;this.items.length>this.maxSize;)this.first();return this},a.prototype.last=function(){return this.items.pop()},a.prototype.first=function(){return this.items.shift(0)},a.prototype.size=function(){return this.items.length},a}(),e=function(){function a(){this.keys=[],this.values=[]}return a.prototype.keys=null,a.prototype.values=null,a.prototype.put=function(a,b){var c;return c=this._indexForKey(a),c>-1?this.values[c]=b:(this.keys.push(a),this.values.push(b)),this},a.prototype._indexForKey=function(a){var b,c,d,e,f;for(f=this.keys,b=d=0,e=f.length;e>d;b=++d)if(c=f[b],a===c)return b;return-1},a.prototype._indexForValue=function(a){var b,c,d,e,f;for(f=this.values,b=d=0,e=f.length;e>d;b=++d)if(c=f[b],a===c)return b;return-1},a.prototype.containsKey=function(a){var b;return b=this._indexForKey(a),b>-1},a.prototype.containsValue=function(a){var b;return b=this._indexForValue(a),b>-1},a.prototype.get=function(a){var b;return b=this._indexForKey(a),b>-1?this.values[b]:void 0},a.prototype.remove=function(a){var b;return b=this._indexForKey(a),void(b>-1&&(this.keys[b]=void 0,this.values[b]=void 0))},a.prototype.clear=function(){return this.keys=[],this.values=[],this},a}(),f=angular.extend({},c),this.requireLogin=function(a){return null==a&&(a=f.loginRequired),f.loginRequired=a,this},this.requireLogin.displayName=""+b.MODULE+"/"+b.COMPONENT+": requireLogin",this.blockForSession=function(a){return null==a&&(a=f.loginBlockForSession),f.loginBlockForSession=a,this},this.blockForSession.displayName=""+b.MODULE+"/"+b.COMPONENT+": blockForSession",this.skipUnauthorizeds=function(a){return null==a&&(a=f.skipUnauthorizeds),f.skipUnauthorizeds=a,this},this.skipUnauthorizeds.displayName=""+b.MODULE+"/"+b.COMPONENT+": skipUnauthorizeds",this.$get=["$rootScope","$q","$interval","$timeout","vertxEventBus",function(c,g,h,i,j){var k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;return E=(null!=j?j.getOptions():void 0)||{},n=E.enabled,m=E.debugEnabled,u=E.prefix,A=E.urlServer,z=E.urlPath,v=E.reconnectEnabled,y=E.sockjsStateInterval,x=E.sockjsReconnectInterval,w=E.sockjsOptions,s=E.messageBuffer,l=null!=j&&null!=(F=j.EventBus)?F.CLOSED:void 0,C=!1,r=null,t=new d(s),q=new e,n&&j&&(j.onopen=function(){var b,d,e,f,g,h,i;D.getConnectionState(!0),c.$broadcast(""+u+"system.connected"),i=D.handlers;for(b in i)if(a.call(i,b))for(e=i[b],g=0,h=e.length;h>g;g++)d=e[g],B.registerHandler(b,d);if(c.$digest(),s&&t.size()){for(;t.size();)f=t.first(),"function"==typeof f&&f();c.$digest()}},j.onclose=function(){return D.getConnectionState(!0),c.$broadcast(""+u+"system.disconnected")},j.onclose.displayName=""+b.MODULE+"/"+b.COMPONENT+": 'onclose' handler"),p=function(a){return D.getConnectionState()===j.EventBus.OPEN?(a(),!0):s?(t.push(a),!0):!1},p.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenConnection",o=function(a){var c;return f.loginRequired?(c=function(){return C?(a(),!0):(m&&console.debug("[VertX EB Service] Message was not sent because login is required"),!1)},c.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenAuthConnection function wrapper",p(c)):p(a)},o.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenAuthConnection",B={registerHandler:function(a,d){var e;if("function"==typeof d)return m&&console.debug("[VertX EB Service] Register handler for "+a),q.containsKey(d)?q.get(d):(e=function(a,b){return d(a,b),c.$digest()},e.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.registerHandler (deconstructor)",q.put(d,e),j.registerHandler(a,q.get(d)))},unregisterHandler:function(a,b){"function"==typeof b&&(m&&console.debug("[VertX EB Service] Unregister handler for "+a),j.unregisterHandler(a,q.get(b)),q.remove(b))},send:function(a,c,d){var e,f,h;return null==d&&(d=1e4),e=g.defer(),h=function(){return j.send(a,c,function(a){return e?e.resolve(a):void 0}),e?i(function(){return e.reject()},d):void 0},h.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.send (ensureOpenAuthConnection callback)",f=o(h),e&&!f&&e.reject(),null!=e?e.promise:void 0},publish:function(a,c){var d,e;return e=function(){return j.publish(a,c)},e.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.publish (ensureOpenAuthConnection callback)",d=o(e)},login:function(a,d,e){var f,h;return null==e&&(e=5e3),f=g.defer(),h=function(a){return"ok"===(null!=a?a.status:void 0)?(f.resolve(a),c.$broadcast(""+u+"system.login.succeeded",{status:null!=a?a.status:void 0})):(f.reject(a),c.$broadcast(""+u+"system.login.failed",{status:null!=a?a.status:void 0}))},h.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.login (callback)",j.login(a,d,h),i(function(){return f.reject()},e),f.promise}},B.registerHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.registerHandler",B.unregisterHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.unregisterHandler",B.send.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.send",B.publish.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.publish",B.login.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.login",D={handlers:{},registerHandler:function(a,b){var c;return D.handlers[a]||(D.handlers[a]=[]),D.handlers[a].push(b),c=null,l===j.EventBus.OPEN&&(c=B.registerHandler(a,b)),function(){var d;c&&c(),D.handlers[a]&&(d=D.handlers[a].indexOf(b),d>-1&&D.handlers[a].splice(d,1))}},unregisterHandler:function(a,b){var c;return D.handlers[a]&&(c=D.handlers[a].indexOf(b),c>-1&&D.handlers[a].splice(c,1)),l===j.EventBus.OPEN?B.unregisterHandler(a,b):void 0},send:function(a,b,c){return null==c&&(c=1e4),B.send(a,b,c)},publish:function(a,b){return B.publish(a,b)},getConnectionState:function(a){return(null!=j?j.EventBus:void 0)?n?a&&(l=j.readyState()):l=j.EventBus.CLOSED:l=3,l},isValidSession:function(){return C},login:function(a,b){return B.login(a,b).then(function(a){return C=!0,a})["catch"](function(a){return C=!1,a})}},D.registerHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.registerHandler",D.unregisterHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.unregisterHandler",D.send.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.send",D.publish.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.publish",D.getConnectionState.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.getConnectionState",D.isValidSession.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.isValidSession",D.login.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.login",k=function(){return D.getConnectionState(!0)},k.displayName=""+b.MODULE+"/"+b.COMPONENT+": periodic connection check",h(k,y),{on:D.registerHandler,addListener:D.registerHandler,un:D.unregisterHandler,removeListener:D.unregisterHandler,send:D.send,publish:D.publish,emit:D.publish,readyState:D.getConnectionState,isEnabled:function(){return n},getBufferCount:function(){return t.size()},isValidSession:function(){return C},login:D.login}}],this.$get.displayName=""+b.MODULE+"/"+b.COMPONENT+": initializer"})}).call(this); \ No newline at end of file +(function(){var a={}.hasOwnProperty;angular.module("knalli.angular-vertxbus",["ng"]),angular.module("knalli.angular-vertxbus").provider("vertxEventBus",function(){var a,b,c;a={MODULE:"angular-vertxbus",COMPONENT:"wrapper"},b={enabled:!0,debugEnabled:!1,prefix:"vertx-eventbus.",urlServer:""+location.protocol+"//"+location.hostname+":"+(location.port||80),urlPath:"/eventbus",reconnectEnabled:!0,sockjsStateInterval:1e4,sockjsReconnectInterval:1e4,sockjsOptions:{},messageBuffer:0},c=angular.extend({},b),this.enable=function(a){return null==a&&(a=b.enabled),c.enabled=a===!0,this},this.enable.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.enable",this.useDebug=function(a){return null==a&&(a=b.debugEnabled),c.debugEnabled=a===!0,this},this.useDebug.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useDebug",this.usePrefix=function(a){return null==a&&(a=b.prefix),c.prefix=a,this},this.usePrefix.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.usePrefix",this.useUrlServer=function(a){return null==a&&(a=b.urlServer),c.urlServer=a,this},this.useUrlServer.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useUrlServer",this.useUrlPath=function(a){return null==a&&(a=b.urlPath),c.urlPath=a,this},this.useUrlPath.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useUrlPath",this.useReconnect=function(a){return null==a&&(a=b.reconnectEnabled),c.reconnectEnabled=a,this},this.useReconnect.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useReconnect",this.useSockJsStateInterval=function(a){return null==a&&(a=b.sockjsStateInterval),c.sockjsStateInterval=a,this},this.useSockJsStateInterval.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useSockJsStateInterval",this.useSockJsReconnectInterval=function(a){return null==a&&(a=b.sockjsReconnectInterval),c.sockjsReconnectInterval=a,this},this.useSockJsReconnectInterval.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useSockJsReconnectInterval",this.useSockJsOptions=function(a){return null==a&&(a=b.sockjsOptions),c.sockjsOptions=a,this},this.useSockJsOptions.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useSockJsOptions",this.useMessageBuffer=function(a){return null==a&&(a=b.messageBuffer),c.messageBuffer=a,this},this.useMessageBuffer.displayName=""+a.MODULE+"/"+a.COMPONENT+": provider.useMessageBuffer",this.$get=["$timeout",function(d){var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return s=angular.extend({},b,c),i=s.enabled,h=s.debugEnabled,k=s.prefix,r=s.urlServer,q=s.urlPath,l=s.reconnectEnabled,o=s.sockjsStateInterval,n=s.sockjsReconnectInterval,m=s.sockjsOptions,f=null,e="undefined"!=typeof vertx&&null!==vertx?vertx.EventBus:void 0,i&&e?(p=""+r+q,h&&console.debug("[Vert.x EB Stub] Enabled: connecting '"+p+"'"),j=null,g=function(){j=new e(p,void 0,m),j.onopen=function(){h&&console.debug("[Vert.x EB Stub] Connected"),"function"==typeof f.onopen&&f.onopen()},j.onclose=function(){h&&console.debug("[Vert.x EB Stub] Reconnect in "+n+"ms"),"function"==typeof f.onclose&&f.onclose(),l&&d(g,n)}},g(),f={reconnect:function(){return j.close()},close:function(){return j.close()},login:function(a,b,c){return j.login(a,b,c)},send:function(a,b,c){return j.send(a,b,c)},publish:function(a,b){return j.publish(a,b)},registerHandler:function(b,c){var d;return j.registerHandler(b,c),d=function(){f.unregisterHandler(b,c)},d.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.registerHandler (deconstructor)",d},unregisterHandler:function(a,b){return j.unregisterHandler(a,b)},readyState:function(){return j.readyState()},EventBus:e,getOptions:function(){return angular.extend({},c)}},f.reconnect.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.reconnect",f.close.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.close",f.login.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.login",f.send.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.send",f.publish.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.publish",f.registerHandler.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.registerHandler",f.unregisterHandler.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.unregisterHandler",f.readyState.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.readyState",f.getOptions.displayName=""+a.MODULE+"/"+a.COMPONENT+": EventBusStub.getOptions"):h&&console.debug("[Vert.x EB Stub] Disabled"),f}],this.$get.displayName=""+a.MODULE+"/"+a.COMPONENT+": Factory.get"}),angular.module("knalli.angular-vertxbus").provider("vertxEventBusService",function(){var b,c,d,e,f;b={MODULE:"angular-vertxbus",COMPONENT:"service"},c={loginRequired:!1,loginBlockForSession:!1,skipUnauthorizeds:!0},d=function(){function a(a){this.maxSize=null!=a?a:10,this.items=[]}return a.prototype.push=function(a){return this.items.push(a),this.recalibrateBufferSize()},a.prototype.recalibrateBufferSize=function(){for(;this.items.length>this.maxSize;)this.first();return this},a.prototype.last=function(){return this.items.pop()},a.prototype.first=function(){return this.items.shift(0)},a.prototype.size=function(){return this.items.length},a}(),e=function(){function a(){this.keys=[],this.values=[]}return a.prototype.keys=null,a.prototype.values=null,a.prototype.put=function(a,b){var c;return c=this._indexForKey(a),c>-1?this.values[c]=b:(this.keys.push(a),this.values.push(b)),this},a.prototype.get=function(a){var b;return b=this._indexForKey(a),b>-1?this.values[b]:void 0},a.prototype.containsKey=function(a){var b;return b=this._indexForKey(a),b>-1},a.prototype.containsValue=function(a){var b;return b=this._indexForValue(a),b>-1},a.prototype.remove=function(a){var b;b=this._indexForKey(a),b>-1&&(this.keys[b]=void 0,this.values[b]=void 0)},a.prototype.clear=function(){return this.keys=[],this.values=[],this},a.prototype._indexForKey=function(a){var b,c,d,e,f;for(f=this.keys,b=d=0,e=f.length;e>d;b=++d)if(c=f[b],a===c)return b;return-1},a.prototype._indexForValue=function(a){var b,c,d,e,f;for(f=this.values,b=d=0,e=f.length;e>d;b=++d)if(c=f[b],a===c)return b;return-1},a}(),f=angular.extend({},c),this.requireLogin=function(a){return null==a&&(a=f.loginRequired),f.loginRequired=a,this},this.requireLogin.displayName=""+b.MODULE+"/"+b.COMPONENT+": provider.requireLogin",this.blockForSession=function(a){return null==a&&(a=f.loginBlockForSession),f.loginBlockForSession=a,this},this.blockForSession.displayName=""+b.MODULE+"/"+b.COMPONENT+": provider.blockForSession",this.skipUnauthorizeds=function(a){return null==a&&(a=f.skipUnauthorizeds),f.skipUnauthorizeds=a,this},this.skipUnauthorizeds.displayName=""+b.MODULE+"/"+b.COMPONENT+": provider.skipUnauthorizeds",this.$get=["$rootScope","$q","$interval","$timeout","vertxEventBus",function(c,g,h,i,j){var k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F;return E=(null!=j?j.getOptions():void 0)||{},o=E.enabled,m=E.debugEnabled,u=E.prefix,A=E.urlServer,z=E.urlPath,v=E.reconnectEnabled,y=E.sockjsStateInterval,x=E.sockjsReconnectInterval,w=E.sockjsOptions,s=E.messageBuffer,l=null!=j&&null!=(F=j.EventBus)?F.CLOSED:void 0,C=!1,r=null,t=new d(s),n=new e,o&&j&&(j.onopen=function(){var b,d,e,f,g,h,i;D.getConnectionState(!0),c.$broadcast(""+u+"system.connected"),i=D.handlers;for(b in i)if(a.call(i,b))for(e=i[b],g=0,h=e.length;h>g;g++)d=e[g],B.registerHandler(b,d);if(c.$digest(),s&&t.size()){for(;t.size();)f=t.first(),"function"==typeof f&&f();c.$digest()}},j.onclose=function(){return D.getConnectionState(!0),c.$broadcast(""+u+"system.disconnected")},j.onclose.displayName=""+b.MODULE+"/"+b.COMPONENT+": 'onclose' handler"),q=function(a){return D.getConnectionState()===j.EventBus.OPEN?(a(),!0):s?(t.push(a),!0):!1},q.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenConnection",p=function(a){var c;return f.loginRequired?(c=function(){return C?(a(),!0):(m&&console.debug("[Vert.x EB Service] Message was not sent because login is required"),!1)},c.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenAuthConnection function wrapper",q(c)):q(a)},p.displayName=""+b.MODULE+"/"+b.COMPONENT+": ensureOpenAuthConnection",B={registerHandler:function(a,d){var e;if("function"==typeof d)return m&&console.debug("[Vert.x EB Service] Register handler for "+a),n.containsKey(d)?n.get(d):(e=function(a,b){d(a,b),c.$digest()},e.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.registerHandler (deconstructor)",n.put(d,e),j.registerHandler(a,n.get(d)))},unregisterHandler:function(a,b){"function"==typeof b&&(m&&console.debug("[Vert.x EB Service] Unregister handler for "+a),j.unregisterHandler(a,n.get(b)),n.remove(b))},send:function(a,c,d){var e,f,h;return null==d&&(d=1e4),e=g.defer(),h=function(){return j.send(a,c,function(a){return e?e.resolve(a):void 0}),e?i(function(){return e.reject()},d):void 0},h.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.send (ensureOpenAuthConnection callback)",f=p(h),e&&!f&&e.reject(),null!=e?e.promise:void 0},publish:function(a,c){var d,e;return e=function(){return j.publish(a,c)},e.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.publish (ensureOpenAuthConnection callback)",d=p(e)},login:function(a,d,e){var f,h;return null==e&&(e=5e3),f=g.defer(),h=function(a){return"ok"===(null!=a?a.status:void 0)?(f.resolve(a),c.$broadcast(""+u+"system.login.succeeded",{status:null!=a?a.status:void 0})):(f.reject(a),c.$broadcast(""+u+"system.login.failed",{status:null!=a?a.status:void 0}))},h.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.login (callback)",j.login(a,d,h),i(function(){return f.reject()},e),f.promise}},B.registerHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.registerHandler",B.unregisterHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.unregisterHandler",B.send.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.send",B.publish.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.publish",B.login.displayName=""+b.MODULE+"/"+b.COMPONENT+": util.login",D={handlers:{},registerHandler:function(a,c){var d,e;return D.handlers[a]||(D.handlers[a]=[]),D.handlers[a].push(c),e=null,l===j.EventBus.OPEN&&(e=B.registerHandler(a,c)),d=function(){var b;e&&e(),D.handlers[a]&&(b=D.handlers[a].indexOf(c),b>-1&&D.handlers[a].splice(b,1))},d.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.registerHandler (deconstructor)",d},unregisterHandler:function(a,b){var c;return D.handlers[a]&&(c=D.handlers[a].indexOf(b),c>-1&&D.handlers[a].splice(c,1)),l===j.EventBus.OPEN?B.unregisterHandler(a,b):void 0},send:function(a,b,c){return null==c&&(c=1e4),B.send(a,b,c)},publish:function(a,b){return B.publish(a,b)},getConnectionState:function(a){return(null!=j?j.EventBus:void 0)?o?a&&(l=j.readyState()):l=j.EventBus.CLOSED:l=3,l},isValidSession:function(){return C},login:function(a,b){return B.login(a,b).then(function(a){return C=!0,a})["catch"](function(a){return C=!1,a})}},D.registerHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.registerHandler",D.unregisterHandler.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.unregisterHandler",D.send.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.send",D.publish.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.publish",D.getConnectionState.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.getConnectionState",D.isValidSession.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.isValidSession",D.login.displayName=""+b.MODULE+"/"+b.COMPONENT+": wrapped.login",k=function(){return D.getConnectionState(!0)},k.displayName=""+b.MODULE+"/"+b.COMPONENT+": periodic connection check",h(k,y),{on:D.registerHandler,addListener:D.registerHandler,un:D.unregisterHandler,removeListener:D.unregisterHandler,send:D.send,publish:D.publish,emit:D.publish,readyState:D.getConnectionState,isEnabled:function(){return o},getBufferCount:function(){return t.size()},isValidSession:function(){return C},login:D.login}}],this.$get.displayName=""+b.MODULE+"/"+b.COMPONENT+": Factory.get"})}).call(this); \ No newline at end of file diff --git a/dist/requirejs/angular-vertxbus.js b/dist/requirejs/angular-vertxbus.js index b80a142..05a8631 100644 --- a/dist/requirejs/angular-vertxbus.js +++ b/dist/requirejs/angular-vertxbus.js @@ -1,14 +1,15 @@ -/*! angular-vertxbus - v0.9.0 - 2014-11-23 +/*! angular-vertxbus - v0.10.0 - 2014-12-14 * http://github.com/knalli/angular-vertxbus * Copyright (c) 2014 ; Licensed */ -define([ - 'angular', - 'vertxbus' -], function (angular) { - (function () { - var __hasProp = {}.hasOwnProperty; - angular.module('knalli.angular-vertxbus', ['ng']); - /* +define(['angular', 'vertxbus'], function(angular) { + +(function() { + var __hasProp = {}.hasOwnProperty; + + angular.module('knalli.angular-vertxbus', ['ng']); + + + /* An AngularJS wrapper for projects using the VertX Event Bus * enabled (default true): if false, the usage of the Event Bus will be disabled (actually, no vertx.EventBus will be created) @@ -20,97 +21,109 @@ define([ * sockjsStateInterval (default 10000 ms): defines the check interval of the underlayling SockJS connection * sockjsReconnectInterval (default 10000 ms): defines the wait time for a reconnect after a disconnect has been recognized * sockjsOptions (default {}): optional SockJS options (new SockJS(url, undefined, options)) - */ - angular.module('knalli.angular-vertxbus').provider('vertxEventBus', function () { - var CONSTANTS, DEFAULT_OPTIONS, options; - CONSTANTS = { - MODULE: 'angular-vertxbus', - COMPONENT: 'wrapper' - }; - DEFAULT_OPTIONS = { - enabled: true, - debugEnabled: false, - prefix: 'vertx-eventbus.', - urlServer: '' + location.protocol + '//' + location.hostname + ':' + (location.port || 80), - urlPath: '/eventbus', - reconnectEnabled: true, - sockjsStateInterval: 10000, - sockjsReconnectInterval: 10000, - sockjsOptions: {}, - messageBuffer: 0 - }; - options = angular.extend({}, DEFAULT_OPTIONS); - this.enable = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.enabled; - } - options.enabled = value === true; - return this; - }; - this.useDebug = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.debugEnabled; - } - options.debugEnabled = value === true; - return this; - }; - this.usePrefix = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.prefix; - } - options.prefix = value; - return this; - }; - this.useUrlServer = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.urlServer; - } - options.urlServer = value; - return this; - }; - this.useUrlPath = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.urlPath; - } - options.urlPath = value; - return this; - }; - this.useReconnect = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.reconnectEnabled; - } - options.reconnectEnabled = value; - return this; - }; - this.useSockJsStateInterval = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.sockjsStateInterval; - } - options.sockjsStateInterval = value; - return this; - }; - this.useSockJsReconnectInterval = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.sockjsReconnectInterval; - } - options.sockjsReconnectInterval = value; - return this; - }; - this.useSockJsOptions = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.sockjsOptions; - } - options.sockjsOptions = value; - return this; - }; - this.useMessageBuffer = function (value) { - if (value == null) { - value = DEFAULT_OPTIONS.messageBuffer; - } - options.messageBuffer = value; - return this; - }; - /* + */ + + angular.module('knalli.angular-vertxbus').provider('vertxEventBus', function() { + var CONSTANTS, DEFAULT_OPTIONS, options; + CONSTANTS = { + MODULE: 'angular-vertxbus', + COMPONENT: 'wrapper' + }; + DEFAULT_OPTIONS = { + enabled: true, + debugEnabled: false, + prefix: 'vertx-eventbus.', + urlServer: "" + location.protocol + "//" + location.hostname + ":" + (location.port || 80), + urlPath: '/eventbus', + reconnectEnabled: true, + sockjsStateInterval: 10000, + sockjsReconnectInterval: 10000, + sockjsOptions: {}, + messageBuffer: 0 + }; + options = angular.extend({}, DEFAULT_OPTIONS); + this.enable = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.enabled; + } + options.enabled = value === true; + return this; + }; + this.enable.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.enable"; + this.useDebug = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.debugEnabled; + } + options.debugEnabled = value === true; + return this; + }; + this.useDebug.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useDebug"; + this.usePrefix = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.prefix; + } + options.prefix = value; + return this; + }; + this.usePrefix.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.usePrefix"; + this.useUrlServer = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.urlServer; + } + options.urlServer = value; + return this; + }; + this.useUrlServer.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useUrlServer"; + this.useUrlPath = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.urlPath; + } + options.urlPath = value; + return this; + }; + this.useUrlPath.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useUrlPath"; + this.useReconnect = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.reconnectEnabled; + } + options.reconnectEnabled = value; + return this; + }; + this.useReconnect.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useReconnect"; + this.useSockJsStateInterval = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.sockjsStateInterval; + } + options.sockjsStateInterval = value; + return this; + }; + this.useSockJsStateInterval.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsStateInterval"; + this.useSockJsReconnectInterval = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.sockjsReconnectInterval; + } + options.sockjsReconnectInterval = value; + return this; + }; + this.useSockJsReconnectInterval.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsReconnectInterval"; + this.useSockJsOptions = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.sockjsOptions; + } + options.sockjsOptions = value; + return this; + }; + this.useSockJsOptions.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useSockJsOptions"; + this.useMessageBuffer = function(value) { + if (value == null) { + value = DEFAULT_OPTIONS.messageBuffer; + } + options.messageBuffer = value; + return this; + }; + this.useMessageBuffer.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.useMessageBuffer"; + + /* A stub representing the VertX Event Bus (core functionality) Because the Event Bus cannot handle a reconnect (because of the underlaying SockJS), a new instance of the bus have to be created. @@ -127,100 +140,102 @@ define([ Furthermore, the stub supports theses extra APIs: - recconnect() - */ - this.$get = [ - '$timeout', - function ($timeout) { - var EventBus_, connect, debugEnabled, enabled, eventBus, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, stub, url, urlPath, urlServer, _ref; - _ref = angular.extend({}, DEFAULT_OPTIONS, options), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions; - stub = null; - EventBus_ = typeof vertx !== 'undefined' && vertx !== null ? vertx.EventBus : void 0; - if (enabled && EventBus_) { - url = '' + urlServer + urlPath; + */ + this.$get = ['$timeout', function($timeout) { + var EventBusOriginal, EventBusStub, connect, debugEnabled, enabled, eventBus, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, url, urlPath, urlServer, _ref; + _ref = angular.extend({}, DEFAULT_OPTIONS, options), enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions; + EventBusStub = null; + EventBusOriginal = typeof vertx !== "undefined" && vertx !== null ? vertx.EventBus : void 0; + if (enabled && EventBusOriginal) { + url = "" + urlServer + urlPath; + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Enabled: connecting '" + url + "'"); + } + eventBus = null; + connect = function() { + eventBus = new EventBusOriginal(url, void 0, sockjsOptions); + eventBus.onopen = function() { if (debugEnabled) { - console.debug('[VertX EventBus] Enabled: connecting \'' + url + '\''); + console.debug("[Vert.x EB Stub] Connected"); } - eventBus = null; - connect = function () { - eventBus = new EventBus_(url, void 0, sockjsOptions); - eventBus.onopen = function () { - if (debugEnabled) { - console.debug('[VertX EventBus] Connected'); - } - if (typeof stub.onopen === 'function') { - stub.onopen(); - } - }; - eventBus.onclose = function () { - if (debugEnabled) { - console.debug('[VertX EventBus] Reconnect in ' + sockjsReconnectInterval + 'ms'); - } - if (typeof stub.onclose === 'function') { - stub.onclose(); - } - if (reconnectEnabled) { - $timeout(connect, sockjsReconnectInterval); - } - }; - }; - connect(); - stub = { - reconnect: function () { - return eventBus.close(); - }, - close: function () { - return eventBus.close(); - }, - login: function (username, password, replyHandler) { - return eventBus.login(username, password, replyHandler); - }, - send: function (address, message, replyHandler) { - return eventBus.send(address, message, replyHandler); - }, - publish: function (address, message) { - return eventBus.publish(address, message); - }, - registerHandler: function (address, handler) { - var deconstructor; - eventBus.registerHandler(address, handler); - /* and return the deregister callback*/ - deconstructor = function () { - stub.unregisterHandler(address, handler); - }; - deconstructor.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.registerHandler (deconstructor)'; - return deconstructor; - }, - unregisterHandler: function (address, handler) { - return eventBus.unregisterHandler(address, handler); - }, - readyState: function () { - return eventBus.readyState(); - }, - EventBus: EventBus_, - getOptions: function () { - return angular.extend({}, options); - } - }; - stub.reconnect.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.reconnect'; - stub.close.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.close'; - stub.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.login'; - stub.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.send'; - stub.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.publish'; - stub.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.registerHandler'; - stub.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.unregisterHandler'; - stub.readyState.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.readyState'; - stub.getOptions.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': EventBusWrapper.getOptions'; - } else { + if (typeof EventBusStub.onopen === 'function') { + EventBusStub.onopen(); + } + }; + eventBus.onclose = function() { if (debugEnabled) { - console.debug('[VertX EventBus] Disabled'); + console.debug("[Vert.x EB Stub] Reconnect in " + sockjsReconnectInterval + "ms"); + } + if (typeof EventBusStub.onclose === 'function') { + EventBusStub.onclose(); } + if (reconnectEnabled) { + $timeout(connect, sockjsReconnectInterval); + } + }; + }; + connect(); + EventBusStub = { + reconnect: function() { + return eventBus.close(); + }, + close: function() { + return eventBus.close(); + }, + login: function(username, password, replyHandler) { + return eventBus.login(username, password, replyHandler); + }, + send: function(address, message, replyHandler) { + return eventBus.send(address, message, replyHandler); + }, + publish: function(address, message) { + return eventBus.publish(address, message); + }, + registerHandler: function(address, handler) { + var deconstructor; + eventBus.registerHandler(address, handler); + + /* and return the deregister callback */ + deconstructor = function() { + EventBusStub.unregisterHandler(address, handler); + }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.registerHandler (deconstructor)"; + return deconstructor; + }, + unregisterHandler: function(address, handler) { + return eventBus.unregisterHandler(address, handler); + }, + readyState: function() { + return eventBus.readyState(); + }, + + /* expose current used internal instance of actual EventBus */ + EventBus: EventBusOriginal, + getOptions: function() { + return angular.extend({}, options); } - return stub; + }; + EventBusStub.reconnect.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.reconnect"; + EventBusStub.close.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.close"; + EventBusStub.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.login"; + EventBusStub.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.send"; + EventBusStub.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.publish"; + EventBusStub.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.registerHandler"; + EventBusStub.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.unregisterHandler"; + EventBusStub.readyState.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.readyState"; + EventBusStub.getOptions.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": EventBusStub.getOptions"; + } else { + if (debugEnabled) { + console.debug("[Vert.x EB Stub] Disabled"); } - ]; - this.$get.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': initializer'; - }); - /* + } + return EventBusStub; + }]; + this.$get.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": Factory.get"; + }); + + + /* A service utilitzing an underlaying Vertx Event Bus The advanced features of this service are: @@ -238,423 +253,456 @@ define([ }); Note the additional configuration of the module itself. - */ - angular.module('knalli.angular-vertxbus').provider('vertxEventBusService', function () { - var CONSTANTS, DEFAULT_OPTIONS, MessageQueueHolder, SimpleMap, options; - CONSTANTS = { - MODULE: 'angular-vertxbus', - COMPONENT: 'service' + */ + + angular.module('knalli.angular-vertxbus').provider('vertxEventBusService', function() { + var CONSTANTS, DEFAULT_OPTIONS, Queue, SimpleMap, options; + CONSTANTS = { + MODULE: 'angular-vertxbus', + COMPONENT: 'service' + }; + DEFAULT_OPTIONS = { + loginRequired: false, + loginBlockForSession: false, + skipUnauthorizeds: true + }; + + /* + Simple queue implementation + + FIFO: #push() + #first() + LIFO: #push() + #last() + */ + Queue = (function() { + function Queue(maxSize) { + this.maxSize = maxSize != null ? maxSize : 10; + this.items = []; + } + + Queue.prototype.push = function(item) { + this.items.push(item); + return this.recalibrateBufferSize(); + }; + + Queue.prototype.recalibrateBufferSize = function() { + while (this.items.length > this.maxSize) { + this.first(); + } + return this; + }; + + Queue.prototype.last = function() { + return this.items.pop(); + }; + + Queue.prototype.first = function() { + return this.items.shift(0); + }; + + Queue.prototype.size = function() { + return this.items.length; + }; + + return Queue; + + })(); + + /* + Simple Map implementation + + This implementation allows usage of non serializable keys for values. + */ + SimpleMap = (function() { + SimpleMap.prototype.keys = null; + + SimpleMap.prototype.values = null; + + function SimpleMap() { + this.keys = []; + this.values = []; + } + + SimpleMap.prototype.put = function(key, value) { + var idx; + idx = this._indexForKey(key); + if (idx > -1) { + this.values[idx] = value; + } else { + this.keys.push(key); + this.values.push(value); + } + return this; + }; + + SimpleMap.prototype.get = function(key) { + var idx; + idx = this._indexForKey(key); + if (idx > -1) { + return this.values[idx]; + } + }; + + SimpleMap.prototype.containsKey = function(key) { + var idx; + idx = this._indexForKey(key); + return idx > -1; }; - DEFAULT_OPTIONS = { - loginRequired: false, - loginBlockForSession: false, - skipUnauthorizeds: true + + SimpleMap.prototype.containsValue = function(value) { + var idx; + idx = this._indexForValue(value); + return idx > -1; }; - MessageQueueHolder = function () { - function MessageQueueHolder(maxSize) { - this.maxSize = maxSize != null ? maxSize : 10; - this.items = []; + + SimpleMap.prototype.remove = function(key) { + var idx; + idx = this._indexForKey(key); + if (idx > -1) { + this.keys[idx] = void 0; + this.values[idx] = void 0; } - MessageQueueHolder.prototype.push = function (item) { - this.items.push(item); - return this.recalibrateBufferSize(); - }; - MessageQueueHolder.prototype.recalibrateBufferSize = function () { - while (this.items.length > this.maxSize) { - this.first(); + }; + + SimpleMap.prototype.clear = function() { + this.keys = []; + this.values = []; + return this; + }; + + SimpleMap.prototype._indexForKey = function(key) { + var i, k, _i, _len, _ref; + _ref = this.keys; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + k = _ref[i]; + if (key === k) { + return i; } - return this; - }; - MessageQueueHolder.prototype.last = function () { - return this.items.pop(); - }; - MessageQueueHolder.prototype.first = function () { - return this.items.shift(0); - }; - MessageQueueHolder.prototype.size = function () { - return this.items.length; - }; - return MessageQueueHolder; - }(); - SimpleMap = function () { - SimpleMap.prototype.keys = null; - SimpleMap.prototype.values = null; - function SimpleMap() { - this.keys = []; - this.values = []; } - SimpleMap.prototype.put = function (key, value) { - var idx; - idx = this._indexForKey(key); - if (idx > -1) { - this.values[idx] = value; - } else { - this.keys.push(key); - this.values.push(value); + return -1; + }; + + SimpleMap.prototype._indexForValue = function(value) { + var i, v, _i, _len, _ref; + _ref = this.values; + for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { + v = _ref[i]; + if (value === v) { + return i; } - return this; - }; - SimpleMap.prototype._indexForKey = function (key) { - var i, k, _i, _len, _ref; - _ref = this.keys; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - k = _ref[i]; - if (key === k) { - return i; + } + return -1; + }; + + return SimpleMap; + + })(); + options = angular.extend({}, DEFAULT_OPTIONS); + this.requireLogin = function(value) { + if (value == null) { + value = options.loginRequired; + } + options.loginRequired = value; + return this; + }; + this.requireLogin.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.requireLogin"; + this.blockForSession = function(value) { + if (value == null) { + value = options.loginBlockForSession; + } + options.loginBlockForSession = value; + return this; + }; + this.blockForSession.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.blockForSession"; + this.skipUnauthorizeds = function(value) { + if (value == null) { + value = options.skipUnauthorizeds; + } + options.skipUnauthorizeds = value; + return this; + }; + this.skipUnauthorizeds.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.skipUnauthorizeds"; + this.$get = ['$rootScope', '$q', '$interval', '$timeout', 'vertxEventBus', function($rootScope, $q, $interval, $timeout, vertxEventBus) { + var connectionIntervalCheck, connectionState, debugEnabled, deconstructors, enabled, ensureOpenAuthConnection, ensureOpenConnection, loginPromise, messageBuffer, messageQueue, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; + _ref = (vertxEventBus != null ? vertxEventBus.getOptions() : void 0) || {}, enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions, messageBuffer = _ref.messageBuffer; + connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0; + validSession = false; + loginPromise = null; + messageQueue = new Queue(messageBuffer); + deconstructors = new SimpleMap(); + if (enabled && vertxEventBus) { + vertxEventBus.onopen = function() { + var address, callback, callbacks, fn, _i, _len, _ref2; + wrapped.getConnectionState(true); + $rootScope.$broadcast("" + prefix + "system.connected"); + _ref2 = wrapped.handlers; + for (address in _ref2) { + if (!__hasProp.call(_ref2, address)) continue; + callbacks = _ref2[address]; + for (_i = 0, _len = callbacks.length; _i < _len; _i++) { + callback = callbacks[_i]; + util.registerHandler(address, callback); } } - return -1; - }; - SimpleMap.prototype._indexForValue = function (value) { - var i, v, _i, _len, _ref; - _ref = this.values; - for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { - v = _ref[i]; - if (value === v) { - return i; + $rootScope.$digest(); + if (messageBuffer && messageQueue.size()) { + while (messageQueue.size()) { + fn = messageQueue.first(); + if (typeof fn === 'function') { + fn(); + } } + $rootScope.$digest(); } - return -1; - }; - SimpleMap.prototype.containsKey = function (key) { - var idx; - idx = this._indexForKey(key); - return idx > -1; - }; - SimpleMap.prototype.containsValue = function (value) { - var idx; - idx = this._indexForValue(value); - return idx > -1; - }; - SimpleMap.prototype.get = function (key) { - var idx; - idx = this._indexForKey(key); - if (idx > -1) { - return this.values[idx]; - } - return void 0; }; - SimpleMap.prototype.remove = function (key) { - var idx; - idx = this._indexForKey(key); - if (idx > -1) { - this.keys[idx] = void 0; - this.values[idx] = void 0; - } - return void 0; + vertxEventBus.onclose = function() { + wrapped.getConnectionState(true); + return $rootScope.$broadcast("" + prefix + "system.disconnected"); }; - SimpleMap.prototype.clear = function () { - this.keys = []; - this.values = []; - return this; - }; - return SimpleMap; - }(); - options = angular.extend({}, DEFAULT_OPTIONS); - this.requireLogin = function (value) { - if (value == null) { - value = options.loginRequired; + vertxEventBus.onclose.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": 'onclose' handler"; + } + ensureOpenConnection = function(fn) { + if (wrapped.getConnectionState() === vertxEventBus.EventBus.OPEN) { + fn(); + return true; + } else if (messageBuffer) { + messageQueue.push(fn); + return true; } - options.loginRequired = value; - return this; + return false; }; - this.requireLogin.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': requireLogin'; - this.blockForSession = function (value) { - if (value == null) { - value = options.loginBlockForSession; - } - options.loginBlockForSession = value; - return this; - }; - this.blockForSession.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': blockForSession'; - this.skipUnauthorizeds = function (value) { - if (value == null) { - value = options.skipUnauthorizeds; - } - options.skipUnauthorizeds = value; - return this; - }; - this.skipUnauthorizeds.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': skipUnauthorizeds'; - this.$get = [ - '$rootScope', - '$q', - '$interval', - '$timeout', - 'vertxEventBus', - function ($rootScope, $q, $interval, $timeout, vertxEventBus) { - var connectionIntervalCheck, connectionState, debugEnabled, enabled, ensureOpenAuthConnection, ensureOpenConnection, fnWrapperMap, loginPromise, messageBuffer, messageQueueHolder, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; - _ref = (vertxEventBus != null ? vertxEventBus.getOptions() : void 0) || {}, enabled = _ref.enabled, debugEnabled = _ref.debugEnabled, prefix = _ref.prefix, urlServer = _ref.urlServer, urlPath = _ref.urlPath, reconnectEnabled = _ref.reconnectEnabled, sockjsStateInterval = _ref.sockjsStateInterval, sockjsReconnectInterval = _ref.sockjsReconnectInterval, sockjsOptions = _ref.sockjsOptions, messageBuffer = _ref.messageBuffer; - connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0; - validSession = false; - loginPromise = null; - messageQueueHolder = new MessageQueueHolder(messageBuffer); - fnWrapperMap = new SimpleMap(); - if (enabled && vertxEventBus) { - vertxEventBus.onopen = function () { - var address, callback, callbacks, fn, _i, _len, _ref2; - wrapped.getConnectionState(true); - $rootScope.$broadcast('' + prefix + 'system.connected'); - _ref2 = wrapped.handlers; - for (address in _ref2) { - if (!__hasProp.call(_ref2, address)) - continue; - callbacks = _ref2[address]; - for (_i = 0, _len = callbacks.length; _i < _len; _i++) { - callback = callbacks[_i]; - util.registerHandler(address, callback); - } - } - $rootScope.$digest(); - if (messageBuffer && messageQueueHolder.size()) { - while (messageQueueHolder.size()) { - fn = messageQueueHolder.first(); - if (typeof fn === 'function') { - fn(); - } - } - $rootScope.$digest(); - } - }; - vertxEventBus.onclose = function () { - wrapped.getConnectionState(true); - return $rootScope.$broadcast('' + prefix + 'system.disconnected'); - }; - vertxEventBus.onclose.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': \'onclose\' handler'; - } - ensureOpenConnection = function (fn) { - if (wrapped.getConnectionState() === vertxEventBus.EventBus.OPEN) { + ensureOpenConnection.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenConnection"; + ensureOpenAuthConnection = function(fn) { + var wrapFn; + if (!options.loginRequired) { + return ensureOpenConnection(fn); + } else { + wrapFn = function() { + if (validSession) { fn(); return true; - } else if (messageBuffer) { - messageQueueHolder.push(fn); - return true; - } - return false; - }; - ensureOpenConnection.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenConnection'; - ensureOpenAuthConnection = function (fn) { - var wrapFn; - if (!options.loginRequired) { - return ensureOpenConnection(fn); } else { - wrapFn = function () { - if (validSession) { - fn(); - return true; - } else { - if (debugEnabled) { - console.debug('[VertX EB Service] Message was not sent because login is required'); - } - return false; - } - }; - wrapFn.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenAuthConnection function wrapper'; - return ensureOpenConnection(wrapFn); - } - }; - ensureOpenAuthConnection.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': ensureOpenAuthConnection'; - util = { - registerHandler: function (address, callback) { - var deconstructor; - if (typeof callback !== 'function') { - return; - } if (debugEnabled) { - console.debug('[VertX EB Service] Register handler for ' + address); - } - if (fnWrapperMap.containsKey(callback)) { - return fnWrapperMap.get(callback); - } - deconstructor = function (message, replyTo) { - callback(message, replyTo); - return $rootScope.$digest(); - }; - deconstructor.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.registerHandler (deconstructor)'; - fnWrapperMap.put(callback, deconstructor); - return vertxEventBus.registerHandler(address, fnWrapperMap.get(callback)); - }, - unregisterHandler: function (address, callback) { - if (typeof callback !== 'function') { - return; + console.debug("[Vert.x EB Service] Message was not sent because login is required"); } - if (debugEnabled) { - console.debug('[VertX EB Service] Unregister handler for ' + address); - } - vertxEventBus.unregisterHandler(address, fnWrapperMap.get(callback)); - fnWrapperMap.remove(callback); - }, - send: function (address, message, timeout) { - var deferred, dispatched, next; - if (timeout == null) { - timeout = 10000; - } - deferred = $q.defer(); - next = function () { - vertxEventBus.send(address, message, function (reply) { - if (deferred) { - return deferred.resolve(reply); - } - }); - if (deferred) { - return $timeout(function () { - return deferred.reject(); - }, timeout); - } - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.send (ensureOpenAuthConnection callback)'; - dispatched = ensureOpenAuthConnection(next); - if (deferred && !dispatched) { - deferred.reject(); - } - return deferred != null ? deferred.promise : void 0; - }, - publish: function (address, message) { - var dispatched, next; - next = function () { - return vertxEventBus.publish(address, message); - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.publish (ensureOpenAuthConnection callback)'; - dispatched = ensureOpenAuthConnection(next); - return dispatched; - }, - login: function (username, password, timeout) { - var deferred, next; - if (timeout == null) { - timeout = 5000; + return false; + } + }; + wrapFn.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenAuthConnection function wrapper"; + return ensureOpenConnection(wrapFn); + } + }; + ensureOpenAuthConnection.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": ensureOpenAuthConnection"; + util = { + registerHandler: function(address, callback) { + var deconstructor; + if (typeof callback !== 'function') { + return; + } + if (debugEnabled) { + console.debug("[Vert.x EB Service] Register handler for " + address); + } + if (deconstructors.containsKey(callback)) { + return deconstructors.get(callback); + } + deconstructor = function(message, replyTo) { + callback(message, replyTo); + $rootScope.$digest(); + }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.registerHandler (deconstructor)"; + deconstructors.put(callback, deconstructor); + return vertxEventBus.registerHandler(address, deconstructors.get(callback)); + }, + unregisterHandler: function(address, callback) { + if (typeof callback !== 'function') { + return; + } + if (debugEnabled) { + console.debug("[Vert.x EB Service] Unregister handler for " + address); + } + vertxEventBus.unregisterHandler(address, deconstructors.get(callback)); + deconstructors.remove(callback); + }, + send: function(address, message, timeout) { + var deferred, dispatched, next; + if (timeout == null) { + timeout = 10000; + } + deferred = $q.defer(); + next = function() { + vertxEventBus.send(address, message, function(reply) { + if (deferred) { + return deferred.resolve(reply); } - deferred = $q.defer(); - next = function (reply) { - if ((reply != null ? reply.status : void 0) === 'ok') { - deferred.resolve(reply); - return $rootScope.$broadcast('' + prefix + 'system.login.succeeded', { status: reply != null ? reply.status : void 0 }); - } else { - deferred.reject(reply); - return $rootScope.$broadcast('' + prefix + 'system.login.failed', { status: reply != null ? reply.status : void 0 }); - } - }; - next.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.login (callback)'; - vertxEventBus.login(username, password, next); - $timeout(function () { + }); + if (deferred) { + return $timeout((function() { return deferred.reject(); - }, timeout); - return deferred.promise; + }), timeout); } }; - util.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.registerHandler'; - util.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.unregisterHandler'; - util.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.send'; - util.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.publish'; - util.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': util.login'; - wrapped = { - handlers: {}, - registerHandler: function (address, callback) { - var unregisterFn; - if (!wrapped.handlers[address]) { - wrapped.handlers[address] = []; - } - wrapped.handlers[address].push(callback); - unregisterFn = null; - if (connectionState === vertxEventBus.EventBus.OPEN) { - unregisterFn = util.registerHandler(address, callback); - } - /* and return the deregister callback*/ - return function () { - var index; - if (unregisterFn) { - unregisterFn(); - } - if (wrapped.handlers[address]) { - index = wrapped.handlers[address].indexOf(callback); - if (index > -1) { - wrapped.handlers[address].splice(index, 1); - } - } - }; - }, - unregisterHandler: function (address, callback) { - var index; - if (wrapped.handlers[address]) { - index = wrapped.handlers[address].indexOf(callback); - if (index > -1) { - wrapped.handlers[address].splice(index, 1); - } - } - if (connectionState === vertxEventBus.EventBus.OPEN) { - return util.unregisterHandler(address, callback); - } - }, - send: function (address, message, timeout) { - if (timeout == null) { - timeout = 10000; - } - return util.send(address, message, timeout); - }, - publish: function (address, message) { - return util.publish(address, message); - }, - getConnectionState: function (immediate) { - if (vertxEventBus != null ? vertxEventBus.EventBus : void 0) { - if (enabled) { - if (immediate) { - connectionState = vertxEventBus.readyState(); - } - } else { - connectionState = vertxEventBus.EventBus.CLOSED; - } - } else { - connectionState = 3; - } - return connectionState; - }, - isValidSession: function () { - return validSession; - }, - login: function (username, password) { - return util.login(username, password).then(function (reply) { - validSession = true; - return reply; - })['catch'](function (reply) { - validSession = false; - return reply; + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.send (ensureOpenAuthConnection callback)"; + dispatched = ensureOpenAuthConnection(next); + if (deferred && !dispatched) { + deferred.reject(); + } + return deferred != null ? deferred.promise : void 0; + }, + publish: function(address, message) { + var dispatched, next; + next = function() { + return vertxEventBus.publish(address, message); + }; + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.publish (ensureOpenAuthConnection callback)"; + dispatched = ensureOpenAuthConnection(next); + return dispatched; + }, + login: function(username, password, timeout) { + var deferred, next; + if (timeout == null) { + timeout = 5000; + } + deferred = $q.defer(); + next = function(reply) { + if ((reply != null ? reply.status : void 0) === 'ok') { + deferred.resolve(reply); + return $rootScope.$broadcast("" + prefix + "system.login.succeeded", { + status: reply != null ? reply.status : void 0 + }); + } else { + deferred.reject(reply); + return $rootScope.$broadcast("" + prefix + "system.login.failed", { + status: reply != null ? reply.status : void 0 }); } }; - wrapped.registerHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.registerHandler'; - wrapped.unregisterHandler.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.unregisterHandler'; - wrapped.send.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.send'; - wrapped.publish.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.publish'; - wrapped.getConnectionState.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.getConnectionState'; - wrapped.isValidSession.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.isValidSession'; - wrapped.login.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': wrapped.login'; - connectionIntervalCheck = function () { - return wrapped.getConnectionState(true); - }; - connectionIntervalCheck.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': periodic connection check'; - $interval(connectionIntervalCheck, sockjsStateInterval); - /* building and exposing the actual service API*/ - return { - on: wrapped.registerHandler, - addListener: wrapped.registerHandler, - un: wrapped.unregisterHandler, - removeListener: wrapped.unregisterHandler, - send: wrapped.send, - publish: wrapped.publish, - emit: wrapped.publish, - readyState: wrapped.getConnectionState, - isEnabled: function () { - return enabled; - }, - getBufferCount: function () { - return messageQueueHolder.size(); - }, - isValidSession: function () { - return validSession; - }, - login: wrapped.login + next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.login (callback)"; + vertxEventBus.login(username, password, next); + $timeout((function() { + return deferred.reject(); + }), timeout); + return deferred.promise; + } + }; + util.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.registerHandler"; + util.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.unregisterHandler"; + util.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.send"; + util.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.publish"; + util.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.login"; + wrapped = { + handlers: {}, + registerHandler: function(address, callback) { + var deconstructor, unregisterFn; + if (!wrapped.handlers[address]) { + wrapped.handlers[address] = []; + } + wrapped.handlers[address].push(callback); + unregisterFn = null; + if (connectionState === vertxEventBus.EventBus.OPEN) { + unregisterFn = util.registerHandler(address, callback); + } + + /* and return the deregister callback */ + deconstructor = function() { + var index; + if (unregisterFn) { + unregisterFn(); + } + if (wrapped.handlers[address]) { + index = wrapped.handlers[address].indexOf(callback); + if (index > -1) { + wrapped.handlers[address].splice(index, 1); + } + } }; + deconstructor.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.registerHandler (deconstructor)"; + return deconstructor; + }, + unregisterHandler: function(address, callback) { + var index; + if (wrapped.handlers[address]) { + index = wrapped.handlers[address].indexOf(callback); + if (index > -1) { + wrapped.handlers[address].splice(index, 1); + } + } + if (connectionState === vertxEventBus.EventBus.OPEN) { + return util.unregisterHandler(address, callback); + } + }, + send: function(address, message, timeout) { + if (timeout == null) { + timeout = 10000; + } + return util.send(address, message, timeout); + }, + publish: function(address, message) { + return util.publish(address, message); + }, + getConnectionState: function(immediate) { + if (vertxEventBus != null ? vertxEventBus.EventBus : void 0) { + if (enabled) { + if (immediate) { + connectionState = vertxEventBus.readyState(); + } + } else { + connectionState = vertxEventBus.EventBus.CLOSED; + } + } else { + connectionState = 3; + } + return connectionState; + }, + isValidSession: function() { + return validSession; + }, + login: function(username, password) { + return util.login(username, password).then(function(reply) { + validSession = true; + return reply; + })["catch"](function(reply) { + validSession = false; + return reply; + }); } - ]; - this.$get.displayName = '' + CONSTANTS.MODULE + '/' + CONSTANTS.COMPONENT + ': initializer'; - }); - }.call(this)); + }; + wrapped.registerHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.registerHandler"; + wrapped.unregisterHandler.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.unregisterHandler"; + wrapped.send.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.send"; + wrapped.publish.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.publish"; + wrapped.getConnectionState.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.getConnectionState"; + wrapped.isValidSession.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.isValidSession"; + wrapped.login.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": wrapped.login"; + connectionIntervalCheck = function() { + return wrapped.getConnectionState(true); + }; + connectionIntervalCheck.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": periodic connection check"; + $interval(connectionIntervalCheck, sockjsStateInterval); + + /* building and exposing the actual service API */ + return { + on: wrapped.registerHandler, + addListener: wrapped.registerHandler, + un: wrapped.unregisterHandler, + removeListener: wrapped.unregisterHandler, + send: wrapped.send, + publish: wrapped.publish, + emit: wrapped.publish, + readyState: wrapped.getConnectionState, + isEnabled: function() { + return enabled; + }, + getBufferCount: function() { + return messageQueue.size(); + }, + isValidSession: function() { + return validSession; + }, + login: wrapped.login + }; + }]; + this.$get.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": Factory.get"; + }); + +}).call(this); + }); \ No newline at end of file