|
48 | 48 | // this.buffer = [];
|
49 | 49 |
|
50 | 50 | // TODO: refactor options to use isDefined
|
51 |
| - this.scope = options && options.scope || $rootScope; |
52 |
| - this.rootScopeFailover = options && options.rootScopeFailover && true; |
53 |
| - this.useApplyAsync = options && options.useApplyAsync || false; |
54 |
| - this._reconnectAttempts = options && options.reconnectAttempts || 0; |
55 |
| - this.initialTimeout = options && options.initialTimeout || 500; // 500ms |
56 |
| - this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes |
57 |
| - this.alwaysReconnect = options && options.alwaysReconnect || false; |
| 51 | + this.scope = options && options.scope || $rootScope; |
| 52 | + this.rootScopeFailover = options && options.rootScopeFailover && true; |
| 53 | + this.useApplyAsync = options && options.useApplyAsync || false; |
| 54 | + this._reconnectAttempts = options && options.reconnectAttempts || 0; |
| 55 | + this.initialTimeout = options && options.initialTimeout || 500; // 500ms |
| 56 | + this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes |
| 57 | + this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false; |
58 | 58 |
|
59 | 59 | this.sendQueue = [];
|
60 | 60 | this.onOpenCallbacks = [];
|
|
72 | 72 |
|
73 | 73 | }
|
74 | 74 |
|
| 75 | + |
75 | 76 | $WebSocket.prototype._readyStateConstants = {
|
76 | 77 | 'CONNECTING': 0,
|
77 | 78 | 'OPEN': 1,
|
|
80 | 81 | 'RECONNECT_ABORTED': 4
|
81 | 82 | };
|
82 | 83 |
|
| 84 | + $WebSocket.prototype._normalCloseCode = 1000; |
| 85 | + |
83 | 86 | $WebSocket.prototype._reconnectableStatusCodes = [
|
84 | 87 | 4000
|
85 | 88 | ];
|
|
183 | 186 |
|
184 | 187 | $WebSocket.prototype._onCloseHandler = function _onCloseHandler(event) {
|
185 | 188 | this.notifyCloseCallbacks(event);
|
186 |
| - if (this.alwaysReconnect || this._reconnectableStatusCodes.indexOf(event.code) > -1) { |
| 189 | + if ((this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1) { |
187 | 190 | this.reconnect();
|
188 | 191 | }
|
189 | 192 | };
|
|
0 commit comments