-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.js
56 lines (45 loc) · 1.28 KB
/
express.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
50
51
52
53
54
55
56
// server side
const express = require("express");
// express server
const app = express();
// nodejs
const server = require("http").Server(app);
// nodejs => socket enabled
const path = require("path");
const io = require("socket.io")(server);
// serve static assets to client
app.use(express.static("public"));
// server
io.on("connection", function(socket) {
console.log(socket.id);
socket.on("size", function(size) {
socket.broadcast.emit("onsize", size);
});
socket.on("color", function(color) {
socket.broadcast.emit("oncolor", color);
});
socket.on("toolchange", function(tool) {
socket.broadcast.emit("ontoolchange", tool);
});
socket.on("hamburger", function() {
socket.broadcast.emit("onhamburger");
});
socket.on("mousedown", function(point) {
socket.broadcast.emit("onmousedown", point);
});
socket.on("mousemove", function(point) {
console.log("Recieved Mouse down event")
socket.broadcast.emit("onmousemove", point);
});
socket.on("undo", function() {
socket.broadcast.emit("onundo");
});
socket.on("redo", function() {
socket.broadcast.emit("onredo");
});
});
// nodejs server
const port = process.env.PORT || 3000;
server.listen(port, function(req, res) {
console.log("Server has started at port 3000");
});