|
1 | | -/*! angular-vertxbus - v0.11.2 - 2015-01-16 |
| 1 | +/*! angular-vertxbus - v1.0.0 - 2015-03-01 |
2 | 2 | * http://github.com/knalli/angular-vertxbus |
3 | 3 | * Copyright (c) 2015 ; Licensed */ |
4 | 4 | (function() { |
|
31 | 31 | enabled: true, |
32 | 32 | debugEnabled: false, |
33 | 33 | prefix: 'vertx-eventbus.', |
34 | | - urlServer: "" + location.protocol + "//" + location.hostname + ":" + (location.port || 80), |
| 34 | + urlServer: "" + location.protocol + "//" + location.hostname + (location.port ? ':' + location.port : ''), |
35 | 35 | urlPath: '/eventbus', |
36 | 36 | reconnectEnabled: true, |
37 | 37 | sockjsStateInterval: 10000, |
|
419 | 419 | return this; |
420 | 420 | }; |
421 | 421 | this.skipUnauthorizeds.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": provider.skipUnauthorizeds"; |
422 | | - this.$get = ['$rootScope', '$q', '$interval', '$timeout', 'vertxEventBus', '$log', function($rootScope, $q, $interval, $timeout, vertxEventBus, $log) { |
423 | | - var callbackMap, connectionIntervalCheck, connectionState, debugEnabled, enabled, ensureOpenAuthConnection, ensureOpenConnection, loginPromise, messageBuffer, messageQueue, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; |
| 422 | + this.$get = ['$rootScope', '$q', '$interval', 'vertxEventBus', '$log', function($rootScope, $q, $interval, vertxEventBus, $log) { |
| 423 | + var callbackMap, connectionIntervalCheck, connectionState, debugEnabled, enabled, ensureOpenAuthConnection, ensureOpenConnection, loginPromise, messageBuffer, messageQueue, prefix, reconnectEnabled, sockjsOptions, sockjsReconnectInterval, sockjsStateInterval, states, urlPath, urlServer, util, validSession, wrapped, _ref, _ref1; |
424 | 424 | _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; |
425 | 425 | connectionState = vertxEventBus != null ? (_ref1 = vertxEventBus.EventBus) != null ? _ref1.CLOSED : void 0 : void 0; |
426 | 426 | validSession = false; |
427 | 427 | loginPromise = null; |
428 | 428 | messageQueue = new Queue(messageBuffer); |
429 | 429 | callbackMap = new SimpleMap(); |
| 430 | + states = { |
| 431 | + connected: false |
| 432 | + }; |
430 | 433 | if (enabled && vertxEventBus) { |
431 | 434 | vertxEventBus.onopen = function() { |
432 | 435 | var address, callback, callbacks, fn, _i, _len, _ref2; |
433 | 436 | wrapped.getConnectionState(true); |
434 | | - $rootScope.$broadcast("" + prefix + "system.connected"); |
| 437 | + if (!states.connected) { |
| 438 | + states.connected = true; |
| 439 | + $rootScope.$broadcast("" + prefix + "system.connected"); |
| 440 | + } |
435 | 441 | _ref2 = wrapped.handlers; |
436 | 442 | for (address in _ref2) { |
437 | 443 | if (!__hasProp.call(_ref2, address)) continue; |
|
456 | 462 | }; |
457 | 463 | vertxEventBus.onclose = function() { |
458 | 464 | wrapped.getConnectionState(true); |
459 | | - return $rootScope.$broadcast("" + prefix + "system.disconnected"); |
| 465 | + if (states.connected) { |
| 466 | + states.connected = false; |
| 467 | + return $rootScope.$broadcast("" + prefix + "system.disconnected"); |
| 468 | + } |
460 | 469 | }; |
461 | 470 | vertxEventBus.onclose.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": 'onclose' handler"; |
462 | 471 | } |
|
532 | 541 | } |
533 | 542 | }); |
534 | 543 | if (deferred) { |
535 | | - return $timeout((function() { |
| 544 | + return $interval((function() { |
536 | 545 | return deferred.reject(); |
537 | | - }), timeout); |
| 546 | + }), timeout, 1); |
538 | 547 | } |
539 | 548 | }; |
540 | 549 | next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.send (ensureOpenAuthConnection callback)"; |
|
574 | 583 | }; |
575 | 584 | next.displayName = "" + CONSTANTS.MODULE + "/" + CONSTANTS.COMPONENT + ": util.login (callback)"; |
576 | 585 | vertxEventBus.login(username, password, next); |
577 | | - $timeout((function() { |
| 586 | + $interval((function() { |
578 | 587 | return deferred.reject(); |
579 | | - }), timeout); |
| 588 | + }), timeout, 1); |
580 | 589 | return deferred.promise; |
581 | 590 | } |
582 | 591 | }; |
|
0 commit comments