I am developing a JavaScript-based web SIP client communicating with Asterisk SIP server.
The SIP client is using JSSIP 3.4.2, I'm testing on Chrome version 80.
Both SIP client and SIP server are behind firewalls. I'm using STUN server stun.l.google.com:19302.
The call is established well, but there's a 40 sec delay between calling the "call" method and establishing a call (starting an RTP session).
Here's the code of SIP UA registration:
// SIP UA registration
var currentUserSipAccount = {
uri: '211',
pwd: 'secret'
};
var sipDomain = 'sip.my-domain.com';
var sipServerUrl = 'wss://' + sipDomain + ':8089/ws';
var socket = new JsSIP.WebSocketInterface(sipServerUrl);
var connectionParams = {};
connectionParams.sockets = [socket];
connectionParams.register = true;
connectionParams.uri = 'sip:' + currentUserSipAccount.uri + '@' + sipDomain;
connectionParams.password = currentUserSipAccount.pwd;
var bwPhone = new JsSIP.UA(connectionParams);
Here's the code of call initiation:
// SIP call
var callNumber = 'sip:233@' + sipDomain;
var callOptions = {
mediaConstraints: {
audio: true, // only audio calls
video: false
},
pcConfig: {
iceServers: [
{'urls': ['stun:stun.l.google.com:19302']}
]
}
};
bwPhone.call(callNumber, callOptions);
I have setup logging of each SIP event and found that the delay is related to the onicegatheringstatechange and onicecandidate events.
Here's the Wireshark log:
Each 10 sec, a STUN request is being sent, followed by an instant response. This happens 4 times.
Here is the browser console log I am getting:
The computer on which I'm doing a call has multiple network interfaces. I see icecandidate events containing two IP addresses, one of them (169.254.128.100) is related to Ethernet and not used, another one (192.168.1.33) is related to WiFi and is used for connecting to Internet.
I also see in the browser console log, that the STUN response is being received within several milliseconds after initiating the call. But after that, JSSIP waits for 40 seconds!
How to avoid this 40 sec delay?