kirm / sip.js

Session Initiation Protocol for node.js
MIT License
431 stars 171 forks source link

Need a simple application for measuring response time. #127

Open DmitryIsakbayev opened 6 years ago

DmitryIsakbayev commented 6 years ago

I need a simple application that measures response times for the progress and final messages. It is working, but the calculated times are very different from the times reported on the wire.

For example, while my application reports 14ms progress and 29ms final, the actual messages on the wire arrive after less than 1ms and 16ms.

I have tried a similar test using SIPp and its results are very close to the actual messages on the wire.

What can I do to improve accuracy?

Here is a simplified version of my code

function ping(fromUser,toUser,toHost) {
  var to = 'sip:' + toUser + '@' + toHost;
  var from='sip:'+fromUser + '@' + 'sip-ping-test';
  var startTime = new Date();

  sip.send({
    method: 'INVITE',
    uri: to,
    headers: {
      to: {uri: to},
      from: {uri: from, params: {tag: rstring()}},
      'call-id': rstring(),
      cseq: {method: 'INVITE', seq: Math.floor(Math.random() * 1e5)},
      contact: [{uri: from}]
    }
  },
  function(rs) {
    if (rs.status < 200) { 
      console.info('progressResponseTime = ' + (new Date() - startTime));
    } else {
      console.info('finalResponseTime = ' + (new Date() - startTime));
    }
  });
}
DmitryIsakbayev commented 6 years ago

Perhaps a stateless client will be more accurate. Is there an example? I see an example for stateless-registrar-redirector.js

DmitryIsakbayev commented 6 years ago

Using the transport API seems to produce similar results.

var startTime;

var transport = sip.makeTransport({publicAddress : localIp}, function(rs, remote) {
  if (rs.status < 200) {
    console.info('progressResponseTime = ' + (new Date() - startTime));
  } else {
    console.info('finalResponseTime = ' + (new Date() - startTime));
  }
});

function ping(fromUser,toUser,toHost) {
  var to = 'sip:' + toUser + '@' + toHost;
  var from='sip:'+fromUser + '@' + 'sip-ping-test';

  var remote =
    {
      "protocol": "UDP",
      "address": toHost,
      "port": 5060
    };

  var message = 
    {
      method: 'INVITE',
      uri: to,
      headers: {
        to: {uri: to},
        from: {uri: from, params: {tag: rstring()}},
        'call-id': rstring(),
        cseq: {method: 'INVITE', seq: Math.floor(Math.random() * 1e5)},
        contact: [{uri: from}],
        via: [{params: {}}]
      }
    };

  startTime = new Date();
  transport.send(remote,message);
}