Interim commit; want to retain chokidar file watcher code, even if it's not needed; not sure if socket.io sync is working yet.
This commit is contained in:
parent
fb4637c2a1
commit
5ade0c8f9c
@ -3,6 +3,7 @@
|
||||
"version": "0.0.1",
|
||||
"dependencies": {
|
||||
"body-parser": "^1.12.4",
|
||||
"chokidar": "^1.6.1",
|
||||
"connect-ensure-login": "^0.1.1",
|
||||
"cookie-parser": "^1.4.3",
|
||||
"express": "^4.12.4",
|
||||
|
28
server.js
28
server.js
@ -95,8 +95,8 @@ io.on('connection', function(socket){
|
||||
//winston.info('a user connected');
|
||||
fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
|
||||
if (!err){
|
||||
winston.info('successful file read');
|
||||
io.emit('download allNotes',data);
|
||||
winston.info('file read on connection');
|
||||
socket.emit('download allNotes',data); // Send content only to newly connected client.
|
||||
} else { winston.error(err); }
|
||||
});
|
||||
socket.on('upload allNotes', function(msg){
|
||||
@ -109,23 +109,45 @@ io.on('connection', function(socket){
|
||||
} else {
|
||||
fileSystem.writeFile(notePath, msg, 'utf-8', function(err) {
|
||||
if (err) { winston.error(err); }
|
||||
winston.info('new contents from client written to allNotes.txt');
|
||||
var exec = require('child_process').exec;
|
||||
var cmd = 'cd note-data && git commit -am "Notes modified via websocket, ' + now + '"';
|
||||
winston.info(cmd);
|
||||
exec(cmd, function(error, stdout, stderr) {
|
||||
if (error) { winston.error(error); }
|
||||
winston.info(stdout);
|
||||
winston.info('new contents from client written to allNotes.txt');
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
// Send new content to all other clients EXCEPT the orig sender.
|
||||
fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
|
||||
if (!err){
|
||||
socket.broadcast.emit('download allNotes',data);
|
||||
winston.info('sent content update to other clients');
|
||||
} else { winston.error(err); }
|
||||
});
|
||||
});
|
||||
socket.on('cm-save', function(msg){
|
||||
winston.info(msg);
|
||||
});
|
||||
});
|
||||
|
||||
//var chokidar = require('chokidar');
|
||||
//var watcher = chokidar.watch(notePath, {
|
||||
//ignored: /[\/\\]\./,
|
||||
//persistent: true
|
||||
//});
|
||||
//watcher.on('change', function(){
|
||||
//winston.info('file watcher change event');
|
||||
//fileSystem.readFile(notePath, {encoding: 'utf-8'}, function(err,data){
|
||||
//if (!err){
|
||||
//winston.info('successful file read');
|
||||
//io.emit('download allNotes',data);
|
||||
//} else { winston.error(err); }
|
||||
//});
|
||||
//});
|
||||
|
||||
http.listen(3000, function() {
|
||||
winston.info("Started on PORT 3000");
|
||||
});
|
||||
|
@ -45,7 +45,6 @@
|
||||
|
||||
<div class=wrap>
|
||||
<div class=border>
|
||||
<!-- <textarea id="editor" name="editor">{{{notetxt}}}</textarea> -->
|
||||
<textarea id="editor" name="editor"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
@ -73,13 +72,14 @@
|
||||
socket.emit('cm-save', 'codemirror save event');
|
||||
}
|
||||
|
||||
var userKeypress = false;
|
||||
var socket = io();
|
||||
socket.on('download allNotes', function(msg){
|
||||
//console.log(msg);
|
||||
userKeypress = false; // Set this back to false, still getting infinite loop.
|
||||
editor.getDoc().setValue(msg);
|
||||
});
|
||||
|
||||
var userKeypress = false;
|
||||
document.onkeydown = function(){ userKeypress = true; };
|
||||
var typingTimer;
|
||||
editor.on("changes", function() {
|
||||
|
Loading…
Reference in New Issue
Block a user