Skip to content

Commit

Permalink
Added auto-reconnect with csp when websocket fails (due to proxy issu…
Browse files Browse the repository at this point in the history
…es, for instance)
  • Loading branch information
mcarter committed Aug 7, 2010
1 parent cdbd2f6 commit 25089d2
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 74 deletions.
23 changes: 15 additions & 8 deletions daemon/orbited2/js_src/Orbited2.js
Expand Up @@ -267,7 +267,7 @@ var count = 0;

function getMultiplexer(baseUri) {
if (!multiplexer) {
multiplexer = new OrbitedMultiplexingProtocol();
multiplexer = new OrbitedMultiplexingProtocol(baseUri);
multiplexer.onClose = function() {
multiplexer = null;
}
Expand All @@ -278,11 +278,13 @@ function getMultiplexer(baseUri) {
uri.setProtocol('ws');
var url = uri.render() + 'ws';
net.connect(multiplexer, 'websocket', { url: url, wsConstructor: originalWebSocket });
multiplexer.connectionLost = bind(multiplexer, '_connectionLost', 'websocket');
multiplexer.mode = 'ws';
}
else { // Fallback ot csp
net.connect(multiplexer, 'csp', { url: baseUri + 'csp' });
multiplexer.mode = 'csp';
multiplexer.connectionLost = bind(multiplexer, '_connectionLost', 'csp');
}
}
count+=1;
Expand Down Expand Up @@ -327,8 +329,9 @@ var Connection = Class(function() {

var OrbitedMultiplexingProtocol = Class(BufferedProtocol, function(supr) {

this.init = function() {
this.init = function(baseUri) {
supr(this, 'init', arguments);
this._baseUri = baseUri;
this._connections = {};
this._last_id = -1;
this._size = -1;
Expand Down Expand Up @@ -377,13 +380,17 @@ var OrbitedMultiplexingProtocol = Class(BufferedProtocol, function(supr) {

//callback
this.onClose = function() { }

this.connectionLost = function() {
this.onClose();
for (id in this._connections) {
this._connections[id].onClose();

this._connectionLost = function(transportName, reason, wasConnected) {
if (!wasConnected) {
if (transportName == 'websocket') {
net.connect(this, 'csp', {url: this._baseUri + 'csp' });
this.connectionLost = bind(this, '_connectionLost', 'csp');
this.mode = 'csp';
}
} else {
this.onClose();
}

}

this._dispatchPayload = function(payload) {
Expand Down

0 comments on commit 25089d2

Please sign in to comment.