简体   繁体   中英

socket.emit not firing after socket reconnected

On device sleep, socket disconnects, And then upon waking the device it automatically reconnects. This is great! However, after reconnecting my angular side socket.emit does not fire now. Thoughts?

On my angular controller, i pass in socket. And this works great on initial connection. However, after reconnection it doesn't appear this socket is now connected or something?

function ChatController($scope, $location, $routeParams, $q, socket)

This is where my app module is created. And where i pass 'socket' into it

angular.module('myChat', ['ngRoute','auth', 'LocalStorageModule', 'myServices', 'angular-timeago', 'socket', 'ngTouch'])

Ive read some places that i need to implement io.connect() somewhere on the client side, but not quite sure where to put this, if in fact is the answer?

After much frustration, I realized the problem laid in my socket.js file. initially when two people enter a room, they both trigger the join:user function. This places both users in the same room. However, when the disconnection happens when the phone sleeps, and then wakes up and reconnects, that user is no longer in the same room, and has been removed from the room. Therefore, i need to have the user rejoin the room next time it sends a message. This is taking into consideration that that page has NOT been refreshed.

Hope this helps some one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM