WebRTC call hangs up just after answering

I’m using Asterisk 13 and everything works fine except WebRTC. I’m able to place calls and answer them.
But when I try to answer a call placed from my WebRTC peer, it gets disconnected immediately. 100 is my WebRTC peer and 200 is a normal soft phone.

---
    -- SIP/200-00000009 answered SIP/100-00000008
Audio is at 16408
Adding codec ulaw to SDP
Adding codec alaw to SDP
Adding non-codec 0x1 (telephone-event) to SDP

<--- Reliably Transmitting (NAT) to 157.46.170.163:56499 --->
SIP/2.0 200 OK
Via: SIP/2.0/WSS d67s9mhmu8hc.invalid;branch=z9hG4bK2414880;received=157.46.170.163;rport=56499
From: <sip:100@therydcompany.in>;tag=dp7uiphikt
To: <sip:100@therydcompany.in>;tag=as569dd66b
Call-ID: fea552shleqheuenqr18
CSeq: 479 INVITE
Server: Asterisk PBX 13.35.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Session-Expires: 90;refresher=uas
Contact: <sip:100@15.207.46.9:0;transport=ws>
Content-Type: application/sdp
Require: timer
Content-Length: 429

v=0
o=root 1788438354 1788438354 IN IP4 15.207.46.9
s=Asterisk PBX 13.35.0
c=IN IP4 15.207.46.9
t=0 0
m=audio 16408 RTP/SAVPF 0 8 126
a=rtpmap:0 PCMU/8000
a=rtpmap:8 PCMA/8000
a=rtpmap:126 telephone-event/8000
a=fmtp:126 0-16
a=maxptime:150
a=connection:new
a=setup:active
a=fingerprint:SHA-256 27:C3:2A:35:C7:2E:D4:40:64:11:CF:53:D8:C8:FD:6F:DA:88:34:E0:E0:9D:65:D0:0F:13:4A:EA:00:D3:33:E9
a=rtcp-mux
a=sendrecv

<------------>
    -- Channel SIP/200-00000009 joined 'simple_bridge' basic-bridge <9eae2370-17b2-4489-9527-bd97e7c882d8>
    -- Channel SIP/100-00000008 joined 'simple_bridge' basic-bridge <9eae2370-17b2-4489-9527-bd97e7c882d8>

<--- SIP read from UDP:157.46.170.163:41117 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK21f76c8e;rport=5060
Contact: <sip:192.168.43.67:41117>
To: <sip:300@157.46.170.163:41117;transport=UDP;rinstance=8ec091c26cade62d>;tag=ff69723d
From: "asterisk" <sip:asterisk@15.207.46.9>;tag=as10f3e274
Call-ID: 61adb87446136306338aefd6389314f6@15.207.46.9:5060
CSeq: 102 OPTIONS
Accept: application/sdp, application/sdp
Accept-Language: en
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
Supported: replaces, norefersub, extended-refer, timer, outbound, path, X-cisco-serviceuri
User-Agent: Z 5.4.5 rv2.10.9.0
Allow-Events: presence, kpml, talk
Content-Length: 0

<------------->
--- (14 headers 0 lines) ---
Really destroying SIP dialog '61adb87446136306338aefd6389314f6@15.207.46.9:5060' Method: OPTIONS

<--- SIP read from UDP:157.46.170.163:33230 --->
REGISTER sip:therydcompany.in;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 157.46.170.163:33230;branch=z9hG4bK-524287-1---ccdd0abde5e82bae;rport
Max-Forwards: 70
Contact: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>
To: <sip:200@therydcompany.in;transport=UDP>
From: <sip:200@therydcompany.in;transport=UDP>;tag=4f042453
Call-ID: SPfJXzsIMIypMLOpWxtWeA..
CSeq: 255 REGISTER
Expires: 60
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
User-Agent: Zoiper rv2.10.8.4
Authorization: Digest username="200",realm="asterisk",nonce="7b5fb69a",uri="sip:therydcompany.in;transport=UDP",response="559c95be5f947b9bc0bc3b7048f56b73",algorithm=MD5
Allow-Events: presence, kpml, talk
Content-Length: 0

<------------->
--- (14 headers 0 lines) ---
Sending to 157.46.170.163:33230 (NAT)
Sending to 157.46.170.163:33230 (NAT)

<--- Transmitting (NAT) to 157.46.170.163:33230 --->
SIP/2.0 401 Unauthorized
Via: SIP/2.0/UDP 157.46.170.163:33230;branch=z9hG4bK-524287-1---ccdd0abde5e82bae;received=157.46.170.163;rport=33230
From: <sip:200@therydcompany.in;transport=UDP>;tag=4f042453
To: <sip:200@therydcompany.in;transport=UDP>;tag=as313c0f5e
Call-ID: SPfJXzsIMIypMLOpWxtWeA..
CSeq: 255 REGISTER
Server: Asterisk PBX 13.35.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
WWW-Authenticate: Digest algorithm=MD5, realm="asterisk", nonce="4c0aa4c1"
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'SPfJXzsIMIypMLOpWxtWeA..' in 32000 ms (Method: REGISTER)

<--- SIP read from WS:157.46.170.163:56499 --->
ACK sip:100@15.207.46.9:0;transport=ws SIP/2.0
Via: SIP/2.0/WSS d67s9mhmu8hc.invalid;branch=z9hG4bK2903460
Max-Forwards: 69
To: <sip:100@therydcompany.in>;tag=as569dd66b
From: <sip:100@therydcompany.in>;tag=dp7uiphikt
Call-ID: fea552shleqheuenqr18
CSeq: 479 ACK
Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY
Supported: outbound
User-Agent: JsSIP 3.4.2
Content-Length: 0

<------------->
--- (11 headers 0 lines) ---

<--- SIP read from WS:157.46.170.163:56499 --->
BYE sip:100@15.207.46.9:0;transport=ws SIP/2.0
Via: SIP/2.0/WSS d67s9mhmu8hc.invalid;branch=z9hG4bK2638347
Max-Forwards: 69
To: <sip:100@therydcompany.in>;tag=as569dd66b
From: <sip:100@therydcompany.in>;tag=dp7uiphikt
Call-ID: fea552shleqheuenqr18
CSeq: 480 BYE
Reason: SIP ;cause=488; text="Not Acceptable Here"
Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY
Supported: outbound
User-Agent: JsSIP 3.4.2
Content-Length: 0

<------------->
--- (12 headers 0 lines) ---
Scheduling destruction of SIP dialog 'fea552shleqheuenqr18' in 6400 ms (Method: BYE)

<--- Transmitting (NAT) to 157.46.170.163:56499 --->
SIP/2.0 200 OK
Via: SIP/2.0/WSS d67s9mhmu8hc.invalid;branch=z9hG4bK2638347;received=157.46.170.163;rport=56499
From: <sip:100@therydcompany.in>;tag=dp7uiphikt
To: <sip:100@therydcompany.in>;tag=as569dd66b
Call-ID: fea552shleqheuenqr18
CSeq: 480 BYE
Server: Asterisk PBX 13.35.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


<------------>
    -- Channel SIP/100-00000008 left 'simple_bridge' basic-bridge <9eae2370-17b2-4489-9527-bd97e7c882d8>
  == Spawn extension (wrtc, 100, 3) exited non-zero on 'SIP/100-00000008'
    -- Channel SIP/200-00000009 left 'simple_bridge' basic-bridge <9eae2370-17b2-4489-9527-bd97e7c882d8>
Scheduling destruction of SIP dialog '2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060' in 6400 ms (Method: INVITE)
Reliably Transmitting (NAT) to 157.46.170.163:33230:
BYE sip:200@157.46.170.163:33230 SIP/2.0
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport
Max-Forwards: 70
From: <sip:100@15.207.46.9>;tag=as6284be95
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Asterisk PBX 13.35.0
X-Asterisk-HangupCause: Normal Clearing
X-Asterisk-HangupCauseCode: 16
Content-Length: 0


---
Retransmitting #1 (NAT) to 157.46.170.163:33230:
BYE sip:200@157.46.170.163:33230 SIP/2.0
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport
Max-Forwards: 70
From: <sip:100@15.207.46.9>;tag=as6284be95
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Asterisk PBX 13.35.0
X-Asterisk-HangupCause: Normal Clearing
X-Asterisk-HangupCauseCode: 16
Content-Length: 0


---
Retransmitting #2 (NAT) to 157.46.170.163:33230:
BYE sip:200@157.46.170.163:33230 SIP/2.0
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport
Max-Forwards: 70
From: <sip:100@15.207.46.9>;tag=as6284be95
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Asterisk PBX 13.35.0
X-Asterisk-HangupCause: Normal Clearing
X-Asterisk-HangupCauseCode: 16
Content-Length: 0


---

<--- SIP read from UDP:157.46.170.163:33230 --->
REGISTER sip:therydcompany.in;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 157.46.170.163:33230;branch=z9hG4bK-524287-1---60aade204be918e6;rport
Max-Forwards: 70
Contact: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>
To: <sip:200@therydcompany.in;transport=UDP>
From: <sip:200@therydcompany.in;transport=UDP>;tag=4f042453
Call-ID: SPfJXzsIMIypMLOpWxtWeA..
CSeq: 256 REGISTER
Expires: 60
Allow: INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE
User-Agent: Zoiper rv2.10.8.4
Authorization: Digest username="200",realm="asterisk",nonce="4c0aa4c1",uri="sip:therydcompany.in;transport=UDP",response="47ea8c53b75e847c285cef28ab4312d9",algorithm=MD5
Allow-Events: presence, kpml, talk
Content-Length: 0

<------------->
--- (14 headers 0 lines) ---
Sending to 157.46.170.163:33230 (NAT)
Reliably Transmitting (NAT) to 157.46.170.163:33230:
OPTIONS sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP SIP/2.0
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK26a51801;rport
Max-Forwards: 70
From: "asterisk" <sip:asterisk@15.207.46.9>;tag=as54886910
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>
Contact: <sip:asterisk@15.207.46.9:5060>
Call-ID: 4a0869f47656453678f4f0a722100856@15.207.46.9:5060
CSeq: 102 OPTIONS
User-Agent: Asterisk PBX 13.35.0
Date: Thu, 30 Jul 2020 12:30:15 GMT
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Content-Length: 0


---

<--- Transmitting (NAT) to 157.46.170.163:33230 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 157.46.170.163:33230;branch=z9hG4bK-524287-1---60aade204be918e6;received=157.46.170.163;rport=33230
From: <sip:200@therydcompany.in;transport=UDP>;tag=4f042453
To: <sip:200@therydcompany.in;transport=UDP>;tag=as313c0f5e
Call-ID: SPfJXzsIMIypMLOpWxtWeA..
CSeq: 256 REGISTER
Server: Asterisk PBX 13.35.0
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Expires: 60
Contact: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;expires=60
Date: Thu, 30 Jul 2020 12:30:15 GMT
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog 'SPfJXzsIMIypMLOpWxtWeA..' in 32000 ms (Method: REGISTER)

<--- SIP read from UDP:157.46.170.163:33230 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport=5060
Contact: <sip:200@157.46.170.163:33230>
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
From: <sip:100@15.207.46.9>;tag=as6284be95
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Zoiper rv2.10.8.4
Content-Length: 0

<------------->
--- (9 headers 0 lines) ---
Really destroying SIP dialog '2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060' Method: INVITE

<--- SIP read from UDP:157.46.170.163:33230 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport=5060
Contact: <sip:200@157.46.170.163:33230>
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
From: <sip:100@15.207.46.9>;tag=as6284be95
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Zoiper rv2.10.8.4
Content-Length: 0

<------------->
--- (9 headers 0 lines) ---

<--- SIP read from UDP:157.46.170.163:33230 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 15.207.46.9:5060;branch=z9hG4bK498d70c2;rport=5060
Contact: <sip:200@157.46.170.163:33230>
To: <sip:200@157.46.170.163:33230;rinstance=a60e2bc804fea608;transport=UDP>;tag=3229844a
From: <sip:100@15.207.46.9>;tag=as6284be95
Call-ID: 2b29c17a76a956955079bfaf369905e1@15.207.46.9:5060
CSeq: 103 BYE
User-Agent: Zoiper rv2.10.8.4
Content-Length: 0

Also, I keep getting this error periodically.

ERROR[2795]: chan_sip.c:4294 __sip_reliable_xmit: Serious Network Trouble; __sip_xmit returns error for pkt data

Please guide.

The peer/user has not been configured to support WebRTC. You’d need to provide the actual configuration.

This is my SIP config. Please check.

[general]
externip=15.207.46.9
localnet=192.168.1.0/255.255.255.0
context=public                  ; Default context for incoming calls. Defaults to 'default'
allowoverlap=no                 ; Disable overlap dialing support. (Default is yes)
udpbindaddr=0.0.0.0             ; IP address to bind UDP listen socket to (0.0.0.0 binds to all)
tcpenable=no                    ; Enable server for incoming TCP connections (default is no)
tcpbindaddr=0.0.0.0             ; IP address for TCP server to bind to (0.0.0.0 binds to all interfaces)
transport=udp                   ; Set the default transports.  The order determines the primary default transport.
srvlookup=yes                   ; Enable DNS SRV lookups on outbound calls
qualify=yes
directmedia=no
nat=force_rport,comedia
insecure=port,invite
canreinvite=no
allowguest=no
alwaysauthreject=yes

websocket_enabled=yes

[authentication]
[basic-options](!)                ; a template
        dtmfmode=rfc2833
        context=from-office
        type=friend
[natted-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=no
        host=dynamic
[public-phone](!,basic-options)   ; another template inheriting basic-options
        directmedia=yes
[my-codecs](!)                    ; a template for my preferred codecs
        disallow=all
        allow=ilbc
        allow=g729
        allow=gsm
        allow=g723
        allow=ulaw
[ulaw-phone](!)                   ; and another one for ulaw-only
        disallow=all
        allow=ulaw

[100]
        type=friend
        context=wrtc
        allow=ulaw,alaw
        secret=hidden
        host=dynamic
        directmedia=no
        canreinvite=no
        encryption=yes
        transport=ws,wss
        force_avp=yes
        dtlsenable=yes
        dtlsverify=fingerprint
        dtlssetup=actpass
        avpf=yes
        icesupport=yes
        rtcp_mux=yes
        dtlscertfile=/etc/letsencrypt/live/therydcompany.in/fullchain.pem
        dtlsprivatekey=/etc/letsencrypt/live/therydcompany.in/privkey.pem
        dtlscafile=/etc/letsencrypt/live/therydcompany.in/chain.pem

[200]
        type=friend
        context=phones
        allow=ulaw,alaw,gsm
        secret=hidden
        host=dynamic
        directmedia=no
        canreinvite=no

[300]
        type=friend
        context=phones
        allow=ulaw,alaw,gsm
        secret=hidden
        host=dynamic
        canreinvite=no
                                   

ICE support is not actually enabling. You’d need to double check that it is enabled in rtp.conf, and that Asterisk has been compiled with pjproject support (bundled is easiest - https://blogs.asterisk.org/2016/03/16/asterisk-13-8-0-now-easier-pjsip-install-method/)

But I’m not using PJSIP.
Still on chan_sip.

PJSIP is part of the pjproject library, that library provides the ICE/STUN/TURN support that is used in Asterisk. It is therefore needed even if using chan_sip. You don’t have to use the PJSIP part of it.

I have enabled it in rtp.conf, still the problem exists.

I don’t have much idea about ICE. Is it necessary for WebRTC? Disabling ICE support didn’t cause any effect.

Is there any other way than reinstalling Asterisk?

ICE support is mandatory for WebRTC. It is how the browser knows what IP address and port media should be sent to, and vice versa. Asterisk has to be built with support for it.

Thank you. The call stays and doesn’t get disconnected upon answering.

But there is no audio. I believe it must be some NAT problem.
RTP debugging gives this:

Got  RTP packet from    157.46.170.163:59724 (type 00, seq 061896, ts 4046053883, len 000160)
Sent RTP packet to      192.168.43.67:59880 (type 00, seq 019188, ts 4046053880, len 000160)
Got  RTP packet from    157.46.170.163:59724 (type 00, seq 061897, ts 4046054043, len 000160)
Sent RTP packet to      192.168.43.67:59880 (type 00, seq 019189, ts 4046054040, len 000160)

You’d need to describe the specific environment, where things are.

I’m using the jsSIP basic example code on my host(EC2 instance) on AWS.
I’m accessing it through my browser to place the call.

Asterisk is on another but similar host on AWS itself, although different region.

If on AWS then you have to ensure there is a stunaddr specified in rtp.conf so that Asterisk can discover its external IP address, or use the options in rtp.conf to also place the external IP address as an ICE candidate.

I’ll also take this time to state that WebRTC is rarely plug and play. If you are deploying it in any way you’ll need to learn about the technology that underpins it, because it can and will fail to work for things.

stunaddr was mentioned. It was a simple problem. I didn’t open all RTP ports on my firewall.

Thank you so much for the help! Really appreciate it! <3