raumstatus/node/public/js/app.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-10-20 22:04:58 +00:00
'use strict';
angular.module('Services', []).
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) {
if(typeof data == 'function') {
callback = data;
data = {};
}
socket.emit(eventName, data, function() {
var args = arguments;
$rootScope.$apply(function() {
if(callback) {
callback.apply(socket, args);
}
});
});
},
emitAndListen: function(eventName, data, callback) {
this.emit(eventName, data, callback);
this.on(eventName, callback);
}
};
});
angular.module('roomstateapp', ['roomstateapp.controllers', 'Services']);