Node.JS TCP STUN server not receiving connection from RTCPeerConnection

587 views Asked by At

I've been doing some localized testing on the webkitRTCPeerConnection in Chrome 43, and running a local TCP server in node.js to receive the STUN packets from the peers. My client code (for local testing) is as follows:

// 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 socket server is only meant to receive the STUN packet and log it for now. It will eventually be a TCP STUN server as outlined in RFC 5389. For now here's the code for it:

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);
}

When the client code finishes running, peer1.iceConnectionState is "checking", and peer1.iceGatheringState, peer2.iceConnectionState and peer2.iceGatheringState all remain "new". Nothing logs on the TCP server except for Listening on port 8080. Can anyone tell me why no connection is opened if peer1.iceConnectionState is "checking"?

0

There are 0 answers