I have created a simple video chat app using javascript's webRTC library peerjs. And now I am trying to deploy the site on zeit.co. But I get the error when a peerjs instance gets created Below is the code where I have mentioned ports and host to run the server
Server side code
const express = require('express')
const app = express()
const path = require('path')
const server = require('http').createServer(app)
const io = require('socket.io').listen(server)
const srv = server.listen(3000)
app.use('/peerjs', require('peer').ExpressPeerServer(srv, {
debug: true
}))
const users = []
const connections = []
server.listen(3000, () => {
console.log('server running')
})
app.use(express.static(path.join(__dirname, 'public')))
app.get('/', (req, res) => {
})
Client side code
const peerObj = {
host: '127.0.0.1',
path: '/peerjs',
debug: 3,
config: {icerServers: [
{ url: 'stun:stun1.l.google.com:19302' },
{ url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: '[email protected]' }
]}
}
peer = new Peer(peerObj)
But there is some good news; PeerJS is a WebRTC framework that abstracts away all of the ice and signalling logic so that you can focus on the functionality of your application. There are two parts to PeerJS, the client-side framework and the server.
PeerJS simplifies WebRTC peer-to-peer data, video, and audio calls. PeerJS wraps the browser's WebRTC implementation to provide a complete, configurable, and easy-to-use peer-to-peer connection API. Equipped with nothing but an ID, a peer can create a P2P data or media stream connection to a remote peer.
There is DataConnection. close() function to close the connection between peers.
I have found a solution for my question. Actually peer server runs on http, and for making it run on https, we have to generate a ssl key and certificate. Even after generating the keys and certificates it will only run on local host and the systems connected to that network.
There is a peer server hosted on heroku, so it is running on https, rather than running your own peer server, we can mention the path of the heroku peer server and then host the app on some hosting website, The app will run properly. Below is my new client side code
peer = new Peer({host:'peerjs-server.herokuapp.com', secure:true, port:443})
and this will run the app properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With