-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (34 loc) · 973 Bytes
/
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
42
43
44
45
const express = require('express')
const http = require('http')
const { Server } = require('socket.io')
const app = express()
const server = http.createServer(app)
const io = new Server(server)
app.use(express.static('./'))
let mutations = []
let events = []
io.on('connection', (socket) => {
console.log('new user connected')
io.emit('cloned summary', mutations)
// io.emit('cloned events', events)
socket.on('input summary', (msg) => {
console.log('new input summary received, current length:', mutations.length)
if (msg.f === 'initialize') {
mutations = []
events = []
}
mutations.push(msg)
io.emit('cloned summary', [msg])
})
socket.on('input events', (msg) => {
console.log('new input event received, current length:', events.length)
events.push(msg)
io.emit('cloned events', [msg])
})
socket.on('disconnect', () => {
console.log('user disconnected')
})
})
server.listen(3000, () => {
console.log('listening on *:3000')
})