-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
33 lines (28 loc) · 921 Bytes
/
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
const express = require("express");
const app = express();
const server = require('http').Server(app);
const io=require('socket.io')(server);
const {v4:uuidV4} = require("uuid");
app.set('view engine','ejs');
app.use(express.static('public'));
app.get('/',(req,res)=>{
res.redirect(`/${uuidV4()}`)
});
var ExpressPeerServer = require('peer').ExpressPeerServer;
var peerExpress = require('express');
var peerApp = peerExpress();
var peerServer = require('http').Server(peerApp);
var options = { debug: true }
var peerPort = 9000;
peerApp.use('/peerjs', ExpressPeerServer(peerServer, options));
app.get('/:room',(req,res)=>{
res.render('room',{roomId:req.params.room})
})
io.on('connection',(socket)=>{
socket.on('join-room',(roomId,userId)=>{
socket.join(roomId);
socket.to(roomId).broadcast.emit("user-connected",userId);
});
})
server.listen(3030);
peerServer.listen(peerPort);