-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (24 loc) · 809 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"); // returns a function wgich need to be called
const socket = require("socket.io");
const app = express(); // initialised and server ready
app.use(express.static("public"))
let port = process.env.PORT || 5000;
let server = app.listen(port,()=>{
console.log("listening to port "+port);
})
let io = socket(server);
io.on("connection",(socket)=>{
console.log("connection was made");
// Received data
socket.on("beginPath",(data)=>{
// data -> data from front end
// transfer data to all computers after receiving
io.sockets.emit("beginPath",data);
})
socket.on("drawStroke",(data)=>{
io.sockets.emit("drawStroke",data);
})
socket.on("undoRedo",(data)=>{
io.sockets.emit("undoRedo",data);
})
})