diff --git a/DanGeffroy.txt b/DanGeffroy.txt new file mode 100644 index 0000000..b2e0252 --- /dev/null +++ b/DanGeffroy.txt @@ -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. diff --git a/README.md b/README.md index 5769d55..88ece86 100644 --- a/README.md +++ b/README.md @@ -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/) diff --git a/public/app/CmdCtrl.js b/public/app/CmdCtrl.js new file mode 100644 index 0000000..2aeb1ab --- /dev/null +++ b/public/app/CmdCtrl.js @@ -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)); + }]); diff --git a/public/app/SocketIOService.js b/public/app/SocketIOService.js index a57e256..1107691 100644 --- a/public/app/SocketIOService.js +++ b/public/app/SocketIOService.js @@ -19,6 +19,7 @@ angular.module('FileSync') }); }); + socket.on('users:visibility-states', function(states) { $timeout(function() { _onVisibilityStatesChanged(states); @@ -45,6 +46,9 @@ angular.module('FileSync') userChangedState: function(state) { socket.emit('user-visibility:changed', state); + }, + onCmdtyped: function(f){ + socket.on('cmd:typed',f); } }; }]); diff --git a/public/index.html b/public/index.html index 56523ae..4e27a46 100644 --- a/public/index.html +++ b/public/index.html @@ -10,10 +10,22 @@
-
+
{{ viewer }}
+
+

Command history

+
+
+
+
+

my-app > {{ cmd }}

+
+
+
+
+
@@ -73,6 +85,7 @@

File History {{ history.visibility.states }}

+ diff --git a/relay.js b/relay.js index 9cb80d5..bae7d81 100644 --- a/relay.js +++ b/relay.js @@ -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 > ", +}); }); diff --git a/server.js b/server.js index 70eece1..071c067 100644 --- a/server.js +++ b/server.js @@ -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() {