【问题标题】:Custom PeerJs Server giving ERR_CONNECTION_TIMED_OUT自定义 PeerJs 服务器提供 ERR_CONNECTION_TIMED_OUT
【发布时间】:2017-10-30 17:09:00
【问题描述】:

所以我使用以下命令在我的 digitalocean 主机上安装了 peerjs 服务器。

 npm install peer
 peerjs --port 9000 --key peerjs

运行上述命令后,腻子给出以下打印:

在 :: 上启动 PeerServer,端口:9000,路径:/ (v. 0.2.8)

以下是我的 index.html 代码:

<!DOCTYPE html>
<html>
<head>
    <title>Peer JS Testing</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.13/peer.js"></script>
    <script>
        $(document).ready(function(){
                // var peer = new Peer({key: 'r6xc2gopu33j714i'});
                // var peer = new Peer({ host: '139.59.3.130', port: 9000, debug: 3});
                var peer = new Peer('', {host: 'thegraphicplanet.com', port: 9000});
                var anotherid;
                var mypeerid;
                mypeerid = peer.id;
                setTimeout(function(){
                    console.log(peer);
                    $('#showid').text('Your ID is: '+peer.id);
                }, 3000);

                $('.connect').click(function(){
                    anotherid = document.getElementById('anotherid').value;



                    // var conn = peer.connect(anotherid);
                    // conn.on('open', function(){
                    //   conn.send('hi!');
                    // });


                    navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                    navigator.getUserMedia({video: true, audio: true}, function(stream) {
                      var call = peer.call(anotherid, stream);
                      call.on('stream', function(remoteStream) {
                        $('.showvideo').prop('src', URL.createObjectURL(stream));
                      });
                    }, function(err) {
                      console.log('Failed to get local stream' ,err);
                    });



                });

                /*
                peer.on('connection', function(conn) {
                  conn.on('data', function(data){
                    // Will print 'hi!'
                    console.log(data);
                  });
                });
                */

                navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                peer.on('call', function(call) {
                  navigator.getUserMedia({video: true, audio: true}, function(stream) {
                    call.answer(stream); // Answer the call with an A/V stream.
                    call.on('stream', function(remoteStream) {
                        $('.showvideo').src = URL.createObjectURL(remotestream);
                        $('.showvideo').play();
                    });
                  }, function(err) {
                    console.log('Failed to get local stream' ,err);
                  });
                });

        });
    </script>
</head>
<body>


<h1 id="showid"></h1>

<label>Enter ID and Connect</label>
<input type="text" id="anotherid" />
<button class="connect">Connect</button>

<video class="showvideo" autoplay></video>

</body>
</html>

当我通过我的 URL 访问它时:https://thegraphicplanet.com/aumkarsandbox/peerjs/

控制台报如下错误:

:9000/peerjs/id?ts=15093825487790.7152652631730707 加载资源失败:net::ERR_CONNECTION_TIMED_OUT

【问题讨论】:

  • 你应该添加 node.js 而不是 JavaScript 作为标签 ;-)
  • 我认为这意味着您的服务器没有运行。默认情况下,您的 digitalocean 盒子上可能未打开端口 9000

标签: javascript webrtc peerjs


【解决方案1】:

也许它变老了,但我有一些东西要提醒所有新使用 peerjs 库或新使用 linux 环境的开发人员。

运行像peerjs --port 9000 --key peerjs 这样的单行命令,它会在您没有关闭服务器时运行。当你按下Ctrl + C按钮时它会停止。

您可以尝试在后台运行命令。尝试使用此命令:

nohup peerjs --port 9000 --key peerjs &gt; /dev/null 2&gt;&amp;1 &amp;

nohup 命令可以在后台运行你的单行命令,这样你就可以用你当前的终端开始做其他事情了。

要关闭连接,您可以使用以下步骤:

  1. 搜索PID(进程ID):ps -ef | grep peerjs
  2. 从 PID 列表中,然后键入:kill &lt;your pid&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-22
    • 1970-01-01
    • 2013-11-01
    • 2019-12-12
    • 2014-12-01
    • 1970-01-01
    • 2012-05-05
    • 1970-01-01
    相关资源
    最近更新 更多