diff --git a/ProcFile b/ProcFile new file mode 100644 index 0000000..489b270 --- /dev/null +++ b/ProcFile @@ -0,0 +1 @@ +web: node server.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..c0eb842 --- /dev/null +++ b/README.md @@ -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") diff --git a/heroku-ssl.js b/heroku-ssl.js new file mode 100644 index 0000000..3f442c0 --- /dev/null +++ b/heroku-ssl.js @@ -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(); + } + }; +}; \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index f5f2dc4..e4c1a7f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -660,6 +660,11 @@ "vary": "~1.1.2" } }, + "express-sslify": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/express-sslify/-/express-sslify-1.2.0.tgz", + "integrity": "sha1-MOhLzu0VV+sYdnK74UMKCioQDZw=" + }, "filelist": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/filelist/-/filelist-1.0.1.tgz", @@ -784,6 +789,11 @@ "integrity": "sha512-UqBRqi4ju7T+TqGNdqAO0PaSVGsDGJUBQvk9eUWNGRY1CFGDzYhLWoM7JQEemnlvVcv/YEmc2wNW8BC24EnUsw==", "dev": true }, + "heroku-ssl-redirect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/heroku-ssl-redirect/-/heroku-ssl-redirect-0.1.1.tgz", + "integrity": "sha512-kL/DvLR2J53iB3TXasQlo5JwF/j2L2zkala6Ddk9o6JwIPeDvbTGT9Aty8WElxcF389ObICCeyf2m7RKpCg5Bg==" + }, "http-cache-semantics": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", @@ -1749,9 +1759,9 @@ "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" }, "uuid": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.1.0.tgz", - "integrity": "sha512-CI18flHDznR0lq54xBycOVmphdCYnQLKn8abKn7PXUiKUGdEd+/l9LWNJmugXel4hXq7S+RMNl34ecyC9TntWg==" + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.0.tgz", + "integrity": "sha512-fX6Z5o4m6XsXBdli9g7DtWgAx+osMsRRZFKma1mIUsLCz6vRvv+pz5VNbyu9UEDzpMWulZfvpgb/cmDXVulYFQ==" }, "vary": { "version": "1.1.2", diff --git a/package.json b/package.json index 7215838..8a0741f 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/public/script.js b/public/script.js index e9c41c5..be51b47 100644 --- a/public/script.js +++ b/public/script.js @@ -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) @@ -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 => { @@ -53,4 +58,4 @@ function addVideoStream(video, stream) { video.play() }) videoGrid.append(video) -} \ No newline at end of file +} diff --git a/server.js b/server.js index 0033e80..4b5a518 100644 --- a/server.js +++ b/server.js @@ -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()}`) }) @@ -26,4 +28,4 @@ io.on('connection', socket => { }) }) -server.listen(3000) \ No newline at end of file +server.listen(port || 3000) \ No newline at end of file diff --git a/views/room.ejs b/views/room.ejs index 269ae95..b86243b 100644 --- a/views/room.ejs +++ b/views/room.ejs @@ -7,7 +7,7 @@ - + Document @@ -28,4 +28,4 @@
- \ No newline at end of file +