-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
32 lines (24 loc) · 793 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
const express = require("express"); // Access
const socket = require("socket.io");
const app = express(); //Initialized and server ready
app.use(express.static("public"));
let port = process.env.PORT || 3000;
let server = app.listen(port, () => {
console.log("Listening to port" + port);
})
let io = socket(server);
io.on("connection", (socket) => {
console.log("Made socket connection");
// Received data
socket.on("beginPath", (data) => {
// data -> data from frontend
// Now transfer data to all connected computers
io.sockets.emit("beginPath", data);
})
socket.on("drawStroke", (data) => {
io.sockets.emit("drawStroke", data);
})
socket.on("redoUndo", (data) => {
io.sockets.emit("redoUndo", data);
})
})