Created
June 10, 2013 19:51
-
-
Save gmarland/5751680 to your computer and use it in GitHub Desktop.
Connecting to websocket using engine.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connectSockets: function() { | |
var that = this; | |
if (this._socket != null) { | |
console.log("Retrying webbsocket connection"); | |
this._socket.removeAllListeners(); | |
this._socket = null; | |
} | |
this._socket = new eio("http://localhost:8080/"); | |
// Handle socket actions | |
this._socket.onopen = function() { | |
console.log("Connected to websocket"); | |
that._socket.onmessage = function(package){ | |
var socketPackage = JSON.parse(package.data); | |
if (socketPackage.action != null) { | |
switch(socketPackage.action) { | |
case "topicUpdated": | |
break; | |
} | |
} | |
}; | |
}; | |
this._socket.onclose = function() { | |
console.log("Disconnected from websocket"); | |
if (that._attemptReconnect) { | |
that._connectionAttempts++; | |
if (that._connectionAttempts < 10) { | |
that.connectSockets(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment