forked from WholeWheatOrange/ppt3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
49 lines (34 loc) · 956 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
38
39
40
41
42
43
44
45
46
47
48
49
const express = require("express");
var cors = require("cors");
const app = express();
const path = require("path");
const port = 3000;
app.use(cors());
app.use(
express.urlencoded({
extended: true,
})
);
// viewed at http://localhost:3000
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname + "/index.html"));
});
app.use(express.static(path.join(__dirname, "/public")));
const server = app.listen(port, () => {
console.log("Listening on port: " + port);
});
const io = require("socket.io")(server);
io.on("connection", function (socket) {
socket.on("sendLines", (target, amount) => {
io.emit("receiveLines", target, amount)
});
socket.on("sendBoard", (data) => {
io.emit("receiveBoard", socket.id, data)
})
socket.on("sendPieceData", ( data) => {
io.emit("receivePieceData", socket.id, data)
})
socket.on("disconnect", () => {
io.emit("removePlayer", socket.id)
})
});