-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (45 loc) · 1.14 KB
/
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
50
51
52
53
54
55
const express = require("express");
const meetingRouter = require("./routes/meetingRoutes");
// setup
const app = express();
const server = require("http").Server(app);
const io = require("socket.io")(server);
app.set("view engine", "ejs");
// Middleware
app.use(express.static("public"));
app.use(express.urlencoded({ extended: false }));
//video confercing
io.on("connection", (socket) => {
socket.on("join-room", (roomId, userId) => {
socket.join(roomId);
socket.to(roomId).emit("user-connected", userId);
socket.once("disconnect", () => {
socket.to(roomId).emit("user-disconnected", userId);
});
// chat event
socket.on("chat", (data) => {
socket.to(roomId).emit("chat", data);
});
// whiteboard
socket.on("draw", (data) => {
socket.to(roomId).emit("ondraw", {
x: data.x,
y: data.y,
});
});
socket.on("down", (data) => {
socket.to(roomId).emit("ondown", {
x: data.x,
y: data.y,
});
});
});
});
// routes
app.use(meetingRouter);
app.get("*", (req, res) => {
res.render("404");
});
// listen
server.listen(8000);
module.exports = io;