Custom PeerJs Server giving ERR_CONNECTION_TIMED_OUT

久未见 提交于 2019-12-11 07:33:34

问题


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:

Started PeerServer on ::, port: 9000, path: / (v. 0.2.8)

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>

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 Failed to load resource: net::ERR_CONNECTION_TIMED_OUT

来源:https://stackoverflow.com/questions/47020721/custom-peerjs-server-giving-err-connection-timed-out

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!