diff --git a/public/app/SocialCtrl.js b/public/app/SocialCtrl.js index ba61d6b..4918a4a 100644 --- a/public/app/SocialCtrl.js +++ b/public/app/SocialCtrl.js @@ -3,11 +3,13 @@ angular .module('FileSync') .controller('SocialCtrl', ['$scope', 'SocketIOService', function($scope, SocketIOService) { this.viewers = []; + this.message = ""; + this.messages = []; function onViewersUpdated(viewers) { this.viewers = viewers; $scope.$apply(); } - + SocketIOService.onViewersUpdated(onViewersUpdated.bind(this)); }]); diff --git a/public/app/SocketIOService.js b/public/app/SocketIOService.js index a57e256..e7d7a59 100644 --- a/public/app/SocketIOService.js +++ b/public/app/SocketIOService.js @@ -31,6 +31,19 @@ angular.module('FileSync') }); return { + sendMessage: function(message){ + socket.emit('chat:message:new', message); + }, + + onNewChatMessage: function(f){ + socket.on('chat:message:new', function(username, message, createdAt){ + console.log(username, message, createdAt); + $timeout(function() { + f(username, message, createdAt); + }); + }); + }, + onViewersUpdated: function(f) { socket.on('viewers:updated', f); }, diff --git a/public/index.html b/public/index.html index 56523ae..fbcac6d 100644 --- a/public/index.html +++ b/public/index.html @@ -1,3 +1,5 @@ + + @@ -6,15 +8,55 @@ + -
-
- {{ viewer }} +
+
+ You are alone ! +
+ {{ viewer }} +
+
+
+ Users connected : +
+ {{ viewer }} +
+
+
+ +
+
+ Chat +
+ +
+
+ Pas encore de messages! +
+
    +
  • + {{message.createdAt | date:"MM/dd/yyyy 'at' H:mm:ss"}} - + : + +
  • +
+
+
+
+
+ +
+
+ +
+
-
+ +
@@ -25,7 +67,7 @@

File History {{ history.visibility.states }}

-
+
{{ edit.timestamp | date : format : shortTime }} @@ -39,11 +81,11 @@

File History {{ history.visibility.states }}

x
-
-
- -
-
+
+
+ +
+
@@ -61,9 +103,9 @@

File History {{ history.visibility.states }}

+ - @@ -74,5 +116,8 @@

File History {{ history.visibility.states }}

+ + + diff --git a/server.js b/server.js index 70eece1..f6e9cb1 100644 --- a/server.js +++ b/server.js @@ -53,10 +53,8 @@ function Viewers(sio) { var viewers = Viewers(sio); - // @todo extract in its own sio.on('connection', function(socket) { - // console.log('nouvelle connexion', socket.id); socket.on('viewer:new', function(nickname) { socket.nickname = nickname; @@ -69,6 +67,12 @@ sio.on('connection', function(socket) { console.log('viewer disconnected %s\nremaining:', socket.nickname, viewers); }); + socket.on('chat:message:new', function(message) { + var created = +new Date(); + console.log('chat:message:new', socket.nickname, message, created); + sio.emit('chat:message:new', socket.nickname, message, created); + }); + socket.on('file:changed', function() { if (!socket.conn.request.isAdmin) { // if the user is not admin @@ -80,6 +84,11 @@ sio.on('connection', function(socket) { sio.emit.apply(sio, ['file:changed'].concat(_.toArray(arguments))); }); + socket.on('message', function(message) + { + sio.emit('message', message); + }); + socket.visibility = 'visible'; socket.on('user-visibility:changed', function(state) {