-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
37 lines (29 loc) · 891 Bytes
/
server.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
const express = require('express')
const { Server } = require("socket.io");
const http = require('http')
const PORT = process.env.PORT || 3000
const app = express()
const server = http.Server(app);
// here we make available the folder "public" to be access
app.use(express.static('public'))
// socket.io
const io = new Server(server);
io.on('connection', (socket) => {
console.log('a user connected');
socket.on("layers", data => {
console.log('socket, layers', data)
socket.broadcast.emit("layers", data)
})
socket.on("results", data => {
console.log('socket, results', data)
socket.broadcast.emit("results", data)
})
socket.on("clear", data => {
console.log('socket, clear')
socket.broadcast.emit("clear", "")
})
});
// setting the server to run on port 3000
server.listen(PORT, function () {
console.log(`Listening on port ${PORT}...`)
})