Ok, this one was a little bit tricky, but after going through several tickets I read that there's an issue with timeouts on Android. If the variable you're assigning to the timeout isn't defined, then it won't work. What I mean is, if you have something like;
this.timeoutTimer = setTimeout(...); //imagine the variable this is a reference to an object that is storing properties for a connection.
it won't work, but if you give a null value to the timeoutTimer property before assigning it the timeout id like this:
this.timeoutTimer = null;
.
. doing something else
.
this.timeoutTimer = setTimeout(...);
it will work with no problem.
Take note on this, THIS IS AN ANDROID ISSUE ONLY, iOS DOESN'T PRESENT THIS ISSUE BUT IF YOU'RE CROSS-PLATFORMING THEN MAKE SURE ANY VARIABLE THAT WILL STORE A TIMEOUT ID IS INITIALIZED AS NULL FIRST.
Now to solve my question, you must be using the socket.io-titanium module, I couldn't make the tiws module to work. So here are the steps to fix this issue using socket.io-titanium:
- Go to the socket.io folder in your folder, then open the lib folder, here there will be several javascript files.
- Open the socket.js file.
- Search for the line
Socket.prototype.handshake = function (fn)
- Add the line
this.heartbeatTimeoutTimer = null;
just below the previous line. - Save and compile for Android.
Now this should make the connection work.