Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

socket.io updated to latest; socket.io reconnect revised; offline sta…

…tus based on socket.io status
  • Loading branch information...
commit 4d3a7e254b2130c75aab9609ddf0ab6b46880662 1 parent 575f9d5
@cadorn cadorn authored
View
52 client/core/ide.js
@@ -127,13 +127,22 @@ define(function(require, exports, module) {
ide.socketConnect = function() {
clearInterval(ide.$retryTimer);
- ide.socket.json.send({
- command: "attach",
- sessionId: ide.sessionId,
- workspaceId: ide.workspaceId
- });
+ // NOTE: This is a workaround for an init bug in socket.io
+ // @see https://github.com/LearnBoost/socket.io-client/issues/390
+ if (!ide.socket.socket.transport) {
+ // Try and connect until we succeed.
+ // NOTE: This may log a connection error to the error console but will recover gracefully and eventually connect.
+ ide.socketDisconnect();
+ } else {
+ ide.socket.json.send({
+ command: "attach",
+ sessionId: ide.sessionId,
+ workspaceId: ide.workspaceId
+ });
+ }
};
+ // NOTE: I don't think this is ever called at the moment! Should really be commented out if not used.
ide.socketReconnect = function() {
// on a reconnect of the socket.io connection, the server may have
// lost our session. Now we do an HTTP request to fetch the current
@@ -148,17 +157,25 @@ define(function(require, exports, module) {
};
ide.socketDisconnect = function() {
- clearTimeout(ide.$retryTimer);
-
+ // On disconnect retry every 1 second for 5 seconds then issue `disconnected`
+ // and retry every 5 seconds indefinitely.
var retries = 0;
- ide.$retryTimer = setInterval(function() {
- if (++retries == 3)
- ide.dispatchEvent("socketDisconnect");
-
- var sock = ide.socket.socket;
- if (!sock.connecting && !sock.reconnecting && !ide.testOffline && ide.loggedIn)
- sock.reconnect();
- }, 1000);
+ function retryTimer(delay) {
+ clearInterval(ide.$retryTimer);
+ ide.$retryTimer = setInterval(function() {
+ retries += 1;
+ if (retries === 5) {
+ ide.dispatchEvent("socketDisconnect");
+ retryTimer(5000);
+ } else {
+ var sock = ide.socket.socket;
+ if (!sock.connecting && !sock.reconnecting && !ide.testOffline && ide.loggedIn) {
+ sock.connect();
+ }
+ }
+ }, delay);
+ }
+ retryTimer(1000);
};
ide.socketMessage = function(message) {
@@ -170,8 +187,9 @@ define(function(require, exports, module) {
return;
}
- if (message.type == "attached")
- ide.dispatchEvent("socketConnect"); //This is called too often!!
+ if (message.type == "attached") {
+ ide.dispatchEvent("socketConnect"); // This is called too often!!
+ }
ide.dispatchEvent("socketMessage", {
message: message
View
18 client/ext/offline/lib-offline.js
@@ -94,12 +94,14 @@ var Offline = module.exports = function(namespace, detectUrl){
//else //Else we try to go online
//this.goOnline();
- this.startDetect();
+ // NOTE: We now call [this].goOffline() and [this].goOnline() externally triggered by socket.io state.
+ // this.startDetect();
}
/**** Offline Detection ****/
-
- this.isSiteAvailable = function(callback){
+// NOTE: We now call [this].goOffline() and [this].goOnline() externally triggered by socket.io state.
+/*
+ this.isSiteAvailable = function(callback) {
var _self = this;
if (!this.http) {
@@ -120,8 +122,10 @@ var Offline = module.exports = function(namespace, detectUrl){
hideLogMessage : true
});
};
-
+*/
this.startDetect = function(){
+// NOTE: We now call [this].goOffline() and [this].goOnline() externally triggered by socket.io state.
+/*
if (this.detectErrorHandler) //Detection already started
return;
@@ -145,15 +149,19 @@ var Offline = module.exports = function(namespace, detectUrl){
this.detectTimer = setInterval(function(){
_self.isSiteAvailable();
}, this.interval);
+*/
}
this.stopDetect = function(){
- clearInterval(this.detectTimer);
+// NOTE: We now call [this].goOffline() and [this].goOnline() externally triggered by socket.io state.
+/*
+// clearInterval(this.detectTimer);
apf.removeEventListener("error", this.detectErrorHandler);
//#ifdef __DEBUG
apf.console.info("Stopped automatic detection of network state");
//#endif
+*/
}
/**** Offline State Management ****/
View
11 client/ext/offline/offline.js
@@ -340,13 +340,18 @@ module.exports = ext.register("ext/offline/offline", {
/**** Init ****/
+ ide.addEventListener("extload", function() {
+ offline.start();
+ });
+
ide.addEventListener("socketConnect", function() {
offline.goOnline();
- ide.removeEventListener("socketConnect", arguments.callee);
+ // NOTE: We may get multiple `socketConnect` events during a session if conenction drops out and comes back.
+ // ide.removeEventListener("socketConnect", arguments.callee);
});
- ide.addEventListener("extload", function() {
- offline.start();
+ ide.addEventListener("socketDisconnect", function(){
+ offline.goOffline();
});
if (_self.offlineStartup)
2  support/socket.io
@@ -1 +1 @@
-Subproject commit 735d5239b325df2ba67d2b9bb4ec32442283bc06
+Subproject commit c08b9f23d66a16a565de7376b138036d7ef8f8c2
2  support/socket.io-client
@@ -1 +1 @@
-Subproject commit 4375ef1344ecb8ad75a3848a00af6b391822f86b
+Subproject commit a9ed218f57e7e441303a7903bc6c22544b4114bd
Please sign in to comment.
Something went wrong with that request. Please try again.