createLocalPeerConnection method

Future<RTCPeerConnection> createLocalPeerConnection()

Creates a local peer connection

Implementation

Future<RTCPeerConnection> createLocalPeerConnection() async {
  RTCPeerConnection peerConnection =
      await createPeerConnection(_configuration);

  peerConnection.onIceCandidate = (RTCIceCandidate candidate) {
    websocket.onIceCandidate(candidate, localParticipant!.connectionId!);
  };

  peerConnection.onSignalingState = (RTCSignalingState? state) {
    if (state == RTCSignalingState.RTCSignalingStateStable) {
      for (var candidate in localParticipant!.iceCandidateList) {
        peerConnection.addCandidate(candidate);
      }
      localParticipant!.iceCandidateList.clear();
    }
  };

  if (localParticipant?.audioTrack != null) {
    peerConnection.addTransceiver(
      init: RTCRtpTransceiverInit(direction: TransceiverDirection.SendOnly),
      track: localParticipant!.audioTrack!,
    );
  }

  if (localParticipant?.videoTrack != null) {
    peerConnection.addTransceiver(
      init: RTCRtpTransceiverInit(
        direction: TransceiverDirection.SendOnly,
      ),
      track: localParticipant!.videoTrack!,
    );
  }

  return peerConnection;
}