Skip to content

Instantly share code, notes, and snippets.

@maggocnx
Created July 22, 2013 08:03
Show Gist options
  • Save maggocnx/6052103 to your computer and use it in GitHub Desktop.
Save maggocnx/6052103 to your computer and use it in GitHub Desktop.
var app = angular.module('gronicom', []);
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);
}
});
})
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment