pub(crate) async fn satisfy_type_and_direction(
    remote_kind: RTPCodecType,
    remote_direction: RTCRtpTransceiverDirection,
    local_transceivers: &mut Vec<Arc<RTCRtpTransceiver>>,
) -> Option<Arc<RTCRtpTransceiver>> {
    // Get direction order from most preferred to least
    let get_preferred_directions = || -> Vec<RTCRtpTransceiverDirection> {
        match remote_direction {
            RTCRtpTransceiverDirection::Sendrecv => vec![
                RTCRtpTransceiverDirection::Recvonly,
                RTCRtpTransceiverDirection::Sendrecv,
            ],
            RTCRtpTransceiverDirection::Sendonly => vec![RTCRtpTransceiverDirection::Recvonly],
            RTCRtpTransceiverDirection::Recvonly => vec![
                RTCRtpTransceiverDirection::Sendonly,
                RTCRtpTransceiverDirection::Sendrecv,
            ],
            _ => vec![],
        }
    };

    for possible_direction in get_preferred_directions() {
        for (i, t) in local_transceivers.iter().enumerate() {
            if t.mid().await.is_empty()
                && t.kind == remote_kind
                && possible_direction == t.direction()
            {
                return Some(local_transceivers.remove(i));
            }
        }
    }

    None
}
/// Given a direction+type pluck a transceiver from the passed list
/// if no entry satisfies the requested type+direction return a inactive Transceiver
Given a direction+type pluck a transceiver from the passed list
if no entry satisfies the requested type+direction return a inactive Transceiver
Given a direction + type pluck a transceiver from the passed list if no entry satisfies the requested type + direction return a inactive Transceiver
pub(crate) async fn satisfy_type_and_direction(
    remote_kind: RTPCodecType,
    remote_direction: RTCRtpTransceiverDirection,
    local_transceivers: &mut Vec<Arc<RTCRtpTransceiver>>,
) -> Option<Arc<RTCRtpTransceiver>> {
    // Get direction order from most preferred to least
    let get_preferred_directions = || -> Vec<RTCRtpTransceiverDirection> {
        match remote_direction {
            RTCRtpTransceiverDirection::Sendrecv => vec![
                RTCRtpTransceiverDirection::Recvonly,
                RTCRtpTransceiverDirection::Sendrecv,
            ],
            RTCRtpTransceiverDirection::Sendonly => vec![RTCRtpTransceiverDirection::Recvonly],
            RTCRtpTransceiverDirection::Recvonly => vec![
                RTCRtpTransceiverDirection::Sendonly,
                RTCRtpTransceiverDirection::Sendrecv,
            ],
            _ => vec![],
        }
    };
    for possible_direction in get_preferred_directions() {
        for (i, t) in local_transceivers.iter().enumerate() {
            if t.mid().await.is_empty()
                && t.kind == remote_kind
                && possible_direction == t.direction()
            {
                return Some(local_transceivers.remove(i));
            }
        }
    }
    None
}
pub ( crate ) async fn satisfy_type_and_direction ( remote_kind : RTPCodecType , remote_direction : RTCRtpTransceiverDirection , local_transceivers : & mut Vec < Arc < RTCRtpTransceiver > > , ) -> Option < Arc < RTCRtpTransceiver > > { // Get direction order from most preferred to least let get_preferred_directions = | | -> Vec < RTCRtpTransceiverDirection > { match remote_direction { RTCRtpTransceiverDirection :: Sendrecv => vec ! [ RTCRtpTransceiverDirection Recvonly RTCRtpTransceiverDirection Sendrecv ] , RTCRtpTransceiverDirection :: Sendonly => vec ! [ RTCRtpTransceiverDirection Recvonly ] , RTCRtpTransceiverDirection :: Recvonly => vec ! [ RTCRtpTransceiverDirection Sendonly RTCRtpTransceiverDirection Sendrecv ] , _ => vec ! [ ] , } } ; for possible_direction in get_preferred_directions ( ) { for ( i , t ) in local_transceivers . iter ( ) . enumerate ( ) { if t . mid ( ) . await . is_empty ( ) && t . kind == remote_kind && possible_direction == t . direction ( ) { return Some ( local_transceivers . remove ( i ) ) ; } } } None }
Given a direction+type pluck a transceiver from the passed list
if no entry satisfies the requested type+direction return a inactive Transceiver
Given a direction + type pluck a transceiver from the passed list if no entry satisfies the requested type + direction return a inactive Transceiver
remote_kind
RTPCodecType
remote_direction
RTCRtpTransceiverDirection
local_transceivers
&mut Vec<Arc<RTCRtpTransceiver>>