Skip to content

Commit 04e25dc

Browse files
authored
Merge pull request #157 from carlogrisetti/fix_delayed_ice
Convert onIceCandidate to async and introduce a delay
2 parents c042316 + 64cd6df commit 04e25dc

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/src/call_sample/signaling.dart

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,21 +392,27 @@ class Signaling {
392392
sender.setParameters(parameters);
393393
*/
394394
}
395-
pc.onIceCandidate = (candidate) {
395+
pc.onIceCandidate = (candidate) async {
396396
if (candidate == null) {
397397
print('onIceCandidate: complete!');
398398
return;
399399
}
400-
_send('candidate', {
401-
'to': peerId,
402-
'from': _selfId,
403-
'candidate': {
404-
'sdpMLineIndex': candidate.sdpMlineIndex,
405-
'sdpMid': candidate.sdpMid,
406-
'candidate': candidate.candidate,
407-
},
408-
'session_id': sessionId,
409-
});
400+
// This delay is needed to allow enough time to try an ICE candidate
401+
// before skipping to the next one. 1 second is just an heuristic value
402+
// and should be thoroughly tested in your own environment.
403+
await Future.delayed(
404+
const Duration(seconds: 1),
405+
() => _send('candidate', {
406+
'to': peerId,
407+
'from': _selfId,
408+
'candidate': {
409+
'sdpMLineIndex': candidate.sdpMlineIndex,
410+
'sdpMid': candidate.sdpMid,
411+
'candidate': candidate.candidate,
412+
},
413+
'session_id': sessionId,
414+
})
415+
);
410416
};
411417

412418
pc.onIceConnectionState = (state) {};

0 commit comments

Comments
 (0)