-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
128 lines (106 loc) · 3.42 KB
/
index.js
File metadata and controls
128 lines (106 loc) · 3.42 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
const express = require('express')
require('./models')
const mongoose = require('mongoose');
const comp = require('compression');
const bp = require('body-parser');
const app = express()
const fs = require('fs')
var privateKey = fs.readFileSync('private.key', 'utf8');
var certificate = fs.readFileSync('certificate.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
const server = require('https').createServer(credentials, app);
const PORT = 80;
const PORTS = 443;
// HTTP to HTTPS
var http = express();
http.get('/.well-known/pki-validation/D8BECDC63A87B87D0E7452A3AF93CEE2.txt', (req, res)=>{
res.sendFile(__dirname+'/D8BECDC63A87B87D0E7452A3AF93CEE2.txt');
});
http.get('*', function(req, res) {
res.redirect('https://' + req.headers.host + req.url);
})
var listen = http.listen(PORT,()=>{
console.log("Secondary Server Started On Port "+listen.address().port);
});
const cors = require('cors')
const { ExpressPeerServer } = require('peer');
const peerServer = ExpressPeerServer(server,{
debug: true
})
const io = require('socket.io')(server);
app.use(bp.json({limit: '50mb'}));
app.use(comp());
app.use(cors());
app.use('/peerjs', peerServer);
const streams = {};
const host = {};
const rooms = {};
io.on('connection', socket => {
console.log("Connection")
socket.on('create-room', (roomId, peerId)=>{
streams[roomId] = peerId;
host[roomId] = socket;
rooms[roomId] = [socket];
console.log('Room created with peerId of '+peerId);
console.log("Room's Id: "+roomId);
socket.on('disconnect', ()=>{
rooms[roomId].forEach(peer => {
peer.emit('host-disconnected');
})
delete rooms[roomId];
delete host[roomId];
delete streams[roomId];
})
})
socket.on('join-room', (roomId, id)=>{
socket.emit('roomId', streams[roomId]);
console.log("Viewer Entered in Room: "+roomId);
if(host[roomId]) host[roomId].emit('watcher-connected', id);
})
socket.on('join-call', (roomId, id)=>{
if(rooms[roomId]){
rooms[roomId].forEach(peer => {
if(peer.connected){
peer.emit('user-connected', id);
}
});
rooms[roomId].push(socket);
}
socket.on('disconnect', ()=>{
if(rooms[roomId]){
rooms[roomId].forEach(peer => {
if(peer.connected){
peer.emit('user-disconnected', id);
}
});
}
})
})
})
require('./routes/torrent')(app);
require('./routes/movies')(app);
app.get('/', (req, res)=>{
res.sendFile(__dirname+'/index.html');
});
app.get('/.well-known/pki-validation/D8BECDC63A87B87D0E7452A3AF93CEE2.txt', (req, res)=>{
res.sendFile(__dirname+'/D8BECDC63A87B87D0E7452A3AF93CEE2.txt');
});
app.get('/player/:mag', (req, res)=>{
res.sendFile(__dirname+'/player.html');
});
app.get('/room/:id', (req, res)=>{
res.sendFile(__dirname+'/room.html');
});
app.get('/about', (req, res)=>{
res.sendFile(__dirname+'/about.html');
});
app.get('/newNewFlu', (req, res)=>{
res.sendFile(__dirname+'/addNew.html');
});
app.get('/newNewglu', (req, res)=>{
res.sendFile(__dirname+'/addSeries.html');
});
app.use(express.static('./statics'));
server.listen(PORTS,()=>{
console.log("Server started on PORT "+server.address().port);
});