简体   繁体   中英

Hosting and deploy peerjs server

to help me with webRTC library 'peer.js'. To get it work i need a my-own server, so i try install peerjs on evennode.com. At hosting settings it's stated Startup command -> Detect automatically (recommended) (Your app is started with npm start in case package.json is available.).

So i did the next actions:

  1. created my new application-> http://mypeerjs.eu-4.evennode.com/
  2. unpacked and put in the hosting source my repository from https://github.com/peers/peerjs-server
  3. in that package .json there is: "scripts": { "test": "mocha test", "start": "peerjs --port 9000 --key peerjs" } also i tried to state (because i ran it from my local server)

    "start": "bin/peerjs --port ${PORT:=9000}"

The issue: The application doesnt start.The log writes next:

2018-01-27 18:41:41 102ea39d5429 ---> Starting app
2018-01-27 18:41:41 102ea39d5429 Detected package.json start script
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 > peer@0.2.8 start /data/app
2018-01-27 18:41:42 102ea39d5429 > peerjs --port 9000 --key peerjs
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 sh: 1: peerjs: not found
2018-01-27 18:41:42 102ea39d5429 npm ERR! peer@0.2.8 start: `peerjs --port 9000 --key peerjs`
2018-01-27 18:41:42 102ea39d5429 npm ERR! `sh "-c" "peerjs --port 9000 --key peerjs"` failed with 127
2018-01-27 18:41:42 102ea39d5429 npm ERR! 
2018-01-27 18:41:42 102ea39d5429 npm ERR! Failed at the peer@0.2.8 start script.
2018-01-27 18:41:42 102ea39d5429 npm ERR! This is most likely a problem with the peer package,
2018-01-27 18:41:42 102ea39d5429 npm ERR! not with npm itself.
2018-01-27 18:41:42 102ea39d5429 npm ERR! Tell the author that this fails on your system:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     peerjs --port 9000 --key peerjs
2018-01-27 18:41:42 102ea39d5429 npm ERR! You can get their info via:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     npm owner ls peer
2018-01-27 18:41:42 102ea39d5429 npm ERR! There is likely additional logging output above.
2018-01-27 18:41:42 102ea39d5429 
2018-01-27 18:41:42 102ea39d5429 npm ERR! System Linux 3.10.0-693.5.2.el7.x86_64
2018-01-27 18:41:42 102ea39d5429 npm ERR! command "/data/n/bin/node" "/data/n/bin/npm" "start"
2018-01-27 18:41:42 102ea39d5429 npm ERR! cwd /data/app
2018-01-27 18:41:42 102ea39d5429 npm ERR! node -v v0.9.1
2018-01-27 18:41:42 102ea39d5429 npm ERR! npm -v 1.1.59
2018-01-27 18:41:42 102ea39d5429 npm ERR! code ELIFECYCLE
2018-01-27 18:41:42 102ea39d5429 npm ERR! 
2018-01-27 18:41:42 102ea39d5429 npm ERR! Additional logging details can be found in:
2018-01-27 18:41:42 102ea39d5429 npm ERR!     /data/app/npm-debug.log
2018-01-27 18:41:42 102ea39d5429 npm ERR! not ok code 0

On my local server it's deployed successfully I unpacked the archive, moved to <path_to_peerjs-server>/bin and used a line to run it with node: node peerjs --port 9000 --key peerjs My server in my home net successfully run, browser peers connects to each other and everything works. HERE IS THE LOG FROM LOCAL SERVER But on the hosting it doesnt so i ask your help. In log, as i got,there is an error

18:41:42 102ea39d5429 npm ERR! peerjs --port 9000 --key peerjs

Thanks for advance!

EDIT i upploaded the application to my hosted server:

var http = require('http');
var server = http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello world!');
});
server.listen(process.env.PORT);

and it works,you may see it. I feel the problem is with listener port opening

let peer = new Peer({host:'peerjs-server.herokuapp.com', secure:true, port:443})

而不是托管您自己的对等服务器

When you create a peer in the script file for your application, include this

const peer = new Peer({
     path: '/peerjs',
     host: '/',
     port: '443'
})

Can also remove port if not need. My server config is like below

const myPeer = new Peer({host: 'peerjs-server.herokuapp.com', secure: true, path: '/peerapp'})

With WebRTC, it will be a mistake to use such an old project like peerjs - no one has updated it in the past 3 years. Don't expect it to work...

If you want to stay in the realm of simple, then look at https://github.com/feross/simple-peer

And check here for some other alternatives as well: https://www.quora.com/Which-is-the-best-WebRTC-JavaScript-library-PeerJS-or-EasyRTC

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM