Skip to content

Commit

Permalink
added socket reconnect session re-establishment
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedeboer committed Nov 24, 2011
1 parent acec689 commit a77853f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
15 changes: 14 additions & 1 deletion client/core/ide.js
Expand Up @@ -132,6 +132,19 @@ define(function(require, exports, module) {
workspaceId: ide.workspaceId
}));
};

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
// session ID and update the Cloud9 config with it. Also, re-attach
// with the backend.
apf.ajax("/reconnect", {
callback: function(data, state, extra) {
ide.sessionId = data;
ide.socketConnect();
}
});
};

ide.socketDisconnect = function() {
clearTimeout(ide.$retryTimer);
Expand Down Expand Up @@ -210,7 +223,7 @@ define(function(require, exports, module) {

ide.socket.on("message", ide.socketMessage);
ide.socket.on("connect", ide.socketConnect);
//ide.socket.on("reconnect", ide.socketReconnect);
ide.socket.on("reconnect", ide.socketReconnect);
//ide.socket.on("reconnecting", ide.socketReconnecting);
ide.socket.on("disconnect", ide.socketDisconnect);
var _oldsend = ide.socket.send;
Expand Down
9 changes: 8 additions & 1 deletion server/cloud9/ide.js
Expand Up @@ -135,13 +135,20 @@ Ide.DEFAULT_PLUGINS = [
var path = Url.parse(req.url).pathname;

this.indexRe = this.indexRe || new RegExp("^" + util.escapeRegExp(this.options.baseUrl) + "(?:\\/(?:index.html?)?)?$");
this.reconnectRe = this.reconnectRe || new RegExp("^" + util.escapeRegExp(this.options.baseUrl) + "\\/reconnect$");
this.workspaceRe = this.workspaceRe || new RegExp("^" + util.escapeRegExp(this.options.davPrefix) + "(\\/|$)");

if (path.match(this.indexRe)) {
if (req.method !== "GET")
return next();
this.$serveIndex(req, res, next);
}
else if (path.match(this.reconnectRe)) {
if (req.method !== "GET")
return next();
res.writeHead(200);
res.end(req.sessionID);
}
else if (path.match(this.workspaceRe)) {
if (!this.davInited) {
if (process.platform == "sunos") {
Expand Down Expand Up @@ -242,7 +249,7 @@ Ide.DEFAULT_PLUGINS = [

setTimeout(function() {
var now = new Date().getTime();
if((now - user.last_message_time) > 10000) {
if ((now - user.last_message_time) > 10000) {
console.log("User fully disconnected", username);
_self.removeUser(user);
}
Expand Down

0 comments on commit a77853f

Please sign in to comment.