createRemotePeerConnection method

Future<void> createRemotePeerConnection(
  1. String connectionId
)

Creates a remote peer connection

Implementation

Future<void> createRemotePeerConnection(String connectionId) async {
  RTCPeerConnection peerConnection =
      await createPeerConnection(_configuration);

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

  peerConnection.onTrack = (RTCTrackEvent event) {
    _setRemoteMediaStream(
        event.streams[0], remoteParticipants[connectionId]!);
  };

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

  peerConnection.addTransceiver(
    kind: RTCRtpMediaType.RTCRtpMediaTypeAudio,
    init: RTCRtpTransceiverInit(direction: TransceiverDirection.RecvOnly),
  );
  peerConnection.addTransceiver(
    kind: RTCRtpMediaType.RTCRtpMediaTypeVideo,
    init: RTCRtpTransceiverInit(direction: TransceiverDirection.RecvOnly),
  );

  remoteParticipants[connectionId]!.peerConnection = peerConnection;
}