-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
77 lines (65 loc) · 2.04 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { emit } = require("process");
const app = require("express")();
const httpServer = require("http").createServer(app);
const options = { cors: ["http://10.52.1.83:8080"] };
const io = require("socket.io")(httpServer, options);
// Connection established
io.on("connection", (socket) => {
console.log(`${new Date().toLocaleString()}: Connected to id: ${socket.id}`);
// Join room
socket.on("join-room", (room, device) => {
socket.join(room);
socket.to(room).emit("connected-device", device);
console.log(
`${new Date().toLocaleString()}: User: ${socket.id} joined room: ${room}`
);
});
// Disconnect client
socket.on("disconnect", () => {
console.log(
`${new Date().toLocaleString()}: User: ${socket.id} disconnected`
);
});
// Disconnect alert
socket.on("disconnect_alert", (room, device) => {
socket.to(room).emit("disconnect_alert", device);
});
// Play vod
socket.on("play-vod", (vodId, room) => {
console.log(
`${new Date().toLocaleString()}: Route to vod with id ${vodId}`
);
socket.to(room).emit("get-vod", vodId);
});
// Pause
socket.on("pause", (room, callback) => {
console.log(`${new Date().toLocaleString()}: Pause`);
socket.to(room).emit("pause");
callback();
});
// Play
socket.on("play", (room, callback) => {
console.log(`${new Date().toLocaleString()}: Play`);
socket.to(room).emit("play");
callback();
});
// Fast forward
socket.on("fast-forward", (room) => {
console.log(`${new Date().toLocaleString()}: Fast-forward`);
socket.to(room).emit("fast-forward");
});
// Rewind
socket.on("rewind", (room) => {
console.log(`${new Date().toLocaleString()}: Rewind`);
socket.to(room).emit("rewind");
});
// Seek
socket.on("seek", (seconds, room) => {
console.log(`${new Date().toLocaleString()}: Seeked to ${seconds} seconds`);
socket.to(room).emit("seek", seconds);
});
});
// Run server on IP-adress machine
httpServer.listen(3000, "10.52.1.83", () => {
console.log("SERVER IS RUNNING");
});