Hellothere
Hellothere

Reputation: 263

socket.io remains disconnected, even after I try to reconnect it? Why?

socket = 'what';
//I do this when person clicks connect: 
if (socket == 'what')
{
socket = io.connect();
}
else if (socket == null)
{
 socket = io.connect();
 socket = socket.socket.reconnect();
 }
//I do other stuff with webrtc and socket. 
//then when person clicks disconnect, I do:
socket.disconnect();
socket = null;

I didn't want to write all the code because there's a lot of it, and I tried to keep this as simple as possible. Basically, socket remains disconnected after I click disconnect. But if I click connect again, socket still remains disconnected, because I console.log it and it says that socket disconnected = true and socket connected = false.

Why does it remain disconnected? How do I just completely refresh the entire socket (just get a totally new socket) without refreshing the browser page? I just want it to fully disconnect on disconnect, and to fully reconnect on reconnect. And it doesn't work....

Upvotes: 2

Views: 1359

Answers (1)

Chris Tate
Chris Tate

Reputation: 458

Ran into this same issue. There is a secret option force new connection:

io.connect(url, { 'force new connection' : true })

You can also use forceNew for 1.0.

More info here:

https://github.com/Automattic/socket.io-client/issues/607

Upvotes: 1

Related Questions