flutter-webrtc / dart-sip-ua

A dart-lang version of the SIP UA stack.
MIT License
338 stars 262 forks source link

with IceRestart: true, INVITE sdp body calls does not have candidates #489

Open reduxdj opened 1 day ago

reduxdj commented 1 day ago

Describe the bug Candidates are missing

Message SIP SDP Details INVITE sips:XXX;transport=wss SIP/2.0 Via: SIP/2.0/WSS vnomntum8t2f.invalid;branch=z9hG4bK14491595000000000 Max-Forwards: 69 To: ;tag=3yy6K835Nr54a From: ;tag=3095069310 Call-ID: yronddbpsbohhemgdnkj CSeq: 8136 INVITE Contact: sip:i56349k5@vnomntum8t2f.invalid;transport=wss;ob Content-Type: application/sdp Allow: INVITE,ACK,CANCEL,BYE,UPDATE,MESSAGE,OPTIONS,REFER,INFO,NOTIFY Supported: ice,replaces,outbound User-Agent: CloudCall 1.114.212(383) EdifyWebRTC MacOS Content-Length: 1327

v=0 o=- 3972420285708532286 5 IN IP4 127.0.0.1 s=- t=0 0 a=group:BUNDLE 0 a=extmap-allow-mixed a=msid-semantic: WMS 542E0354-6445-4029-A198-510963880AB0 m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 102 0 8 13 110 126 c=IN IP4 24.22.55.111 a=rtcp:9 IN IP4 0.0.0.0 a=ice-ufrag:YuGj a=ice-pwd:EMA+4vhP5c9gLHMMDy4gKMeC a=ice-options:trickle renomination a=fingerprint:sha-256 3E:FB:66:D1:CC:96:A8:4A:50:35:84:F6:4E:A1:04:48:BB:EF:0F:B5:D5:96:05:EB:42:E3:B4:AF:94:C7:CF:E9 a=setup:actpass a=mid:0 a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time a=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01 a=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid a=sendrecv a=msid:542E0354-6445-4029-A198-510963880AB0 0221DA9E-8767-4DAA-ABD2-85654918B5BE a=rtcp-mux a=rtpmap:111 opus/48000/2 a=rtcp-fb:111 transport-cc a=fmtp:111 minptime=10;useinbandfec=1 a=rtpmap:63 red/48000/2 a=fmtp:63 111/111 a=rtpmap:9 G722/8000 a=rtpmap:102 ILBC/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:8 PCMA/8000 a=rtpmap:13 CN/8000 a=rtpmap:110 telephone-event/48000 a=rtpmap:126 telephone-event/8000 a=ssrc:3757599216 cname:teM+Ps/dMRaUG7SX a=ssrc:3757599216 msid:542E0354-6445-4029-A198-510963880AB0 0221DA9E-8767-4DAA-ABD2-85654918B5BE

reduxdj commented 1 day ago

Basically, you need to add the following function to add candidates if IceRestart is true to your sendUpdate and sendReinvite functions in RTCSession to fix the bug:

// Set up a Completer to wait for ICE gathering to complete
Completer<void> iceGatheringCompleter = Completer();

// Set up event handlers for ICE gathering state
_connection!.onIceGatheringState = (RTCIceGatheringState state) {
  logger.d('ICE Gathering State: $state');
  if (state == RTCIceGatheringState.RTCIceGatheringStateComplete) {
    if (!iceGatheringCompleter.isCompleted) {
      iceGatheringCompleter.complete();
    }
  }
};

// Collect ICE candidates (optional, for logging or custom handling)
_connection!.onIceCandidate = (RTCIceCandidate candidate) {
  if (candidate != null) {
    logger.d('New ICE Candidate: ${candidate.candidate}');
  }
};