Skip to content

Commit

Permalink
corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlapa committed Aug 27, 2024
1 parent 8cfc9ed commit ccc5df3
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ crate-type = ["cdylib", "rlib", "staticlib"]
lto = "fat"

[features]
default = ["console_error_panic_hook"]
default = ["console_error_panic_hook", "talc"]
dart-codegen = ["medea-macro/dart-codegen"]
mockable = ["mockall"]

Expand Down Expand Up @@ -71,7 +71,7 @@ send_wrapper = "0.6"
backoff = { version = "0.4", features = ["wasm-bindgen"] }
console_error_panic_hook = { version = "0.1", optional = true }
js-sys = "0.3"
talc = { version = "4.4", default-features = false, features = ["lock_api"] }
talc = { version = "4.4", default-features = false, features = ["lock_api"], optional = true }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
wasm-logger = "0.2"
Expand Down
47 changes: 23 additions & 24 deletions src/platform/wasm/codec_capability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
//!
//! [RTCRtpCodecCapability]: https://w3.org/TR/webrtc#dom-rtcrtpcodeccapability

use js_sys::{Array, JsString, Reflect};
use wasm_bindgen::JsValue;
use web_sys::RtcRtpSender;
use web_sys::{RtcRtpCodecCapability, RtcRtpSender};

use crate::{
media::MediaKind, platform::codec_capability::CodecCapabilityError as Error,
Expand All @@ -14,7 +12,7 @@ use crate::{
///
/// [RTCRtpCodecCapability]: https://w3.org/TR/webrtc#dom-rtcrtpcodeccapability
#[derive(Clone, Debug)]
pub struct CodecCapability(JsValue);
pub struct CodecCapability(RtcRtpCodecCapability);

impl CodecCapability {
/// Returns available [RTCRtpSender]'s [`CodecCapability`]s.
Expand All @@ -29,34 +27,35 @@ impl CodecCapability {
pub async fn get_sender_codec_capabilities(
kind: MediaKind,
) -> Result<Vec<Self>, Error> {
// TODO: This Reflect usage is refactored out in #180.
let codecs = RtcRtpSender::get_capabilities(&kind.to_string())
.and_then(|capabs| {
Reflect::get(&capabs, &JsString::from("codecs")).ok()
})
.ok_or(Error::FailedToGetCapabilities)?;

Ok(Array::from(&codecs).iter().map(Self).collect())
let mut result = Vec::new();

let Some(caps) = RtcRtpSender::get_capabilities(&kind.to_string())
else {
return Err(Error::FailedToGetCapabilities);
};

for codec in caps.get_codecs().values() {
let Ok(codec) = codec else {
continue;
};
result.push(Self(RtcRtpCodecCapability::from(codec)));
}

Ok(result)
}

/// Returns [MIME media type][2] of this [`CodecCapability`].
///
/// # Errors
///
/// With [`Error::FailedToGetMimeType`] if fails to retrieve codec's
/// [MIME media type][2].
///
/// [2]: https://w3.org/TR/webrtc#dom-rtcrtpcodeccapability-mimetype
pub fn mime_type(&self) -> Result<String, Error> {
Reflect::get(&self.0, &JsString::from("mimeType"))
.ok()
.and_then(|a| a.as_string())
.ok_or(Error::FailedToGetMimeType)
#[must_use]
pub fn mime_type(&self) -> String {
self.0.get_mime_type()
}

/// Returns the underlying [`JsValue`] of this [`CodecCapability`].
/// Returns the underlying [`RtcRtpCodecCapability`] of this
/// [`CodecCapability`].
#[must_use]
pub const fn handle(&self) -> &JsValue {
pub const fn handle(&self) -> &RtcRtpCodecCapability {
&self.0
}
}
3 changes: 3 additions & 0 deletions src/platform/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ pub use self::{
/// Unimplemented on WASM targets.
pub type MediaDisplayInfo = ();

#[cfg(feature = "talc")]
/// When the `talc` feature is enabled, use `talc` as the global
/// allocator.
/// SAFETY: The runtime environment must be single-threaded WASM.
#[global_allocator]
static ALLOCATOR: talc::TalckWasm = unsafe { talc::TalckWasm::new_global() };
Expand Down

0 comments on commit ccc5df3

Please sign in to comment.