resilient-websocket
Advanced tools
Comparing version 1.0.4 to 1.0.6
@@ -13,2 +13,3 @@ export interface OnCallback { | ||
pongMessage?: string | object; | ||
reconnectOnError?: boolean; | ||
} | ||
@@ -21,3 +22,4 @@ export declare const defaultOptions: ResilientWebSocketOptions; | ||
CLOSE = "close", | ||
PONG = "pong" | ||
PONG = "pong", | ||
ERROR = "error" | ||
} | ||
@@ -38,2 +40,3 @@ export interface WebSocketFactory { | ||
send: (data: any) => void; | ||
close: () => void; | ||
on: (event: WebSocketEvent, callback: OnCallback) => void; | ||
@@ -47,3 +50,4 @@ private respondToCallbacks; | ||
private onClose; | ||
private onError; | ||
} | ||
export default ResilientWebSocket; |
@@ -23,2 +23,3 @@ "use strict"; | ||
pongMessage: 'PONG', | ||
reconnectOnError: true | ||
}; | ||
@@ -32,2 +33,3 @@ var WebSocketEvent; | ||
WebSocketEvent["PONG"] = "pong"; | ||
WebSocketEvent["ERROR"] = "error"; | ||
})(WebSocketEvent = exports.WebSocketEvent || (exports.WebSocketEvent = {})); | ||
@@ -46,2 +48,3 @@ var WebSocketFactory = function (url) { return new WebSocket(url); }; | ||
socket.addEventListener('close', _this.onClose); | ||
socket.addEventListener('error', _this.onError); | ||
return socket; | ||
@@ -52,2 +55,7 @@ }; | ||
}; | ||
this.close = function () { | ||
clearTimeout(_this.pongTimeout); | ||
clearInterval(_this.pingTimeout); | ||
_this.socket.close(); | ||
}; | ||
this.on = function (event, callback) { | ||
@@ -107,2 +115,8 @@ var callbackList = _this.callbacks.get(event); | ||
}; | ||
this.onError = function () { | ||
_this.respondToCallbacks(WebSocketEvent.ERROR, _this); | ||
if (_this.options.reconnectOnError) { | ||
_this.onClose(); | ||
} | ||
}; | ||
this.url = url; | ||
@@ -109,0 +123,0 @@ this.options = __assign({}, exports.defaultOptions, options); |
{ | ||
"name": "resilient-websocket", | ||
"version": "1.0.4", | ||
"version": "1.0.6", | ||
"description": "A client WebSocket wrapper with support for reconnection and ping/pong", | ||
@@ -5,0 +5,0 @@ "main": "dist/ResilientWebSocket.js", |
28612
13
205