From 10ab3cdcacfb5b470b4e395d0964f7ab2b25f5ce Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 20 Jul 2021 15:45:10 -0700 Subject: [PATCH] implement RTCEngine.negotiate --- lib/src/rtc_engine.dart | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/src/rtc_engine.dart b/lib/src/rtc_engine.dart index d5af658..5a80a6b 100644 --- a/lib/src/rtc_engine.dart +++ b/lib/src/rtc_engine.dart @@ -105,7 +105,28 @@ class RTCEngine with SignalClientDelegate { return completer.future; } - negotiate() async {} + negotiate([Map? constraints]) async { + var pub = this.publisher; + if (pub == null) { + return; + } + + var remoteDesc = await pub.pc.getRemoteDescription(); + // handle cases that we couldn't create a new offer due to a pending answer + // that's lost in transit + if (remoteDesc != null && + pub.pc.signalingState == + RTCSignalingState.RTCSignalingStateHaveLocalOffer) { + await pub.pc.setRemoteDescription(remoteDesc); + } + + if (constraints == null) { + constraints = {}; + } + var offer = await pub.pc.createOffer(constraints); + await pub.pc.setLocalDescription(offer); + client.sendOffer(offer); + } _configurePeerConnections() async { if (publisher != null) {