Reputation: 1495
I am using socket.io with js client side like so:
this.connect = function(roomname) {
var deferred = $q.defer();
if(self.isConnected) {
deferred.$$reject('already connected');
return deferred.promise;
}
self.isConnected = true;
connectedRoom = roomName;
socket = io('', {
query: 'roomname=' + roomname
});
socket.on('connect', function() {
console.log('socket client connected ' + socket.id);
$rootScope.$broadcast('socketsConnected');
socket.emit('room', roomName, function() {
deferred.resolve();
});
});
socket.on('reconnect', function() {
self.isConnected = true;
console.log('socket client reconnecting ' + socket.id);
});
socket.on('disconnect', function() {
self.isConnected = false;
console.log('socket client disconnecting ' + socket.id);
});
return deferred.promise;
}
When I switch off the server, the disconnect
event fired as expected. When I switch the server back on, reconnect
is fired as expected.
However if I switch of my wi-fi, the disconnect
event never fires (I have left it several minutes).
When I switch the wi-fi back on the reconnect
event does not fire, it does however seem to re-establish a connection as the messages will then emit and receive correctly.
How can I get these events to fire on losing wi-fi?
Upvotes: 0
Views: 189
Reputation: 1495
Ok, I've had a long day. In case anyone is as much of an idiot as I am, my server was on the same machine as my client so cutting the wi-fi had zero effect!
Upvotes: 2