Hi I'm building an angularjs service that will use websockets via socket.io to communicate with backend (node.js). I found a snippet of code online but I don't quite understand how it works. Specifically on the lines under "var args = arguments". Help?
angularjs_service.js
app.factory('socket', function ($rootScope) {
var socket = io.connect();
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);
}
});
})
}
};
});