createAnswer method Null safety

Future<RTCSessionDescription> createAnswer(
  1. {bool audioRecv = true,
  2. bool videoRecv = true,
  3. bool audioSend = true,
  4. bool videoSend = true}
)

This method is used to create webrtc answer, sets local description on internal PeerConnection object It supports both style of answer creation that is plan-b and unified.

Implementation

Future<RTCSessionDescription> createAnswer({bool audioRecv: true, bool videoRecv: true, bool audioSend: true, bool videoSend: true}) async {
  dynamic offerOptions;
  if (_context._isUnifiedPlan && !_context._usePlanB) {
    await _prepareTranscievers(audioRecv: audioRecv, audioSend: audioSend, videoRecv: videoRecv, videoSend: videoSend);
  } else {
    offerOptions = {"offerToReceiveAudio": audioRecv, "offerToReceiveVideo": videoRecv};
  }
  try {
    RTCSessionDescription offer = await webRTCHandle!.peerConnection!.createAnswer(offerOptions ?? {});
    await webRTCHandle!.peerConnection!.setLocalDescription(offer);
    return offer;
  } catch (e) {
    //    handling kstable exception most ugly way but currently there's no other workaround, it just works
    RTCSessionDescription offer = await webRTCHandle!.peerConnection!.createAnswer(offerOptions ?? {});
    await webRTCHandle!.peerConnection!.setLocalDescription(offer);
    return offer;
  }
}