Skip to content

Commit b5a880e

Browse files
committed
Merge pull request #31 from Jakobud/feature/default-close-code
Default 1000 closing code added
2 parents 592c441 + 65c6cd0 commit b5a880e

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

reconnecting-websocket.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
* onopen // sometime later...
4141
* onmessage
4242
* onmessage
43-
* etc...
43+
* etc...
4444
*
4545
* It is API compatible with the standard WebSocket API, apart from the following members:
4646
*
@@ -124,7 +124,7 @@
124124
if (self.debug || ReconnectingWebSocket.debugAll) {
125125
console.debug('ReconnectingWebSocket', 'attempt-connect', url);
126126
}
127-
127+
128128
var localWs = ws;
129129
var timeout = setTimeout(function() {
130130
if (self.debug || ReconnectingWebSocket.debugAll) {
@@ -134,7 +134,7 @@
134134
localWs.close();
135135
timedOut = false;
136136
}, self.timeoutInterval);
137-
137+
138138
ws.onopen = function(event) {
139139
clearTimeout(timeout);
140140
if (self.debug || ReconnectingWebSocket.debugAll) {
@@ -148,7 +148,7 @@
148148
reconnectAttempt = false;
149149
eventTarget.dispatchEvent(e);
150150
};
151-
151+
152152
ws.onclose = function(event) {
153153
clearTimeout(timeout);
154154
ws = null;
@@ -209,6 +209,10 @@
209209
* If the connection is already CLOSED, this method does nothing.
210210
*/
211211
this.close = function(code, reason) {
212+
// Default CLOSE_NORMAL code
213+
if (typeof code == 'undefined') {
214+
code = 1000;
215+
}
212216
forcedClose = true;
213217
if (ws) {
214218
ws.close(code, reason);

0 commit comments

Comments
 (0)