-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (29 loc) · 802 Bytes
/
app.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
const express = require('express')
const socket = require('socket.io')
const cors = require('cors');
let PORT = 3000
const app = express();
// Allow all origins
app.use(cors());
app.use(express.static("public"))
const server = app.listen(PORT,()=>{
console.log(`Server started at port ${PORT}`)
})
const io = socket(server)
io.on('connection', (socket)=>{
console.log('Socket connected!')
// received data
socket.on('beginPath', (data) => {
//now transfer data to all connections
io.sockets.emit('beginPath', data)
})
socket.on('drawStroke', (data) => {
io.sockets.emit('drawStroke', data)
})
socket.on('redoUndo', (data) => {
io.sockets.emit('redoUndo', data)
})
socket.on('colorWidthChange', (data) => {
io.sockets.emit('colorWidthChange', data)
})
})