forked from miroapp/app-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
61 lines (49 loc) · 1.69 KB
/
Copy pathserver.js
File metadata and controls
61 lines (49 loc) · 1.69 KB
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
57
58
59
60
61
const express = require("express");
const path = require("path");
const app = express();
const port = 3000;
const http = require("http").Server(app);
const io = require("socket.io")(http);
app.get("/facilitator", (req, res) => {
res.sendFile(__dirname + "/facilitator.html");
});
app.get("/facilitator-modal", (req, res) => {
res.sendFile(__dirname + "/facilitator-modal.html");
});
app.get("/participant", (req, res) => {
res.sendFile(__dirname + "/participant.html");
});
app.get("/participant-modal", (req, res) => {
res.sendFile(__dirname + "/participant-modal.html");
});
app.use("/src", express.static(path.join(__dirname, "src")));
io.on("connection", (socket) => {
socket.on("joinRoom", (msg) => {
console.log(`<socket server> client joining ${msg}`);
socket.join(msg);
});
socket.on("command", (msg) => {
const command = msg.command;
const rooms = Array.from(socket.rooms);
console.log(`<socket server> command msg ${msg.command} to ${rooms}`);
rooms.map((room) => io.to(room).emit("execute", command));
});
socket.on("direct-command", (msg) => {
const command = msg.command;
const socketId = msg.socketId;
console.log(`<socket server> direct command msg ${command} to ${socketId}`);
io.to(socketId).emit("execute", command);
});
socket.on("request", (msg) => {
const request = msg.request;
const socketId = socket.id;
console.log(`<socket server> ${socketId} requesting ${request}`);
const rooms = Array.from(socket.rooms);
rooms.map((room) =>
io.to(room).emit("respond", { socketId: socketId, request: request }),
);
});
});
http.listen(port, () => {
console.log(`youtube-room server running on port ${port}/`);
});