Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GET https://127.0.0.1:9000/peerjs/peerjs/id?ts=14993271469660.591159722513086 net::ERR_CONNECTION_REFUSED

Tags:

node.js

peerjs

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)
  • List item
like image 234
Aishwarya Chaturvedi Avatar asked Jul 06 '17 08:07

Aishwarya Chaturvedi


People also ask

What is PeerJS used for?

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.

What is PeerJS in Nodejs?

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.

How do I close PeerJS connection?

There is DataConnection. close() function to close the connection between peers.


1 Answers

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.

like image 200
Aishwarya Chaturvedi Avatar answered Oct 01 '22 21:10

Aishwarya Chaturvedi