-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
48 lines (34 loc) · 994 Bytes
/
server.js
File metadata and controls
48 lines (34 loc) · 994 Bytes
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
42
43
44
45
46
47
48
const PORT = 3000;
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.use('/static', express.static('static'));
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket) {
socket.on('disconnect', function() {
io.emit('users', io.engine.clientsCount);
});
socket.on('getValue', function(value) {
if (io.engine.clientsCount == 1) {
io.emit('initValue', {'index': '// index.js'});
} else {
io.emit('getValue', value);
}
});
socket.on('initValue', function(value) {
io.emit('initValue', value);
io.emit('users', io.engine.clientsCount);
});
socket.on('changeValue', function(value) {
io.emit('changeValue', value);
});
socket.on('newFile', function(value) {
io.emit('newFile', value);
});
});
http.listen(PORT, function() {
console.log('Server listening on port', PORT)
});