Skip to content

Instantly share code, notes, and snippets.

@rosterloh
Created May 2, 2014 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosterloh/a32f2b1362719527354c to your computer and use it in GitHub Desktop.
Save rosterloh/a32f2b1362719527354c to your computer and use it in GitHub Desktop.
The world's most basic socket.io AngularJS factory
appServices.factory('socket', function ($rootScope) {
var socket = io.connect('http://localhost:3000');
return {
on: function (eventName, callback) {
socket.on(eventName, function () {
var args = arguments;
$rootScope.$apply(function () {
callback.apply(socket, args);
});
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment