Add the socket connection checker

pull/1/head
Yann Flory 9 years ago
parent 1c54af69a1
commit deb2084fc5

@ -1025,12 +1025,6 @@ return /******/ (function(modules) { // webpackBootstrap
this.protocol = _ServiceProvider2.default.get(cs.EXCHANGEPROTOCOL_SERVICE); this.protocol = _ServiceProvider2.default.get(cs.EXCHANGEPROTOCOL_SERVICE);
this.defaults = { this.defaults = {
signaling: 'ws://localhost:9000', signaling: 'ws://localhost:9000',
/**
* If an error is encountered but it is recoverable, do not immediately fail
* but if it keeps firing errors over and over, do fail.
*/
recoverableErrorCount: 0,
MAX_RECOVERABLE_ERRORS: 15,
// Maximum number of milliseconds of lag before we fail the connection. // Maximum number of milliseconds of lag before we fail the connection.
MAX_LAG_BEFORE_DISCONNECT: 20000 MAX_LAG_BEFORE_DISCONNECT: 20000
}; };
@ -1040,6 +1034,8 @@ return /******/ (function(modules) { // webpackBootstrap
_createClass(WebSocketService, [{ _createClass(WebSocketService, [{
key: 'join', key: 'join',
value: function join(key) { value: function join(key) {
var _this = this;
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var settings = Object.assign({}, this.settings, options); var settings = Object.assign({}, this.settings, options);
@ -1051,24 +1047,19 @@ return /******/ (function(modules) { // webpackBootstrap
resolve(socket); resolve(socket);
}; };
socket.onerror = reject; socket.onerror = reject;
}); // Check the status of the socket connection
} var isSocketDisconnected = function isSocketDisconnected(realtime, sock) {
return sock.readyState === sock.CLOSING || sock.readyState === sock.CLOSED || realtime.getLag().waiting && realtime.getLag().lag > _this.settings.MAX_LAG_BEFORE_DISCONNECT;
// Check the status of the socket connection };
/*var isSocketDisconnected = function (realtime) { socket.checkSocket = function (realtime) {
let sock = ws._socket; if (isSocketDisconnected(realtime, socket) && !socket.intentionallyClosing) {
return sock.readyState === sock.CLOSING
|| sock.readyState === sock.CLOSED
|| (realtime.getLag().waiting && realtime.getLag().lag > MAX_LAG_BEFORE_DISCONNECT);
}
var checkSocket = module.exports.checkSocket = function (realtime) {
if (isSocketDisconnected(realtime) && !socket.intentionallyClosing) {
return true; return true;
} else { } else {
return false; return false;
} }
};*/ };
});
}
}]); }]);
return WebSocketService; return WebSocketService;

@ -31,7 +31,7 @@ define([
var debug = function (x) { console.log(x); }, var debug = function (x) { console.log(x); },
warn = function (x) { console.error(x); }, warn = function (x) { console.error(x); },
verbose = function (x) { console.log(x); }; verbose = function (x) { console.log(x); };
// verbose = function () {}; // comment out to enable verbose logging verbose = function () {}; // comment out to enable verbose logging
// ------------------ Trapping Keyboard Events ---------------------- // // ------------------ Trapping Keyboard Events ---------------------- //
@ -130,7 +130,7 @@ define([
}); });
// Check the connection to the channel // Check the connection to the channel
//checkConnection(wc); checkConnection(wc);
bindAllEvents(textarea, doc, onEvent, false); bindAllEvents(textarea, doc, onEvent, false);
@ -202,31 +202,32 @@ define([
} }
var checkConnection = function(wc) { var checkConnection = function(wc) {
//TODO if(wc.channels && wc.channels.size > 0) {
/*var socketChecker = setInterval(function () { var channels = Array.from(wc.channels);
if (netflux.checkSocket(realtime)) { var channel = channels[0];
warn("Socket disconnected!");
var socketChecker = setInterval(function () {
recoverableErrorCount += 1; if (channel.checkSocket(realtime)) {
warn("Socket disconnected!");
if (recoverableErrorCount >= MAX_RECOVERABLE_ERRORS) {
warn("Giving up!"); recoverableErrorCount += 1;
realtime.abort();
wc.leave() if (recoverableErrorCount >= MAX_RECOVERABLE_ERRORS) {
.then(null, function(err) { warn("Giving up!");
warn(err); realtime.abort();
}); try { channel.close(); } catch (e) { warn(e); }
if (config.onAbort) { if (config.onAbort) {
config.onAbort({ config.onAbort({
socket: socket socket: channel
}); });
}
if (socketChecker) { clearInterval(socketChecker); }
} }
if (socketChecker) { clearInterval(socketChecker); } } else {
// it's working as expected, continue
} }
} else { }, 200);
// it's working as expected, continue }
}
}, 200);*/
} }
return { return {

Loading…
Cancel
Save