Leon
Leon

Reputation: 348

Where should be the location for coturn or ice setting for sipjs 0.11.0?

I am moving from sipjs 0.7x to sipjs 0.11 After reading the Git issue https://github.com/onsip/SIP.js/pull/426#issuecomment-312065734 and https://sipjs.com/api/0.8.0/sessionDescriptionHandler/

I have found that the ice options (coturn, turn, stun) is not in User Agent anymore, but the problem is that I am not quite understand where should I use the setDescription(sessionDescription, options, modifiers)

I have seen that the ice is set in options, using options.peerConnectionOptions.rtcConfiguration.iceServers

below is what I haved tried

session.on('trackAdded', function () {
            // We need to check the peer connection to determine which track was added
            var modifierArray = [
                SIP.WebRTC.Modifiers.stripTcpCandidates,
                SIP.WebRTC.Modifiers.stripG722,
                SIP.WebRTC.Modifiers.stripTelephoneEvent
                ];
            var options = {
            peerConnectionOptions:{
                rtcConfiguration:{
                    iceServers : {
                                [{urls: 'turn:35.227.67.199:3478',
                                username: 'leon',
                                credential: 'leon_pass'}]
                    }
                }
            }
        }
            session.setDescription('trackAdded', options,modifierArray);

            var pc = session.sessionDescriptionHandler.peerConnection;

            // Gets remote tracks
            var remoteStream = new MediaStream();
            pc.getReceivers().forEach(function (receiver) {
                remoteStream.addTrack(receiver.track);
            });
            remoteAudio.srcObject = remoteStream;
            remoteAudio.play();

            // Gets local tracks
            // var localStream = new MediaStream();
            // pc.getSenders().forEach(function(sender) {
            //     localStream.addTrack(sender.track);
            // });
            // localVideo.srcObject = localStream;
            // localVideo.play();
        });
    }

I have tried this and it seems that the traffic is not going to the coturn server. I have used Trickle Ice "https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/" to test and it is fine, but I have found there is not traffic going through the coturn server. You could also use this one and I do not mind.

There is even no demo on the official website to show how could we use the setDescription(sessionDescription, options, modifiers). In this case can I please ask some recommendations?

Upvotes: 0

Views: 1469

Answers (1)

justlo0king
justlo0king

Reputation: 371

Configure STUN/TURN servers in the parameters passed to new UserAgent. Here is sample, it seems to be working on v0.17.1:

const userAgentOptions = {
  ...
  sessionDescriptionHandlerFactoryOptions: {
    peerConnectionConfiguration: {
      iceServers: [{
        urls: "stun:stun.l.google.com:19302"
      }, {
        urls: "turn:TURN_SERVER_HOST:PORT",
        username: "USERNAME",
        credential: "PASSWORD"
      }]
    },
  },
  ...
};
const userAgent = new SIP.UserAgent(userAgentOptions);

When using SimpleUser - pass it inside SimpleUserOptions:

const simpleUser = new Web.SimpleUser(url, { userAgentOptions })

Upvotes: 1

Related Questions