-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (74 loc) · 2.14 KB
/
app.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
78
79
80
81
82
83
84
85
86
87
const fs = require('fs');
const express = require('express');
const cors = require('cors');
const path = require('path');
const app = express();
const http = require('http').Server(app);
/*
const io = require("socket.io")(http, {
cors: {
origin: ["http://remotevideocontroller.onrender.com", "chrome-extension://hkbagmafpdcfpjoeaookbcbjbijdmdnf"],
methods: ["GET", "POST"],
allowedHeaders: ["my-custom-header"],
credentials: true
}
});
*/
const io = require("socket.io")(http, { cors: '*' });
/*
const io = require("socket.io")(http, {
cors: {
origin: ["http://remotevideocontroller.onrender.com", "chrome-extension://hkbagmafpdcfpjoeaookbcbjbijdmdnf"],
methods: ["GET", "POST"]
}
});
*/
const port = process.env.port || 8000;
app.use(cors());
app.get('/', (req, res, next) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/home', (req, res, next) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/qr', (req, res, next) => {
res.sendFile(path.join(__dirname, 'test.html'));
});
app.get('/qr2', (req, res, next) => {
res.sendFile(path.join(__dirname, 'qrcodeTest.html'));
});
app.use(express.static(__dirname, {
extensions: ["html", "htm", "gif", "png", "js"],
}));
io.on("connection", (socket) => {
console.log("a user connected");
socket.on("disconnect", () => {
console.log("a user disconnected");
});
socket.on("join room", (id) => {
//socket.join("072");
console.log(id);
});
socket.on("video message", (a) => {
console.log(a);
socket.broadcast.emit("video message", a);
// Uncomment the following code if you want to save the data to a file
/*
if (a.playerstate == 1 || a.playerstate == 2 || a.playerstate == -1 || a.playerstate == 3) {
let data = JSON.stringify(a) + "\n";
fs.appendFile('./data.json', data, (err) => {
if (err) throw err;
console.log('Data written to file');
});
}
*/
});
/*
socket.on("video read", (a) => {
io.to(socket.id).emit("video read", fs.readFileSync('./data.json', 'utf-8'));
});
*/
});
http.listen(port, ["127.0.0.1"], () => {
console.log("Server started");
});