#![expect( // intentional
clippy::new_without_default,
reason = "makes no sense for `wasm_bindgen`"
)]
use derive_more::with_trait::{From, Into};
use wasm_bindgen::prelude::*;
use crate::{api::FacingMode, media, media::constraints::ConstrainBoolean};
#[wasm_bindgen]
#[derive(Clone, Debug, From, Into)]
pub struct MediaStreamSettings(media::MediaStreamSettings);
#[wasm_bindgen]
impl MediaStreamSettings {
#[must_use]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
media::MediaStreamSettings::new().into()
}
pub fn device_audio(&mut self, constraints: DeviceAudioTrackConstraints) {
self.0.device_audio(constraints.into());
}
pub fn display_audio(&mut self, constraints: DisplayAudioTrackConstraints) {
self.0.display_audio(constraints.into());
}
pub fn device_video(&mut self, constraints: DeviceVideoTrackConstraints) {
self.0.device_video(constraints.into());
}
pub fn display_video(&mut self, constraints: DisplayVideoTrackConstraints) {
self.0.display_video(constraints.into());
}
}
#[wasm_bindgen]
#[derive(Debug, From, Into)]
pub struct DeviceAudioTrackConstraints(media::DeviceAudioTrackConstraints);
#[expect( // `wasm_bindgen` doesn't support `const fn`
clippy::missing_const_for_fn,
reason = "`wasm_bindgen` doesn't support `const fn`"
)]
#[wasm_bindgen]
impl DeviceAudioTrackConstraints {
#[must_use]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
media::DeviceAudioTrackConstraints::new().into()
}
pub fn device_id(&mut self, device_id: String) {
self.0.device_id(device_id);
}
pub fn exact_auto_gain_control(&mut self, agc: bool) {
self.0.auto_gain_control = Some(ConstrainBoolean::Exact(agc));
}
pub fn ideal_auto_gain_control(&mut self, agc: bool) {
self.0.auto_gain_control = Some(ConstrainBoolean::Ideal(agc));
}
pub fn exact_noise_suppression(&mut self, ns: bool) {
self.0.noise_suppression = Some(ConstrainBoolean::Exact(ns));
}
pub fn ideal_noise_suppression(&mut self, ns: bool) {
self.0.noise_suppression = Some(ConstrainBoolean::Ideal(ns));
}
pub fn exact_echo_cancellation(&mut self, aec: bool) {
self.0.echo_cancellation = Some(ConstrainBoolean::Exact(aec));
}
pub fn ideal_echo_cancellation(&mut self, aec: bool) {
self.0.echo_cancellation = Some(ConstrainBoolean::Ideal(aec));
}
}
#[wasm_bindgen]
#[derive(Copy, Clone, Debug, From, Into)]
pub struct DisplayAudioTrackConstraints(media::DisplayAudioTrackConstraints);
#[wasm_bindgen]
impl DisplayAudioTrackConstraints {
#[must_use]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
media::DisplayAudioTrackConstraints::new().into()
}
}
#[wasm_bindgen]
#[derive(Debug, From, Into)]
pub struct DeviceVideoTrackConstraints(media::DeviceVideoTrackConstraints);
#[expect( // `wasm_bindgen` doesn't support `const fn`
clippy::missing_const_for_fn,
reason = "`wasm_bindgen` doesn't support `const fn`"
)]
#[wasm_bindgen]
impl DeviceVideoTrackConstraints {
#[must_use]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
media::DeviceVideoTrackConstraints::new().into()
}
pub fn device_id(&mut self, device_id: String) {
self.0.device_id(device_id);
}
pub fn exact_facing_mode(&mut self, facing_mode: FacingMode) {
self.0.exact_facing_mode(facing_mode.into());
}
pub fn ideal_facing_mode(&mut self, facing_mode: FacingMode) {
self.0.ideal_facing_mode(facing_mode.into());
}
pub fn exact_height(&mut self, height: u32) {
self.0.exact_height(height);
}
pub fn ideal_height(&mut self, height: u32) {
self.0.ideal_height(height);
}
pub fn height_in_range(&mut self, min: u32, max: u32) {
self.0.height_in_range(min, max);
}
pub fn exact_width(&mut self, width: u32) {
self.0.exact_width(width);
}
pub fn ideal_width(&mut self, width: u32) {
self.0.ideal_width(width);
}
pub fn width_in_range(&mut self, min: u32, max: u32) {
self.0.width_in_range(min, max);
}
}
#[wasm_bindgen]
#[derive(Clone, Debug, From, Into)]
pub struct DisplayVideoTrackConstraints(media::DisplayVideoTrackConstraints);
#[expect( // `wasm_bindgen` doesn't support `const fn`
clippy::missing_const_for_fn,
reason = "`wasm_bindgen` doesn't support `const fn`"
)]
#[wasm_bindgen]
impl DisplayVideoTrackConstraints {
#[must_use]
#[wasm_bindgen(constructor)]
pub fn new() -> Self {
media::DisplayVideoTrackConstraints::new().into()
}
pub fn exact_height(&mut self, height: u32) {
self.0.exact_height(height);
}
pub fn ideal_height(&mut self, height: u32) {
self.0.ideal_height(height);
}
pub fn exact_width(&mut self, width: u32) {
self.0.exact_width(width);
}
pub fn ideal_width(&mut self, width: u32) {
self.0.ideal_width(width);
}
pub fn exact_frame_rate(&mut self, frame_rate: u32) {
self.0.exact_frame_rate(frame_rate);
}
pub fn ideal_frame_rate(&mut self, frame_rate: u32) {
self.0.ideal_frame_rate(frame_rate);
}
}