Skip to content

Commit d20de88

Browse files
committed
Updated the option to allow it to reconnect only if it wasn't a normal close
1 parent 18d2cb4 commit d20de88

9 files changed

+91
-43
lines changed

angular-websocket.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@
4848
// this.buffer = [];
4949

5050
// 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;
5858

5959
this.sendQueue = [];
6060
this.onOpenCallbacks = [];
@@ -72,6 +72,7 @@
7272

7373
}
7474

75+
7576
$WebSocket.prototype._readyStateConstants = {
7677
'CONNECTING': 0,
7778
'OPEN': 1,
@@ -80,6 +81,8 @@
8081
'RECONNECT_ABORTED': 4
8182
};
8283

84+
$WebSocket.prototype._normalCloseCode = 1000;
85+
8386
$WebSocket.prototype._reconnectableStatusCodes = [
8487
4000
8588
];
@@ -183,7 +186,7 @@
183186

184187
$WebSocket.prototype._onCloseHandler = function _onCloseHandler(event) {
185188
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) {
187190
this.reconnect();
188191
}
189192
};

angular-websocket.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)