J. Doe
J. Doe

Reputation: 21

JsSIP Implementation

I'm working on a telecom company. We want to develop a SIP phone wit JsSIP library. But we can't do it. We create a basic form for test like this:

var socket = new JsSIP.WebSocketInterface('*****');
var configuration = {
  sockets  : [ socket ],
  uri      : '*****',
  password : '*****'
};

var ua = new JsSIP.UA(configuration);

ua.start();

// Register callbacks to desired call events
var eventHandlers = {
  'progress': function(e) {
    console.log('call is in progress');
  },
  'failed': function(e) {
    console.log('call failed with cause: '+ e.data.cause);
  },
  'ended': function(e) {
    console.log('call ended with cause: '+ e.data.cause);
  },
  'confirmed': function(e) {
    console.log('call confirmed');
  }
};

var options = {
  'eventHandlers'    : eventHandlers,
  'mediaConstraints' : { 'audio': true, 'video': true }
};

var session = ua.call('680', options);

Above code is working. We can call anywhere but calling user's voice isn't come to us. How can i do that? What must we do? Does anyone have a example code for this project?

Upvotes: 2

Views: 8358

Answers (3)

Mert Yılmaz
Mert Yılmaz

Reputation: 41

session.connection.addEventListener('addstream',function(e) {  // Or addtrack
        remoteAudio.srcObject = e.stream;
        remoteAudio.play();

     });

Upvotes: 0

Alexander Kachkaev
Alexander Kachkaev

Reputation: 912

If you are looking for an example code, feel free to check out the implementation of react-sip (a package that helps embed JsSIP into React apps). In particular, you may find the source of <SipProvider/> component useful, even if not using React.

Perhaps, the reason why you don’t hear user voice is because you don't have an HTML5 <audio/> DOM element on your page, which is attached to your JsSIP instance.

Here is roughly what you should add:  

// in the beginning, e.g. before you create an instance of JsSIP.WebSocketInterface
var remoteAudio = window.document.createElement('audio');
window.document.body.appendChild(remoteAudio);

// inside rtcSession.on('accepted', function() {...})
remoteAudio.src = window.URL.createObjectURL(
  rtcSession.connection.getRemoteStreams()[0]
);
remoteAudio.play();
// rtcSession comes from an argument in
// ua.on('newRTCSession', ({ originator, session: rtcSession }) => {});

// when no longer need to make calls (e.g. on user logout)
delete remoteAudio;

Upvotes: 1

dnarsay
dnarsay

Reputation: 71

If the call is getting established, but there is no audio path, probably the SDP endpoints of the caller/callee are not reachable by each other.

The call will disconnect with reason "RTP timeout" in that case.

Here are some tips:

  1. Turn JSSIP console debug ON by running JsSIP.debug.enable('JsSIP:*');

  2. Reload the page.

  3. Make a call and and check the console logs on the browser for further details.

More on it: http://jssip.net/documentation/3.0.x/api/debug/

If you see the wrong set of SDP IP addresses going out or coming in, then the ICE candidates are incorrect or not in proper sequence.

STUN and other configuration settings will need to be adjusted in that case. http://jssip.net/documentation/0.3.x/api/ua_configuration_parameters/

Also, refer to jssip demo page, view the source code, and see what/how the additional configuration is applied. https://tryit.jssip.net/

Upvotes: 1

Related Questions