Node.JS TCP STUN服务器未从RTCPeerConnection接收连接

时间:2015-06-19 19:18:15

标签: javascript node.js tcp webrtc stun

我一直在Chrome 43中的webkitRTCPeerConnection上进行一些本地化测试,并在node.js中运行本地TCP服务器以接收来自对等方的STUN数据包。我的客户端代码(用于本地测试)如下:

// Chrome only

var iceServers = {
    iceServers: [{
      url: "stun:localhost:8080"
    }]
  },
  optional = {
    optional: [{
      DtlsSrtpKeyAgreement: true
    }, {
      RtpDataChannels: true
    }]
  },
  peer1 = new webkitRTCPeerConnection(iceServers, optional),
  peer2 = new webkitRTCPeerConnection(iceServers, optional);

peer1.createOffer(function(offer) {
  peer1.setLocalDescription(offer);
  peer2.setRemoteDescription(offer);
  peer2.createAnswer(function(answer) {
    peer1.setRemoteDescription(answer);
  });
});

My Node.JS TCP套接字服务器仅用于接收STUN数据包并立即记录。它最终将成为RFC 5389中概述的TCP STUN服务器。现在这里是它的代码:

var net = require('net'),
    options = {
        allowHalfOpen: true
    },
    port = 8080,
    server = net.createServer(options, connectionListener);

server.listen(port, listening);

function connectionListener(connection) {
    var data = '';

    console.log('Connection opened');

    connection.setEncoding('utf8');

    connection.on('data', function (buffer) {
        console.log('data received');

        data += buffer;
    });

    connection.on('end', function () {
        console.log('data stream ended');

        connection.end();

        console.log('----\n%s\n----', data);
    });
}

function listening() {
    console.log('Listening on port %d', port);
}

当客户端代码完成运行时,peer1.iceConnectionState"checking",而peer1.iceGatheringStatepeer2.iceConnectionStatepeer2.iceGatheringState都保留"new"。除了Listening on port 8080之外,TCP服务器上没有任何日志。任何人都可以告诉我为什么peer1.iceConnectionState"checking"时没有打开任何关联?

0 个答案:

没有答案