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

Viewed 5668

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: 'webrtc@live.com' }
  ]}
}

peer = new Peer(peerObj)
  • List item
3 Answers

Hi if you dont want to depend herokuapp as Aish said

you can run on the terminal:

npm install peer

Then your server.js you add: `

 //Peer server
    var privateKey  = fs.readFileSync('sslcert/server.key', 'utf8');
    var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');

  const { PeerServer } = require('peer');
  const peerServer = PeerServer({ port: 443, 
                                path: '/' ,
                                ssl: {
                                    key: privateKey,
                                    cert: certificate
                                  }
                            
                            });

` The privatekey and certificates are needed for HTTPS. Make sure to have them on the paths where they are fetched. Make sure that on client side (script run on index.html) you have:

myPeer = new Peer({host:'/', 
                  secure:true,
                   port:443,
                path: '/'})
Related