Asterisk and JsSIP no audio

Hi,

I’m connecting a webrtc client to Asterisk 16, but I can’t hear the audio playback (dialed 200, and I should hear the demo-congrats audio file). Connecting with a SIP softphone works fine. The connections are within the same LAN segment.

This is my pjsip.conf:

[transport-wss]
type=transport
protocol=wss
bind=0.0.0.0
; All other transport parameters are ignored for wss transports.

[patient]
type=aor
max_contacts=5
remove_existing=yes

[patient]
type=auth
auth_type=userpass
username=patient
password=patient 
                      

[patient]
type=endpoint
aors=patient
auth=patient
dtls_auto_generate_cert=yes
webrtc=yes
; Setting webrtc=yes is a shortcut for setting the following options:
; use_avpf=yes
; media_encryption=dtls
; dtls_verify=fingerprint
; dtls_setup=actpass
; ice_support=yes
; media_use_received_transport=yes
; rtcp_mux=yes
;;;;direct_media=no
;;;;max_audio_streams=10
;;;;max_video_streams=10
context=default
disallow=all
allow=opus,alaw,ulaw,gsm,vp8,h264
rtp_symmetric=yes
force_rport=yes

[doctor]
type=aor
max_contacts=5
remove_existing=yes

[doctor]
type=auth
auth_type=userpass
username=doctor
password=doctor 
                      

[doctor]
type=endpoint
aors=doctor
auth=doctor
dtls_auto_generate_cert=yes
webrtc=yes
; Setting webrtc=yes is a shortcut for setting the following options:
; use_avpf=yes
; media_encryption=dtls
; dtls_verify=fingerprint
; dtls_setup=actpass
; ice_support=yes
; media_use_received_transport=yes
; rtcp_mux=yes
;;;;direct_media=no
;;;;max_audio_streams=10
;;;;max_video_streams=10
context=default
disallow=all
allow=opus,alaw,ulaw,gsm,vp8,h264
rtp_symmetric=yes
force_rport=yes

[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060

[201]
type=endpoint
context=default
disallow=all
allow=alaw,ulaw,gsm
auth=201
aors=201

[201]
type=auth
auth_type=userpass
password=201
username=201

[201]
type=aor
max_contacts=1

The dialplan:

[default]
exten => 200,1,Answer()
same => n,Playback(demo-congrats)
same => n,Hangup()

exten => patient,1,Answer()
same => n,Dial(PJSIP/${EXTEN})
same => n,Hangup()

exten => doctor,1,Answer()
same => n,Dial(PJSIP/${EXTEN})
same => n,Hangup()

The Asterisk log:

https://pastebin.com/PVvA0Eja

Finally, this is the JsSIP debug log:

https://pastebin.com/FQwcmvZf

What can I try?

Regards,

Vieri

On the Asterisk side it appears media is being received and sent. You’d need to check the browser side to see if something is up.

I guess you’re right. I’m unable to even make a basic jssip call work as the one shown on their web site (https://jssip.net/documentation/3.4.x/getting_started/):

<html>
<head>
    <script src="./assets/js/jssip.js" ></script>
    <script>JsSIP.debug.enable('JsSIP:*');</script>
</head>
<body>
<script>

// Create our JsSIP instance and run it:

var socket = new JsSIP.WebSocketInterface('wss://sip.domain.org:8090/ws');
var configuration = {
  sockets  : [ socket ],
  uri      : 'sip:doctor@sip.domain.org',
  password : 'doctor',
  display_name : 'doctor',
  contact_uri : 'sip:doctor@sip.domain.org',
  realm : 'asterisk'
};

var ua = new JsSIP.UA(configuration);

ua.start();
ua.register();

// 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('sip:200@sip.domain.org', options);


</script>
</body>
</html>

Looks simple, and I’m trying to KIS, but in this simple “hello world” sample, I still can’t hear anything, and I’m in the same LAN segment.
The Asterisk console and pjsip show enpoints does show me however that something’s up:

Endpoint: doctor In use 1 of inf
InAuth: doctor/doctor
Aor: doctor 5
Contact: doctor/sip:doctor@10.215.144.48:52961;tran 1dd81c2968 NonQual nan
Channel: PJSIP/doctor-0000000b/Playback Up 00:00:21
Exten: 200 CLCID: “” <>

I’ll keep digging into this.

Thanks

Strange though…
Even if I try the JsSIP demo here: http://tryit.jssip.net/ and configure it to connect to my Asterisk server, I get the following on the console:

  == WebSocket connection from 'my_client_ip_addr:52531' for protocol 'sip' accepted using version '13'
    -- Added contact 'sip:doctor@my_client_ip_addr:52531;transport=ws' to AOR 'doctor' with expiration of 600 seconds
  == Setting global variable 'SIPDOMAIN' to 'sip.domain.org'
    -- Executing [200@default:1] Answer("PJSIP/doctor-0000000c", "") in new stack
       > 0x7f26f0046c40 -- Strict RTP learning after remote address set to: my_client_ip_addr:51268
       > 0x7f26f00064f0 -- Strict RTP learning after remote address set to: my_client_ip_addr:51268
       > 0x7f26f0046c40 -- Strict RTP learning after remote address set to: my_client_ip_addr:51268
       > 0x7f26f00064f0 -- Strict RTP learning after ICE completion
    -- Executing [200@default:2] Playback("PJSIP/doctor-0000000c", "demo-congrats") in new stack
    -- <PJSIP/doctor-0000000c> Playing 'demo-congrats.gsm' (language 'en')
       > 0x7f26f00064f0 -- Strict RTP switching to RTP target address my_client_ip_addr:51268 as source
       > 0x7f26f0046c40 -- Strict RTP switching to RTP target address my_client_ip_addr:51268 as source
       > 0x7f26f0046c40 -- Strict RTP learning complete - Locking on source address my_client_ip_addr:51268
       > 0x7f26f00064f0 -- Strict RTP learning complete - Locking on source address my_client_ip_addr:51268
    -- Executing [200@default:3] Hangup("PJSIP/doctor-0000000c", "") in new stack
  == Spawn extension (default, 200, 3) exited non-zero on 'PJSIP/doctor-0000000c'

I’m using both Chrome and Firefox (latest versions), no apparent errors, but I can’t hear anything at all (no “demo-congrats”).

I opened tcp 8090 in my case and udp ports 20000 to 40000 according to my rtp.conf.

Do I need to allow anything else?

You are playing back a GSM encoded file, it will need to transcode. Make sure opus is installed, or try calling another instance of the JsSIP demo with say Edge this time. (You can share the mic and speakers, but it does create a feedback loop if its working). Another thing to try is to use ULAW codec in your endpoints - just to test, its not a great codec, but its able to transcode, and Chrome/Edge supports it.

Thanks for the tip, but I’m afraid it didn’t change anything.

*CLI>   == WebSocket connection from 'my_client_ip_addr:52663' for protocol 'sip' accepted using version '13'
    -- Added contact 'sip:5iqmtdp3@my_client_ip_addr:52663;transport=ws' to AOR 'doctor' with expiration of 600 seconds
  == Setting global variable 'SIPDOMAIN' to 'sip.domain.org'
    -- Executing [200@default:1] Answer("PJSIP/doctor-00000001", "") in new stack
       > 0x7f33880533a0 -- Strict RTP learning after remote address set to: my_client_ip_addr:50876
       > 0x7f33880629b0 -- Strict RTP learning after remote address set to: my_client_ip_addr:50876
       > 0x7f33880533a0 -- Strict RTP learning after remote address set to: my_client_ip_addr:50876
       > 0x7f33880629b0 -- Strict RTP learning after ICE completion
    -- Executing [200@default:2] Playback("PJSIP/doctor-00000001", "demo-congrats") in new stack
    -- <PJSIP/doctor-00000001> Playing 'demo-congrats.ulaw' (language 'en')
       > 0x7f33880629b0 -- Strict RTP switching to RTP target address my_client_ip_addr:50876 as source
       > 0x7f33880533a0 -- Strict RTP switching to RTP target address my_client_ip_addr:50876 as source
       > 0x7f33880533a0 -- Strict RTP learning complete - Locking on source address my_client_ip_addr:50876
       > 0x7f33880629b0 -- Strict RTP learning complete - Locking on source address my_client_ip_addr:50876
    -- Executing [200@default:3] Hangup("PJSIP/doctor-00000001", "") in new stack
  == Spawn extension (default, 200, 3) exited non-zero on 'PJSIP/doctor-00000001'

The ulaw codec is being used, but I still can’t hear anything no matter which browser I use.

I’m using the current demo site here: https://tryit.jssip.net/

Change:

to:

on the endpoint you are using to test with, reload pjsip and re-register the extension, and try again. If you hear the message then there is a problem with you opus codec. Its not complaining about the translation path… but its also not playing the audio.

I already changed it to:

allow=ulaw,alaw,opus,gsm,vp8,h264

but now I changed it as you requested:

allow=alaw,ulaw,opus,gsm,vp8,h264

(although I thought you said you wanted ulaw to come first).

Now, with alaw in pole position, the Asterisk log shows the same data except for:

<PJSIP/doctor-00000000> Playing 'demo-congrats.alaw' (language 'en')

Still, I can’t hear anything in the browsers (of course, audio output works, so it’s not a hardware or local driver issue, if anyone wondered).

Try the same thing here:
https://www.innovateasterisk.com/phone/

It’s almost as if the playback stream is not being played out to an AUDIO object, our the audio object is muted. The demo page above allows you to select an output device, like speakers etc.

Wow, ok, so that site works… Now I just need to find out why jssip doesn’t.
Thanks, you’ve helped a lot.
More homework for me.

The page I sent is the result of a project based on sipjs.js:


Welcome to clone, use, etc etc… feel free

Thanks. Nice project.
I’m trying to learn the basics here…
Since you built around sipjs, I’m trying to make the basic demo (demo1) work on my server.
I can connect via wss, but (and I feel silly asking this) I then try to call my “200” extension in the “default” context.
The makeURI call to sip:200@mydomain.org doesn’t seem to work, and it syntactically fails on “200”. So by any chance do you know what the format would be here?

I’m not all that familiar with their solution, but the way they have probably build their system would be that you need to include all the sip: and the @domain stuff to make up a real SIP URL. (I find that annoying and not typical of user behaviour)

I have outlined these concepts in these two videos:


and (with PJSIP)

So the format of the dial will be as follows… If you register on a server say:
asterisk.myserver.com, with username x and password y.
Once you are registered, anything you dial should then be:
sip:200@asterisk.myserver.com (i’m using 200 as the example you provided)
This in turn fires the context that you have mapped to the endpoint. In your case you have:
context=default
so in your dial plan you should have a context
[default]

and this is what links one user to the other. (Its explained better in the videos).

Yes, that’s exactly what I thought: sip:200@domain.org.

However, when I try that I get:

[May 28 17:09:51] NOTICE[21245]: res_pjsip/pjsip_distributor.c:676 log_failed_request: Request 'INVITE' from '"SIP.js Demo" <sip:anonymous.1n6io4@anonymous.invalid>' failed for 'my_client_ip_addr:52927' (callid: rkc7veh50sv7236cu98k) - No matching endpoint found

By the way, I tried your demo and was hoping to make a video call. Both of my SIP endpoints seem to support the codecs, and I have this for both in pjsip.conf:

allow=alaw,ulaw,opus,gsm,vp8,h264

However, I’m only getting an audio call.

Do you have audio tag in html? you should attach a web stream to audio tag once it appear (on event onstream or ontrack) - do you make it?
Thanks

Yes, correct, the sipjs engine only fires the trackAdded event, from there you must take the audio track, and set it to the < audio > object.

Something like this should do:

session.on('trackAdded', function () {
   var pc = session.sessionDescriptionHandler.peerConnection;
   var remoteStream = new MediaStream();
   pc.getReceivers().forEach(function (receiver) {
        if(receiver.track && receiver.track.kind == "audio"){
            remoteStream.addTrack(receiver.track);
        } 
    });
    var remoteAudio = $("#myAudioObject").get(0);
    remoteAudio.srcObject = remoteStream;
    remoteAudio.onloadedmetadata = function(e) {
        remoteAudio.play();
    } 
});

in chrome it’s on(‘addstream’) event, in safari on(‘track’)

I would use a known library like sipjs or jssip, and use their API. In this case it will not be browser dependent.

If you are truly set on this task, you can see more about a WebRTC PeerConnection here: https://webrtc.github.io/samples/src/content/peerconnection/pc1/

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.