medea_jason/platform/dart/
send_parameters.rs

1//! Wrapper around [RTCRtpParameters].
2//!
3//! [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
4
5use dart_sys::Dart_Handle;
6use derive_more::From;
7use medea_macro::dart_bridge;
8
9use super::{
10    send_encoding_parameters::SendEncodingParameters, utils::list::DartList,
11};
12use crate::platform::dart::utils::handle::DartHandle;
13
14#[dart_bridge("flutter/lib/src/native/platform/send_parameters.g.dart")]
15mod send_parameters {
16    use dart_sys::Dart_Handle;
17
18    use crate::platform::Error;
19
20    extern "C" {
21        /// Returns [RTCRtpEncodingParameters][1] from the provided
22        /// [RTCRtpParameters].
23        ///
24        /// [RTCRtpParameters]: https://w3.org/TR/webrtc#dom-rtcrtpparameters
25        /// [1]: https://w3.org/TR/webrtc#dom-rtcrtpencodingparameters
26        pub fn encodings(parameters: Dart_Handle)
27        -> Result<Dart_Handle, Error>;
28    }
29}
30
31/// Representation of [RTCRtpSendParameters][0].
32///
33/// [0]: https://w3.org/TR/webrtc#dom-rtcrtpsendparameters
34#[derive(Clone, Debug, From)]
35pub struct SendParameters(DartHandle);
36
37impl SendParameters {
38    /// Returns [`SendEncodingParameters`] of these [`SendParameters`].
39    #[must_use]
40    pub fn encodings(&self) -> Box<[SendEncodingParameters]> {
41        let encodings =
42            unsafe { send_parameters::encodings(self.0.get()) }.unwrap();
43
44        let encodings: Vec<_> =
45            Vec::from(DartList::from(unsafe { DartHandle::new(encodings) }))
46                .into_iter()
47                .map(|encoding: DartHandle| {
48                    SendEncodingParameters::from(encoding)
49                })
50                .collect();
51
52        encodings.into_boxed_slice()
53    }
54
55    /// Returns the underlying [`Dart_Handle`] of these [`SendParameters`].
56    #[must_use]
57    pub fn handle(&self) -> Dart_Handle {
58        self.0.get()
59    }
60}