kirm / sip.js

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

Very slow proxy #99

Open FerdinandvHagen opened 9 years ago

FerdinandvHagen commented 9 years ago

Hey,

I am trying to build a very basic proxy to send Notifications to a phone when someone is trying to call. The problem is that Microsoft doesn't allow an app to run in the background on Windows Phone to wait for a call as you would need for VOIP. You have to send a notification to the phone which launches the app and then you have to do the Register stuff, etc. I know mainly two Apps right now, one of them being Linphone.

I have a basic example working. The only problem I currently have is that there is an extreme delay between the calls. Especially if I try to send a message from my sip.js to the SIP-Server. Everything else like 'INVITE', 'ACK', etc. seems to be delivered nearly instantaneously. But the REGISTER takes about 35 seconds until the packet gets forwarded to the SIP-Server.

My current code:

proxy.start({
    logger: {
        recv: function (m) { console.error('recv PROXY: ' + util.inspect(m, null, null)); },
        send: function (m) { console.error('send PROXY: ' + util.inspect(m, null, null)); },
        error: function (e) { console.error(e.stack); }
    }
}, function (rq) {
    if (rq.method == 'INVITE') {
        util.debug('INVITING: ' + rq.uri);

        var uri = sip.parseUri(rq.uri);
        console.error(util.inspect(uri, null, null));

        if (uri.params['pn-type'] != undefined && uri.params['pn-type'] == 'wp') {
            wns.sendIncomingCallNotification('http://' + uri.params['app-id'] + uri.params['pn-tok'], function (error, response, body) {
                if (error) {
                    console.log(error);
                } else {
                    console.log(response.statusCode, 'Other function');
                }
            });
        }
    }

    if (rq.method == 'REGISTER') {
        proxy.send(sip.makeResponse(rq, 100, 'TRYING'));
    }

    proxy.send(rq);
});

If I leave the 'TRYING' out my phone goes completely into rage mode as it gets no answers.

Any ideas?

Thank you very much

Ferdinand

FerdinandvHagen commented 9 years ago

OK. Seems that this is related to Issue #94. Just tried and entered the IP-address of sipgate.de into the phone instead of the Name and now it works exactly like I wish it would. Whole 'REGISTER' process only takes a second or two.

Is it possible that every occurrence of sipgate.de in the packet is causing a full SIP-address search?

kirm commented 9 years ago

No, sip.js only resolves uri it determined to be address of next hop server. And unfortunately I don't have any means to speed up name resolution.

FerdinandvHagen commented 9 years ago

Hmm. Ok. I will try to dig a little bit deeper. Thank you.