0

I am integrating sipjs in react native and here is the code;

import {Registerer, UserAgent} from 'sip.js';

export const registerUserAgent = async () => {
  try {

    let sipUsername = 'my username';
    let sipToken = 'my token';

    const userAgentOptions = {
      transportOptions: {
        server: 'wss://my.websocket.server:port',
        traceSip: true,
      },
      logLevel: 'debug',
    };

    userAgentOptions.uri = UserAgent.makeURI(
      `sip:${sipUsername}@my.websocket.server:port`,
    );

    let userAgent = new UserAgent(userAgentOptions);
    userAgent.delegate = {
      onDisconnect(err) {
        console.log(err, 'Disconnect error');
      },
    };
    await userAgent.start();
 

  } catch (err) {
    console.log(err);
  }
};

But the userAgent never starts, it throws an error;

Error: WebSocket closed wss://my.websocket.server:port (code: 1006)]

I am not sure what is going wrong here. Note that the server is working fine.

And this issue is only with android. On iOS everything works fine.

Irfan wani
  • 4,084
  • 2
  • 19
  • 34

1 Answers1

0
  1. Locate the problem
Clent Network Server
Running code in debugging mode Traffic sniffing Extended logging
  1. In general, try to detect the presence or absence of network packets on the client, on the hardware, and on the server alternately. Start with the server, e.g. run tcpdump there. And see if network requests to the specified port from the specified address are received.

It's probably a systemic problem. Try to see the development status or similar errors.

nucr0t
  • 61
  • 1
  • Can you please explain a bit how to do so, for client side debugging, i am not getting any special logs, it just shows, websocket disconnected. I tried with react native debugger network inspector but it is not helpful as it doesnot show the network requests from app – Irfan wani Jul 15 '23 at 10:11
  • 1
    Try using the remote [debugging functionality](https://codeburst.io/react-native-debugging-tools-3a24e4e40e4). To see real events and traffic. The [official documentation](https://reactnative.dev/docs/debugging.html#chrome-developer-tools) for Chrome should also help. – nucr0t Jul 15 '23 at 10:39
  • already using the remote debugger. It is not helpful. – Irfan wani Jul 16 '23 at 05:41
  • java.security.cert.certpathvalidator Exception: trust anchor for ceritfication path not found . This is the actual error @nucr0t – Irfan wani Jul 16 '23 at 06:59
  • 1
    The problem is probably one of the ones described [here](https://developer.android.com/training/articles/security-ssl#CommonProblems). Try using the certificate binding in the [example](https://developer.android.com/training/articles/security-config#CertificatePinning). To fill digest, use [gnutls](https://gnutls.org/manual/html_node/gnutls_002dcli-Invocation.html). `gnutls-cli – nucr0t Jul 16 '23 at 17:56
  • As you can see in the above code in question, i am using sipUsername and sipToken to validate the user. These two things are coming from an api call. When i changed the api to production one, it works fine. Websocket connects. And in dev api, though the api works fine, but socket doesn't connect. It is completely out of my mind. – Irfan wani Jul 17 '23 at 03:16