-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
44 lines (39 loc) · 1.12 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
const express = require('express');
const http = require('http');
const https = require('https');
const fs = require('fs');
const app = express();
const SocketIo = require('socket.io');
app.use(express.static(__dirname + '/dist'));
// const httpServer = http.createServer(app);
// const wsServer = SocketIo(httpServer);
// httpServer.listen(80, () => {
// console.log('http server started');
// });
const httpsServer = https.createServer(
{
ca: fs.readFileSync('./ssl/ca_bundle.crt'),
key: fs.readFileSync('./ssl/private.key'),
cert: fs.readFileSync('./ssl/certificate.crt'),
},
app,
);
const wsServer = SocketIo(httpsServer);
httpsServer.listen(443, () => {
console.log('https server started');
});
wsServer.on('connection', (socket) => {
socket.on('joinRoom', (roomId) => {
socket.join(roomId);
socket.to(roomId).emit('userJoin');
});
socket.on('offer', (roomId, offer) => {
socket.to(roomId).emit('offer', offer);
});
socket.on('answer', (roomId, answer) => {
socket.to(roomId).emit('answer', answer);
});
socket.on('candidate', (roomId, candidate) => {
socket.to(roomId).emit('candidate', candidate);
});
});