@@ -1664,38 +1664,39 @@ class RTCSession extends EventManager {
16641664 // Add 'pc.onicencandidate' event handler to resolve on last candidate.
16651665 bool finished = false ;
16661666 Future <Null > Function () ready = () async {
1667- _connection.onIceCandidate = null ;
1668- _connection.onIceGatheringState = null ;
1669- _iceGatheringState = RTCIceGatheringState .RTCIceGatheringStateComplete ;
1670- finished = true ;
1671- _rtcReady = true ;
1672- RTCSessionDescription desc = await _connection.getLocalDescription ();
1673- logger.debug ('emit "sdp"' );
1674- emit (EventSdp (originator: 'local' , type: type, sdp: desc.sdp));
1675- completer.complete (desc);
1667+ if (! finished) {
1668+ finished = true ;
1669+ _connection.onIceCandidate = null ;
1670+ _connection.onIceGatheringState = null ;
1671+ _iceGatheringState = RTCIceGatheringState .RTCIceGatheringStateComplete ;
1672+ _rtcReady = true ;
1673+ RTCSessionDescription desc = await _connection.getLocalDescription ();
1674+ logger.debug ('emit "sdp"' );
1675+ emit (EventSdp (originator: 'local' , type: type, sdp: desc.sdp));
1676+ completer.complete (desc);
1677+ }
16761678 };
16771679
16781680 _connection.onIceGatheringState = (RTCIceGatheringState state) {
16791681 _iceGatheringState = state;
16801682 if (state == RTCIceGatheringState .RTCIceGatheringStateComplete ) {
1681- if (! finished) {
1682- ready ();
1683- }
1683+ ready ();
16841684 }
16851685 };
16861686
1687+ bool hasCandidate = false ;
16871688 _connection.onIceCandidate = (RTCIceCandidate candidate) {
16881689 if (candidate != null ) {
16891690 emit (EventIceCandidate (candidate, ready));
1690- if (! finished ) {
1691- finished = true ;
1691+ if (! hasCandidate ) {
1692+ hasCandidate = true ;
16921693 /**
1693- * Just wait for 3 seconds. In the case of multiple network connections,
1694+ * Just wait for 0.5 seconds. In the case of multiple network connections,
16941695 * the RTCIceGatheringStateComplete event needs to wait for 10 ~ 30 seconds.
16951696 * Because trickle ICE is not defined in the sip protocol, the delay of
16961697 * initiating a call to answer the call waiting will be unacceptable.
16971698 */
1698- setTimeout (() => ready (), 3000 );
1699+ setTimeout (() => ready (), 500 );
16991700 }
17001701 }
17011702 };
0 commit comments