(function() {
var app = angular.module('rooms.controllers', []);
app.factory('socket', function ($rootScope) {
var socket = io('http://localhost:9999/');
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);
}
});
})
}
};
});
app.controller('UsersController', function($scope, socket) {
$scope.leaders = [{
leader: 'Test Leader',
}];
$scope.click = function() {
alert($scope);
}
socket.emit('user online');
socket.on('user online', function(leaders) {
console.dir(leaders);
$scope.leaders = leaders;
});
})
.directive('usersList', function(){
return {
restrict: 'EA',
templateUrl: 'js/templates/users-list.html'
};
});
app.controller('ChatsController', function($scope, socket) {
$scope.messages = [];
$scope.send = function(msg){
console.dir(msg);
socket.emit('common chat message', msg || {});
};
})
.directive('usersChats', function(){
return {
restrict: 'EA',
templateUrl: 'js/templates/users-chats.html'
};
});
})();