自定义 PeerJs 服务器提供 ERR_CONNECTION_TIMED_OUT [英] Custom PeerJs Server giving ERR_CONNECTION_TIMED_OUT

查看:63
本文介绍了自定义 PeerJs 服务器提供 ERR_CONNECTION_TIMED_OUT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So I installed peerjs server on my digitalocean hosting using following command.

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

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

After running above command the putty gave following print:

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

以下是我的 index.html 代码:

Following is my index.html code:

<!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/

When I access it on my URL: https://thegraphicplanet.com/aumkarsandbox/peerjs/

它在控制台上出现以下错误:

It is giving following error on console:

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

:9000/peerjs/id?ts=15093825487790.7152652631730707 Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

推荐答案

也许它已经老了,但我有一些事情要提醒所有新使用 peerjs 库或新使用 linux 环境的开发人员.

Maybe it getting old but I have something to remind all developer who newly uses peerjs library or newly with linux environment.

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

Running a single line command like peerjs --port 9000 --key peerjs, it runs while you are not close your server. It will stop when you press Ctrl + C button.

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

You can try to run the command background. Try use this command:

nohup peerjs --port 9000 --key peerjs >/dev/null 2>&1 &

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

The nohup command can run your single line command in the background, so then u can start do other thing with your current terminal.

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

To close the connection, you may use below step:

  1. 搜索PID(进程ID):ps -ef |grep peerjs
  2. 从PID列表中输入:kill

这篇关于自定义 PeerJs 服务器提供 ERR_CONNECTION_TIMED_OUT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆