How can I use sip.js connect freeswitch with wss

344 Views Asked by At

I am trying to register with the server using sipjs.It can works with ws,but when i use wss,some errors occured.I have used a self-signed certificate wss.pem to instead the old one

freeswitch error

tport.c:2777 tport_wakeup_pri() tport_wakeup_pri(0x7fe5c800be90): events IN
tport.c:867 tport_alloc_secondary() tport_alloc_secondary(0x7fe5c800be90): new secondary tport 0x7fe5c8018990
tport.c:2103 tport_close() tport_close(0x7fe5c8018990): (null)/(null):(null)
tport_type_ws.c:641 tport_ws_next_timer() tport_ws_next_timer(0x7fe5c8018990): Error establishing SSL to (null)/(null):(null)
tport.c:2278 tport_set_secondary_timer() tport(0x7fe5c8018990): set timer at 0 ms because zap
tport.c:2103 tport_close() tport_close(0x7fe5c8018990): (null)/(null):(null)
tport_type_ws.c:535 tport_ws_deinit_secondary() 0x7fe5c8018990 destroy wss transport 0x7fe5c8018b80.

sip.js

const transportOptions = {
        server: "wss://10.16.127.26:7443"//fs
      }; 
      //ua
    // const userAgent = new UserAgent({transportOptions});
    // userAgent.start();
    const fake_uri='sip:'+extName+'@10.16.127.26'
    const uri = UserAgent.makeURI(fake_uri);
    const targeturi=UserAgent.makeURI(target);
    if (!uri) {
        throw new Error("Failed to create URi");
      }
        const userAgentOptions = {
        authorizationPassword: '1234',
        authorizationUsername: '1001',
        transportOptions,
        // hackWssInTransport: true,
        uri,
      };
    const userAgent = new UserAgent(userAgentOptions);
    connect.addEventListener('click',e=>{
            // console.log('ok');
        const registerer = new Registerer(userAgent);
        userAgent.start().then(() => {
          registerer.register()
          console.log('11');
        });
        // console.log( registerer.register());
        })
1

There are 1 best solutions below

3
On

You mention having a self signed certificate, is it possible your browser isn't fully establishing the TLS connection and disconnecting when it sees the untrusted cert? You can typically get around this by issuing a valid cert or visiting the freeswitch instance in a browser as a page and clicking through the certificate validation failure.

For you, that means going to https://10.16.127.26:7443 in a browser and clicking through the cert warning. When you've done that go back to your sipjs page and try again.

this is just a guess, you might have other issues. There might be more information in the browser's console or elsewhere in the freeswitch logs.