Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion public/app/SocialCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}]);
13 changes: 13 additions & 0 deletions public/app/SocketIOService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
67 changes: 56 additions & 11 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


<!doctype html>
<html ng-app="FileSync">
<head>
Expand All @@ -6,15 +8,55 @@
<link rel="stylesheet" href="/components/bootstrap/dist/css/bootstrap-theme.css"/>
<link rel="stylesheet" href="/components/highlightjs/styles/github.css"/>
<link rel="stylesheet" href="css/style.css"/>
<link rel="stylesheet" href="/app/css/chat.css"/>
</head>

<body>
<div class="container" ng-controller="SocialCtrl as social">
<div ng-repeat="viewer in social.viewers" class="animate">
{{ viewer }}
<div class="container col-xs-1" ng-controller="SocialCtrl as social">
<div ng-if="social.viewers.length ===0">
You are alone !
<div ng-repeat="viewer in social.viewers" class="animate">
{{ viewer }}
</div>
</div>
<div ng-if="social.viewers.length > 0" >
Users connected :
<div ng-repeat="viewer in social.viewers" class="animate">
{{ viewer }}
</div>
</div>
</div>

<div class="container panel panel-default chat-container chatCSS col-xs-5" ng-controller="ChatCtrl as chat">
<div class="panel-heading">
Chat
</div>

<div class="animate chat-messages panel-body">
<div class="alert alert-info" ng-if="chat.messages.length ===0">
Pas encore de messages!
</div>
<ul ng-if="chat.messages.length > 0">
<li ng-repeat="message in chat.messages">
{{message.createdAt | date:"MM/dd/yyyy 'at' H:mm:ss"}} -
<span ng-bind="message.username" ng-attr-title=""></span> :
<span ng-bind="message.message"></span>
</li>
</ul>
</div>
<div class="chat-options row-fluid panel-body">
<form class="form-inline">
<div class="form-group" style="width:80%">
<input ng-model="chat.message" type="text" class="form-control" style="width:100%" placeholder="What are you thinking about?" value="" />
</div>
<div class="form-group" style="width:19%">
<button ng-click="chat.sendMessage()" style="width:100%" type="submit" name="button" class="btn btn-success">Send</button>
</div>
</form>
</div>
</div>
<div class="container" ng-controller="HistoryCtrl as history">

<div class="container col-xs-6" ng-controller="HistoryCtrl as history">
<div class="history">

<div class="row-fluid">
Expand All @@ -25,7 +67,7 @@ <h4 class="col-xs-12">File History {{ history.visibility.states }}</h4>
<div class="row-fluid">
<div ng-repeat="edit in history.edits" class="animate">
<div class="line well ng-cloak">
<div class="row">
<div class="row">

<div class="cell col-xs-2">
{{ edit.timestamp | date : format : shortTime }}
Expand All @@ -39,11 +81,11 @@ <h4 class="col-xs-12">File History {{ history.visibility.states }}</h4>
<a href ng-click="history.remove(edit)" class="btn btn-danger" title="">x</a>
</div>

<div class="col-xs-12">
<div hljs source="edit.content">
<textarea></textarea>
</div>
</div>
<div class="col-xs-12">
<div hljs source="edit.content">
<textarea></textarea>
</div>
</div>

</div>

Expand All @@ -61,9 +103,9 @@ <h4 class="col-xs-12">File History {{ history.visibility.states }}</h4>

<script src="/components/angular/angular.js" type="text/javascript"></script>
<script src="/components/angular-animate/angular-animate.js" type="text/javascript"></script>
<script src="/components/highlightjs/highlight.pack.js" type="text/javascript"></script>
<script src="/components/angular-highlightjs/angular-highlightjs.js" type="text/javascript"></script>

<script src="/components/highlightjs/highlight.pack.js" type="text/javascript"></script>
<script src="/components/moment/moment.js" type="text/javascript"></script>
<script src="/components/lodash/lodash.js" type="text/javascript"></script>
<script src="/components/visibilityjs/lib/visibility.core.js" type="text/javascript"></script>
Expand All @@ -74,5 +116,8 @@ <h4 class="col-xs-12">File History {{ history.visibility.states }}</h4>
<script src="/app/SocketIOService.js" type="text/javascript"></script>
<script src="/app/SocialCtrl.js" type="text/javascript"></script>
<script src="/app/VisibilityService.js" type="text/javascript"></script>
<script src="/app/chat/ChatCtrl.js" type="text/javascript"></script>
<script src="/app/chat/ChatService.js" type="text/javascript"></script>
</body>
</html>

13 changes: 11 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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) {
Expand Down