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.defaults = {
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.
MAX_LAG_BEFORE_DISCONNECT: 20000
};
@ -1040,6 +1034,8 @@ return /******/ (function(modules) { // webpackBootstrap
_createClass(WebSocketService, [{
key: 'join',
value: function join(key) {
var _this = this;
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var settings = Object.assign({}, this.settings, options);
@ -1051,24 +1047,19 @@ return /******/ (function(modules) { // webpackBootstrap
resolve(socket);
};
socket.onerror = reject;
});
}
// Check the status of the socket connection
/*var isSocketDisconnected = function (realtime) {
let sock = ws._socket;
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) {
// 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;
};
socket.checkSocket = function (realtime) {
if (isSocketDisconnected(realtime, socket) && !socket.intentionallyClosing) {
return true;
} else {
} else {
return false;
}
};*/
}
};
});
}
}]);
return WebSocketService;

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

Loading…
Cancel
Save