Basic socket.io event is working.

This commit is contained in:
jkaplon 2016-11-09 11:14:32 -05:00
parent 6b7800fb66
commit 15d9f02133
3 changed files with 18 additions and 2 deletions

View File

@ -15,6 +15,7 @@
"passport-local": "^1.0.0", "passport-local": "^1.0.0",
"pg": "^4.4.3", "pg": "^4.4.3",
"serve-favicon": "^2.3.0", "serve-favicon": "^2.3.0",
"socket.io": "^1.5.1",
"sqlite3": "^3.0.8", "sqlite3": "^3.0.8",
"winston": "^2.1.1" "winston": "^2.1.1"
}, },

View File

@ -140,6 +140,16 @@ app.get('/logout', function(req, res){
res.redirect('/'); res.redirect('/');
}); });
app.listen(3000, function() { var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connection', function(socket){
//winston.info('a user connected');
socket.on('cm-save', function(msg){
winston.info(msg);
});
});
http.listen(3000, function() {
winston.info("Started on PORT 3000"); winston.info("Started on PORT 3000");
}); });

View File

@ -16,6 +16,7 @@
<script src="mode/markdown/markdown.js"></script> <script src="mode/markdown/markdown.js"></script>
<script src="addon/edit/matchbrackets.js"></script> <script src="addon/edit/matchbrackets.js"></script>
<script src="keymap/vim.js"></script> <script src="keymap/vim.js"></script>
<script src="https://cdn.socket.io/socket.io-1.4.5.js"></script>
<style type="text/css"> <style type="text/css">
html, body { height: 100%; margin: 0; padding: 0; } html, body { height: 100%; margin: 0; padding: 0; }
.wrap { .wrap {
@ -67,7 +68,11 @@
// This no worky, there's no concept of <leader> in CodeMirror, but i was hoping this would work-around it. // This no worky, there's no concept of <leader> in CodeMirror, but i was hoping this would work-around it.
//CodeMirror.Vim.map(' c', '<Esc>o- [ ] ', 'normal') //CodeMirror.Vim.map(' c', '<Esc>o- [ ] ', 'normal')
//CodeMirror.Vim.map(' x', '<ESC>;s/\[\s\]/[x]/g<CR>;noh<CR>', 'normal') //CodeMirror.Vim.map(' x', '<ESC>;s/\[\s\]/[x]/g<CR>;noh<CR>', 'normal')
//CodeMirror.commands.save = function(){ alert("Saving"); } CodeMirror.commands.save = function(){
//alert("Saving");
var socket = io();
socket.emit('cm-save', 'codemirror save event');
}
var typingTimer; var typingTimer;
editor.on("changes", function() { editor.on("changes", function() {