0

我正在尝试通过 Internet 连接获得一个 hello worlds WebRTC 示例,这与我正在使用此代码的本地计算机不同


    <html>
      <head>
        <title>WebRTC Tests</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <script type="text/javascript" src="./simplepeer.min.js"></script>
      </head>
      <body>
        <style>
          #outgoing {
            width: 600px;
            word-wrap: break-word;
            white-space: normal;
          }
        </style>
        <form>
          <textarea id="incoming"></textarea>
          <button type="submit">submit</button>
        </form>
        <pre id="outgoing"></pre>
        <script src="simplepeer.min.js"></script>
        <script>
          const p = new SimplePeer({
            initiator: location.hash === "#1",
            config: {
              sdpSemantics: "unified-plan",
              iceTransportPolicy: "relay",
              reconnectTimer: 100,
              iceServers: [
                { urls: ["stun:eu-turn8.xirsys.com"] },
                {
                  username:"my_username",
                  credential: "my_password",
                  urls: [
                    "turn:eu-turn8.xirsys.com:80?transport=udp",
                    "turn:eu-turn8.xirsys.com:3478?transport=udp",
                    "turn:eu-turn8.xirsys.com:80?transport=tcp",
                    "turn:eu-turn8.xirsys.com:3478?transport=tcp",
                    "turns:eu-turn8.xirsys.com:443?transport=tcp",
                    "turns:eu-turn8.xirsys.com:5349?transport=tcp",
                  ],
                },
              ],
            },
            trickle: false,
          });
    
          p.on("error", (err) => console.log("error", err));
    
          p.on("signal", (data) => {
            console.log("SIGNAL", JSON.stringify(data));
            document.querySelector("#outgoing").textContent = JSON.stringify(data);
          });
    
          document.querySelector("form").addEventListener("submit", (ev) => {
            ev.preventDefault();
            p.signal(JSON.parse(document.querySelector("#incoming").value));
          });
    
          p.on("connect", () => {
            console.log("CONNECT");
            p.send("whatever" + Math.random());
          });
    
          p.on("data", (data) => {
            console.log("data: " + data);
          });
        </script>
      </body>
    </html>

我认为同伴成功连接到冰服务器

我得到这样的东西


    {"type":"offer","sdp":"v=0\r\no=- 2164965454299906991 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=msid-semantic: WMS\r\nm=application 58912 UDP/DTLS/SCTP webrtc-datachannel\r\nc=IN IP4 178.128.172.237\r\na=candidate:4213592065 1 udp 33563647 178.128.172.237 58912 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:4213592065 1 udp 33563391 178.128.172.237 65469 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3716587576 1 udp 16785919 159.89.29.206 61355 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3716587576 1 udp 16785663 159.89.29.206 64585 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=candidate:3273125197 1 udp 7935 159.89.29.206 61649 typ relay raddr 0.0.0.0 rport 0 generation 0 network-cost 999\r\na=ice-ufrag:l/P6\r\na=ice-pwd:o44fq+dTPwzTMqdJyepGYS9C\r\na=fingerprint:sha-256 98:DA:31:33:23:0D:D3:BD:9B:4A:C5:89:79:0D:99:E4:38:45:45:84:67:CB:FC:31:31:7C:6B:C2:D8:C2:72:D8\r\na=setup:actpass\r\na=mid:0\r\na=sctp-port:5000\r\na=max-message-size:262144\r\n"}

但对等方无法相互连接

    error Error: Connection failed.
        at a (VM70468 simplepeer.min.js:6)
        at p._onConnectionStateChange (VM70468 simplepeer.min.js:6)
        at RTCPeerConnection._pc.onconnectionstatechange (VM70468 simplepeer.min.js:6)

我的 chrome://webrtc-internals/ 日志看起来像这样


    https://www.riseofbots.com/webrtc/index.html#1, { iceServers: [stun:eu-turn8.xirsys.com, turn:eu-turn8.xirsys.com:80?transport=udp, turn:eu-turn8.xirsys.com:3478?transport=udp, turn:eu-turn8.xirsys.com:80?transport=tcp, turn:eu-turn8.xirsys.com:3478?transport=tcp, turns:eu-turn8.xirsys.com:443?transport=tcp, turns:eu-turn8.xirsys.com:5349?transport=tcp], iceTransportPolicy: relay, bundlePolicy: balanced, rtcpMuxPolicy: require, iceCandidatePoolSize: 0, sdpSemantics: "unified-plan" },
    
    Time    Event
    8/29/2020, 7:41:24 PM   
    createLocalDataChannel
    8/29/2020, 7:41:24 PM   negotiationneeded
    8/29/2020, 7:41:24 PM   
    createOffer
    8/29/2020, 7:41:24 PM   
    createOfferOnSuccess
    8/29/2020, 7:41:24 PM   
    setLocalDescription (munged)
    8/29/2020, 7:41:24 PM   
    signalingstatechange
    8/29/2020, 7:41:24 PM   setLocalDescriptionOnSuccess
    8/29/2020, 7:41:24 PM   
    icegatheringstatechange
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:24 PM   
    icecandidateerror
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icecandidate (relay)
    8/29/2020, 7:41:25 PM   
    icegatheringstatechange
    8/29/2020, 7:42:50 PM   
    setRemoteDescription
    8/29/2020, 7:42:50 PM   
    signalingstatechange
    8/29/2020, 7:42:50 PM   
    signalingstatechange
    8/29/2020, 7:42:50 PM   setRemoteDescriptionOnSuccess
    8/29/2020, 7:42:50 PM   
    createAnswer
    8/29/2020, 7:42:50 PM   
    createAnswerOnSuccess
    8/29/2020, 7:42:50 PM   
    setLocalDescription (munged)
    8/29/2020, 7:42:50 PM   
    signalingstatechange
    8/29/2020, 7:42:50 PM   setLocalDescriptionOnSuccess
    8/29/2020, 7:42:50 PM   
    icegatheringstatechange
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    icecandidateerror
    8/29/2020, 7:42:50 PM   
    iceconnectionstatechange
    8/29/2020, 7:42:50 PM   
    iceconnectionstatechange (legacy)
    8/29/2020, 7:42:50 PM   
    connectionstatechange
    8/29/2020, 7:42:50 PM   
    icecandidate (relay)
    8/29/2020, 7:42:50 PM   
    icecandidate (relay)
    8/29/2020, 7:42:51 PM   
    icecandidate (relay)
    8/29/2020, 7:42:51 PM   
    icecandidate (relay)
    8/29/2020, 7:42:51 PM   
    icecandidate (relay)
    8/29/2020, 7:42:51 PM   
    icecandidate (relay)
    8/29/2020, 7:42:51 PM   
    icegatheringstatechange
    8/29/2020, 7:43:07 PM   
    iceconnectionstatechange
    8/29/2020, 7:43:07 PM   
    iceconnectionstatechange (legacy)
    8/29/2020, 7:43:07 PM   
    connectionstatechange
    8/29/2020, 7:43:07 PM   close
    8/29/2020, 7:43:07 PM   
    connectionstatechange
    Stats Tables
    RTCCertificate_90:CC:82:30:06:17:A9:46:56:60:C1:B9:3D:AE:F9:AD:20:5F:1B:7B:49:12:8B:5C:B0:82:9E:CA:5A:30:04:70 (certificate)
    RTCDataChannel_6 (data-channel)
    RTCPeerConnection (peer-connection)
    RTCTransport_0_1 (transport)
    RTCIceCandidatePair_A3CDTSBV_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_A3CDTSBV_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_A3CDTSBV_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_A3CDTSBV_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_A3CDTSBV_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_A3CDTSBV_pPd2PFqR (candidate-pair)
    RTCIceCandidatePair_UB759FSC_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_UB759FSC_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_UB759FSC_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_UB759FSC_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_UB759FSC_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_UB759FSC_pPd2PFqR (candidate-pair)
    RTCIceCandidate_A3CDTSBV (local-candidate)
    RTCIceCandidate_H+8IMlJN (remote-candidate)
    RTCIceCandidate_OeCFMKnA (remote-candidate)
    RTCIceCandidate_UB759FSC (local-candidate)
    RTCIceCandidate_UybVjbsA (remote-candidate)
    RTCIceCandidate_aCTtFtgZ (remote-candidate)
    RTCIceCandidate_jNRqBEDa (remote-candidate)
    RTCIceCandidate_pPd2PFqR (remote-candidate)
    RTCIceCandidatePair_+D71hhQo_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_+D71hhQo_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_+D71hhQo_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_+D71hhQo_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_+D71hhQo_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_+D71hhQo_pPd2PFqR (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_FtqjTR78_pPd2PFqR (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_TyMs9u0h_pPd2PFqR (candidate-pair)
    RTCIceCandidatePair_thN/4O23_H+8IMlJN (candidate-pair)
    RTCIceCandidatePair_thN/4O23_OeCFMKnA (candidate-pair)
    RTCIceCandidatePair_thN/4O23_UybVjbsA (candidate-pair)
    RTCIceCandidatePair_thN/4O23_aCTtFtgZ (candidate-pair)
    RTCIceCandidatePair_thN/4O23_jNRqBEDa (candidate-pair)
    RTCIceCandidatePair_thN/4O23_pPd2PFqR (candidate-pair)
    RTCIceCandidate_+D71hhQo (local-candidate)
    RTCIceCandidate_FtqjTR78 (local-candidate)
    RTCIceCandidate_TyMs9u0h (local-candidate)
    RTCIceCandidate_thN/4O23 (local-candidate)
    Stats graphs for RTCPeerConnection (peer-connection)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_A3CDTSBV_pPd2PFqR (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_UB759FSC_pPd2PFqR (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_+D71hhQo_pPd2PFqR (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_FtqjTR78_pPd2PFqR (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_TyMs9u0h_pPd2PFqR (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_H+8IMlJN (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_OeCFMKnA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_UybVjbsA (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_aCTtFtgZ (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_jNRqBEDa (candidate-pair)
    Stats graphs for RTCIceCandidatePair_thN/4O23_pPd2PFqR (candidate-pair)

我真的不知道我做错了什么?

4

1 回答 1

0

对我来说,以下初始化参数有效:

new SimplePeer({
    initiator: location.hash === "#1",
    stream: localStream, //(optional stream for video/audio)
    config: {
      iceServers: [{
        urls: "stun:stun.l.google.com:19302"
      }]
    }
})

你也可以添加你的转弯服务器,但如果它在同一个网络中,则不需要眩晕和转弯。这里还有一个示例项目,您可以用作参考。带演示

于 2020-08-29T18:24:50.247 回答