I am doing a factory for socket.io, if the user is not logged in, then I
var socket = io.connect (SOCKET_URL);
When the user logs in to the site, then I am changing the socket value.
socket = io.connect (SOCKET_URL, {forceNew: true});
I have in my controller
socket.on ('notification', function (data) {console.log (data);}) Code> This socket.one ('Notification') is working after factory replacement socket variable.
My factory
app .factory ('socket', function ($ rootScope)) {var socket = io.connect (SOCKET_URL); Return {reconnect: function () {console.log ("reconnect"); Socket = io.connect (SOCKET_URL, {forceNew: True});}, on: function (eventName, callback) {socket.on (eventName, function) {var args = arguments; $ RootScope $ Applied (function () {callback.apply (socket, args);})}});}});
My Controller
app.controller ('myCtrl1', function ($ radius, socket) {$ scope.login = function () {// ............. socket.reconnect ();}}); App.controller ('myCtrl2', function ($ scope, socket) {socket.on ('notification', function (data) {// it is not working console.log (data); // call socket.reconnect after ( );})});
No comments:
Post a Comment