托管和部署peerjs服务器

时间:2018-01-27 20:26:31

标签: node.js server webrtc hosting peerjs

帮助我使用webRTC库' peer.js'。为了使它工作,我需要一个我自己的服务器,所以我尝试在evennode.com上安装peerjs。在托管设置中,它声明了启动命令 - >自动检测(推荐)(如果package.json可用,您的应用程序将以npm start启动。)。

所以我做了下一步行动:

  1. 创建了我的新应用程序 - > http://mypeerjs.eu-4.evennode.com/
  2. 解压缩并从https://github.com/peers/peerjs-server
  3. 放入托管源我的存储库
  4. 在那个包中.json有: "脚本":{"测试":" mocha测试","开始":" peerjs --port 9000 --key peerjs" } 我也尝试说(因为我是从我的本地服务器运行的)

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

  5. 问题:应用程序没有启动。日志写下:

    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
    

    在我的本地服务器上已成功部署 我解压缩了存档,移动到<path_to_peerjs-server>/bin并使用一行来运行它与节点: node peerjs --port 9000 --key peerjs 我的家庭网络中的服务器成功运行,浏览器对等体相互连接,一切正常。 HERE IS THE LOG FROM LOCAL SERVER 但在主机上它并没有,所以我问你的帮助。 在日志中,正如我所知,有一个错误

      

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

    感谢您提前!

    编辑我将应用程序重新加载到托管服务器:

    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);
    

    它有效,你可能会看到它。 我觉得问题在于侦听器端口打开

4 个答案:

答案 0 :(得分:7)

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

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

答案 1 :(得分:1)

使用WebRTC,使用像peerjs这样的老项目是错误的 - 过去3年没有人更新过它。不要指望它能起作用......

如果您希望保持简单,请查看https://github.com/feross/simple-peer

并在此处查看其他一些替代方案:https://www.quora.com/Which-is-the-best-WebRTC-JavaScript-library-PeerJS-or-EasyRTC

答案 2 :(得分:1)

在脚本文件中为您的应用程序创建对等项时,请包括

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

答案 3 :(得分:0)

如果不需要,也可以删除端口。我的服务器配置如下

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