Created
July 22, 2013 08:03
-
-
Save maggocnx/6052103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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