Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ProcFile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node server.js
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Zoom-Clone-With-WebRTC
### This is a working zoom but as basic , no additional functionality is added besides normal video calling in rooms.
### You could use the default id provided in the adress bar or you can use custom id by entring after the website address [Zoom-Clone-Link](https://zoom-clone123.herokuapp.com/custom-id-here "Zoom-Clone")
21 changes: 21 additions & 0 deletions heroku-ssl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Force load with https on production environment
* https://devcenter.heroku.com/articles/http-routing#heroku-headers
*/
module.exports = function(environments, status) {
environments = environments || ['production'];
status = status || 302;
return function(req, res, next) {
if (environments.indexOf(process.env.NODE_ENV) >= 0) {
if (req.headers['x-forwarded-proto'] !== 'https') {
res.redirect(status, 'https://' + req.hostname + req.originalUrl);
}
else {
next();
}
}
else {
next();
}
};
};
16 changes: 13 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"dependencies": {
"ejs": "^3.1.3",
"express": "^4.17.1",
"express-sslify": "^1.2.0",
"heroku-ssl-redirect": "^0.1.1",
"socket.io": "^2.3.0",
"uuid": "^8.1.0"
"uuid": "^8.3.0"
},
"devDependencies": {
"nodemon": "^2.0.4"
Expand Down
17 changes: 11 additions & 6 deletions public/script.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const socket = io('/')
const videoGrid = document.getElementById('video-grid')
const myPeer = new Peer(undefined, {
host: '/',
port: '3001'
})
const myPeer = new Peer()
let userCounter = 0
const myVideo = document.createElement('video')
myVideo.muted = true
const peers = {}
navigator.mediaDevices.getUserMedia({
video: true,
audio: true
audio: {
sampleSize:8,
echoCancellation: true
}
}).then(stream => {
addVideoStream(myVideo, stream)

Expand All @@ -23,11 +24,15 @@ navigator.mediaDevices.getUserMedia({

socket.on('user-connected', userId => {
connectToNewUser(userId, stream)
++userCounter
console.log(userCounter)
})
})

socket.on('user-disconnected', userId => {
if (peers[userId]) peers[userId].close()
--userCounter
console.log(userCounter)
})

myPeer.on('open', id => {
Expand All @@ -53,4 +58,4 @@ function addVideoStream(video, stream) {
video.play()
})
videoGrid.append(video)
}
}
6 changes: 4 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
const { v4: uuidV4 } = require('uuid')
const ssl = require('./heroku-ssl')
const port = process.env.PORT

app.set('view engine', 'ejs')
app.use(express.static('public'))

app.use(ssl())
app.get('/', (req, res) => {
res.redirect(`/${uuidV4()}`)
})
Expand All @@ -26,4 +28,4 @@ io.on('connection', socket => {
})
})

server.listen(3000)
server.listen(port || 3000)
4 changes: 2 additions & 2 deletions views/room.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<script>
const ROOM_ID = "<%= roomId %>"
</script>
<script defer src="https://unpkg.com/peerjs@1.2.0/dist/peerjs.min.js"></script>
<script defer src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>
<script src="/socket.io/socket.io.js" defer></script>
<script src="script.js" defer></script>
<title>Document</title>
Expand All @@ -28,4 +28,4 @@
<body>
<div id="video-grid"></div>
</body>
</html>
</html>