How do I provide a password to sip.js when using SimpleUser?

340 Views Asked by At

I am using sip.js from the browser to connect to SIP via WebSocket.

This is the guide I am following: https://sipjs.com/guides/simple-user/

But my SIP server requires a password. The guide does not give any information how to provide a SIP password.

I am successfully connected, but registration fails:

SIP/2.0 401 Unauthorized Via: SIP/2.0/WSS logger-factory.js:103 Tue Aug 22 2023 13:46:30 GMT+0200 (Central European Summer Time) | sip.user-agent-client | 401 apparently in authentication loop, cannot authenticate overrideMethod @ console.js:213 print @ logger-factory.js:103 genericLog @ logger-factory.js:73 genericLog @ logger.js:39 warn @ logger.js:27 authenticationGuard @ user-agent-client.js:198 receiveResponse @ user-agent-client.js:292 receiveResponse @ user-agent-client.js:373 receiveResponse @ non-invite-client-transaction.js:115 receiveResponseFromTransport @ user-agent-core.js:927 receiveIncomingResponseFromTransport @ user-agent-core.js:247 onTransportMessage @ user-agent.js:1042 transport.onMessage @ user-agent.js:908 onWebSocketMessage @ transport.js:503 eval @ transport.js:259 Show 1 more frame Show less logger-factory.js:103 Tue Aug 22 2023 13:46:30 GMT+0200 (Central European Summer Time) | sip.Registerer | Failed to register, status code 401

1

There are 1 best solutions below

0
On

I faced same issue, and reading and guessing options I found one way, hope this can help you. Tryin like this:

let server = "wss://sip.company.it";
let options = {
    aor: "sip:[email protected]",
    userAgentOptions: {
        authorizationUsername: "9999",
        authorizationPassword: "mysupersecretpassword"
    },
    media: {
        remote: {
            audio: document.getElementById("remoteAudio")
        }
    }
};

let sip = new SIP.Web.SimpleUser(server, options);

sip.connect();
sip.register();

I found the userAgentOptions param at this manual

the above example I made it to be use on browser, If you want to used on nodejs I guess the process is similar.