SIP.js icon indicating copy to clipboard operation
SIP.js copied to clipboard

Customize "viaHost" after UserAgent.start()

Open anzai opened this issue 4 years ago • 2 comments

Would you prepare the feature to customize viaHost after trasnport connection on UserAgent.start()?

Situation

I am trying to make TCP transport socket with net.Socket as follows:

// copy from `lib/platform/web/transport/transport.js`
import { Socket } from 'net';

export class Transport
{
    _connect()
    {
        // ...
        socket = new Socket();
        socket.connect(port, ip);

        socket.on('connect', (ev) => { this.onTcpSocketOpen(ev, socket); });
        // ...
    }
}

I have one trouble on UserAgent. UserAgent has the viaHost option which is used at constructor(). But I'd like to set ViaHost after UserAgent.start() = UserAgent.transport.connect(). In my case with TCP transport, ViaHost needs to be net.Socket.localAddress + localPort, and these parameters are specified after connect().

var userAgent = new UserAgent({
    // some options for TCP transport
    transportConstructor: TcpTransport,
    contactParams: { transport: "tcp" },
    hackViaTcp: true,

    // not spefified yet
    // viaHost: "xxx.xxx.xxx.xxx",
});
var userAgent = new UserAgent(userAgentOptions);

userAgent
    // tansport.connect() -> net.Socket.connect()
    // The values for "viaHost" are specified now
    .start()

    .then(() => {
        // RESGISTER, INVITE, ...
    });

Currently Registerer.register() sends the request like:

REGISTER sip:__my_sip_server__ SIP/2.0
Via: SIP/2.0/TCP tlm1onma0uh0.invalid;branch=z9hG4bK9805820
                 ^^^^^^^^^^^^^^^^^^^^
To: <sip:__user__@__my_sip_server__>
From: <sip:__user__@__my_sip_server__>;tag=hjuhun3haq
CSeq: 2 REGISTER
Call-ID: 63bo4ves6mu6p4m3b47u
Max-Forwards: 70
Contact: <sip:[email protected];transport=tcp>;expires=600
                       ^^^^^^^^^^^^^^^^^^^^
Allow: ACK,CANCEL,INVITE,MESSAGE,BYE,OPTIONS,INFO,NOTIFY,REFER
Supported: outbound, path, gruu
User-Agent: SIP.js/0.20.0
Content-Length: 0

anzai avatar Aug 04 '22 05:08 anzai

Ok. Enhancement request.

Notes to self...

The existence of hackViaTcp option is indicative of the underlying issue here. The ClientTransaction sets the Via header like so _request.setViaHeader(this.id, transport.protocol);. While it's appears to be good thing that it is utilizing the transport to set the header, it is only using the protocol but I gather it should be also looking for a local ip:port as well.

john-e-riordan avatar Oct 21 '22 18:10 john-e-riordan

Also, a pull request to add a TCP transport would get considered.

john-e-riordan avatar Oct 21 '22 18:10 john-e-riordan