use web_sys::{RtcRtpCodecCapability, RtcRtpSender};
use crate::{
media::MediaKind, platform::codec_capability::CodecCapabilityError as Error,
};
#[derive(Clone, Debug)]
pub struct CodecCapability(RtcRtpCodecCapability);
impl CodecCapability {
#[expect(clippy::unused_async, reason = "`cfg` code uniformity")]
pub async fn get_sender_codec_capabilities(
kind: MediaKind,
) -> Result<Vec<Self>, Error> {
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)
}
#[must_use]
pub fn mime_type(&self) -> String {
self.0.get_mime_type()
}
#[must_use]
pub const fn handle(&self) -> &RtcRtpCodecCapability {
&self.0
}
}