ethstats-server/public/js/services.js
Marian Oancea cd0d7ef899 update
2015-01-20 20:29:31 +02:00

27 lines
621 B
JavaScript

'use strict';
/* Services */
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);
}
});
})
}
};
});