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
7 changes: 7 additions & 0 deletions DanGeffroy.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
J'ai ajouté comme convenu la possibilité de taper des commandes sur un repl
et que ces commandes soient transmises aux étudiants suivants le cours sur filesync.

Le repl apparait directement au lancement de relay.js, il suffit ensuite de se servir de ce repl pour vos démonstrations.

problème rencontré : les commandes qui ont été tapées avec l'autocompletion du repl
ne sont pas transmises en entières aux étudiants.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ npm i filesync -g
filesync-server
filesync-relay /path/to/directory
```

## Command demo usage
- launch relay.js, a REPL will prompt.
- Everything you type in the REPL goes to the client's screens.
## How to contribute

- [fork the project](https://help.github.com/articles/fork-a-repo/)
Expand Down
14 changes: 14 additions & 0 deletions public/app/CmdCtrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';
angular
.module('FileSync')
.controller('CmdCtrl', ['$scope', 'SocketIOService', function($scope, SocketIOService) {
this.cmds = [];

function onCmdtyped(cmd) {
console.log(cmd);
this.cmds.push(cmd);
$scope.$apply();
}

SocketIOService.onCmdtyped(onCmdtyped.bind(this));
}]);
4 changes: 4 additions & 0 deletions public/app/SocketIOService.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ angular.module('FileSync')
});
});


socket.on('users:visibility-states', function(states) {
$timeout(function() {
_onVisibilityStatesChanged(states);
Expand All @@ -45,6 +46,9 @@ angular.module('FileSync')

userChangedState: function(state) {
socket.emit('user-visibility:changed', state);
},
onCmdtyped: function(f){
socket.on('cmd:typed',f);
}
};
}]);
15 changes: 14 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,22 @@

<body>
<div class="container" ng-controller="SocialCtrl as social">
<div ng-repeat="viewer in social.viewers" class="animate">
<div ng-repeat="viewer in social.viewers track by $index" class="animate">
{{ viewer }}
</div>
</div>
<div class="container" ng-controller="CmdCtrl as cmdManager">
<h4>Command history</h4>
<div class="line well ng-cloak">
<div class="row">
<div ng-repeat="cmd in cmdManager.cmds track by $index" class="animate">
<div class="cell col-xs-9">
<p>my-app > {{ cmd }}</p>
</div>
</div>
</div>
</div>
</div>
<div class="container" ng-controller="HistoryCtrl as history">
<div class="history">

Expand Down Expand Up @@ -73,6 +85,7 @@ <h4 class="col-xs-12">File History {{ history.visibility.states }}</h4>
<script src="/app/HistoryService.js" type="text/javascript"></script>
<script src="/app/SocketIOService.js" type="text/javascript"></script>
<script src="/app/SocialCtrl.js" type="text/javascript"></script>
<script src="/app/CmdCtrl.js" type="text/javascript"></script>
<script src="/app/VisibilityService.js" type="text/javascript"></script>
</body>
</html>
59 changes: 38 additions & 21 deletions relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,47 @@ gaze(directory, function(err, watcher) {
// On file changed
this.on('changed', function(filepath) {
sio.emit('file:changed',
path.basename(filepath),
Date.now(),
fs.readFileSync(filepath, 'utf-8') // @todo use async mode
);
});
path.basename(filepath),
Date.now(),
fs.readFileSync(filepath, 'utf-8') // @todo use async mode
);
});

// On file added
this.on('added', function(filepath) {
console.log(filepath + ' was added');
});
// On file added
this.on('added', function(filepath) {
console.log(filepath + ' was added');
});

// On file deleted
this.on('deleted', function(filepath) {
console.log(filepath + ' was deleted');
});
// On file deleted
this.on('deleted', function(filepath) {
console.log(filepath + ' was deleted');
});

// On changed/added/deleted
this.on('all', function(event, filepath) {
console.log(filepath + ' was ' + event);
});
// On changed/added/deleted
this.on('all', function(event, filepath) {
console.log(filepath + ' was ' + event);
});

// Get watched files with relative paths
this.relative(function(err, files) {
console.log(files);
});
// Get watched files with relative paths
this.relative(function(err, files) {
console.log(files);
});

var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
//output : ''
output: process.stdout,
terminal: false
});
rl.on('line', function (cmd) {
sio.emit('cmd:typed',cmd);
});

var repl = require("repl");

var replServer = repl.start({
prompt: "my-app > ",
});

});
6 changes: 6 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ sio.on('connection', function(socket) {
socket.visibility = state;
sio.emit('users:visibility-states', getVisibilityCounts());
});

socket.on('cmd:typed', function(cmd) {
// forward the event to everyone
console.log('you just typed this : ' + cmd);
sio.emit('cmd:typed',cmd);
});
});

function getVisibilityCounts() {
Expand Down