-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (32 loc) · 1.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
var express = require('express');
app = express(),
http = require('http').Server(app),
io = require('socket.io')(http);
// app routing
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
app.use("/css", express.static(__dirname + "/css"));
app.use("/js", express.static(__dirname + "/js"));
app.use("/node_modules", express.static(__dirname + "/node_modules"));
});
io.sockets.on('connection', function (socket) {
console.log('a user session', socket.id);
socket.on('coOpText', function (paragraphs) {
console.log('server recived text:', paragraphs);
console.log('sending to all other users');
//socket.broadcast.emit('msgBroadcast', paragraphs);
socket.broadcast.to(paragraphs.editor).emit('msgBroadcast', paragraphs);
});
socket.on('coOpJoin', function (targetEditor, callback) {
if (targetEditor !== '') {
console.info('joining co-op room:', targetEditor);
socket.join(targetEditor);
if (callback !== undefined) {
callback();
}
}
});
});
http.listen(5000, function () {
console.log('listening on *:5000');
});