Answer the question
In order to leave comments, you need to log in
How to unsubscribe from Socket.IO sockets?
Let's say we have a factory:
var socket = io.connect('ip');
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
},
emit: function (eventName, data, callback) {
socket.emit(eventName, data, function () {
var args = arguments;
$rootScope.$apply(function () {
if (callback) {
callback.apply(socket, args);
}
});
})
}
};
socketIo.emit('subscribe', 'needThis');
socketIo.on('needThis', function(data){
console.log(data);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question