mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Add MediaDevices::GetUserMedia
This commit is contained in:
parent
eee183d7f4
commit
8b0719a6f2
5 changed files with 40 additions and 12 deletions
|
@ -101,7 +101,7 @@ use servo_media::audio::graph::NodeId;
|
||||||
use servo_media::audio::panner_node::{DistanceModel, PanningModel};
|
use servo_media::audio::panner_node::{DistanceModel, PanningModel};
|
||||||
use servo_media::audio::param::ParamType;
|
use servo_media::audio::param::ParamType;
|
||||||
use servo_media::player::Player;
|
use servo_media::player::Player;
|
||||||
use servo_media::webrtc::WebRtcController;
|
use servo_media::webrtc::{MediaStream as BackendMediaStream, WebRtcController};
|
||||||
use servo_media::Backend;
|
use servo_media::Backend;
|
||||||
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -485,6 +485,7 @@ unsafe_no_jsmanaged_fields!(NodeId);
|
||||||
unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType);
|
unsafe_no_jsmanaged_fields!(AnalysisEngine, DistanceModel, PanningModel, ParamType);
|
||||||
unsafe_no_jsmanaged_fields!(dyn Player);
|
unsafe_no_jsmanaged_fields!(dyn Player);
|
||||||
unsafe_no_jsmanaged_fields!(WebRtcController);
|
unsafe_no_jsmanaged_fields!(WebRtcController);
|
||||||
|
unsafe_no_jsmanaged_fields!(dyn BackendMediaStream);
|
||||||
unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>);
|
unsafe_no_jsmanaged_fields!(Mutex<MediaFrameRenderer>);
|
||||||
unsafe_no_jsmanaged_fields!(RenderApiSender);
|
unsafe_no_jsmanaged_fields!(RenderApiSender);
|
||||||
unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
|
unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
|
||||||
|
|
|
@ -2,15 +2,18 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::MediaDevicesBinding;
|
use crate::dom::bindings::codegen::Bindings::MediaDevicesBinding::MediaStreamConstraints;
|
||||||
use crate::dom::bindings::error::Fallible;
|
use crate::dom::bindings::codegen::Bindings::MediaDevicesBinding::{self, MediaDevicesMethods};
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::mediastream::MediaStream;
|
||||||
|
use crate::dom::promise::Promise;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use servo_media::ServoMedia;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct MediaDevices {
|
pub struct MediaDevices {
|
||||||
|
@ -32,3 +35,25 @@ impl MediaDevices {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl MediaDevicesMethods for MediaDevices {
|
||||||
|
/// https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia
|
||||||
|
fn GetUserMedia(&self, constraints: &MediaStreamConstraints) -> Rc<Promise> {
|
||||||
|
let p = Promise::new(&self.global());
|
||||||
|
let media = ServoMedia::get().unwrap();
|
||||||
|
let mut tracks = vec![];
|
||||||
|
if constraints.audio {
|
||||||
|
if let Some(audio) = media.create_audioinput_stream() {
|
||||||
|
tracks.push(audio)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if constraints.video {
|
||||||
|
if let Some(video) = media.create_videoinput_stream() {
|
||||||
|
tracks.push(video)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let stream = MediaStream::new(&self.global(), tracks);
|
||||||
|
p.resolve_native(&stream);
|
||||||
|
p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,30 +3,31 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::codegen::Bindings::MediaStreamBinding;
|
use crate::dom::bindings::codegen::Bindings::MediaStreamBinding;
|
||||||
use crate::dom::bindings::error::Fallible;
|
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::window::Window;
|
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use servo_media::webrtc::MediaStream as BackendMediaStream;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct MediaStream {
|
pub struct MediaStream {
|
||||||
eventtarget: EventTarget,
|
eventtarget: EventTarget,
|
||||||
|
#[ignore_malloc_size_of = "defined in servo-media"]
|
||||||
|
tracks: Vec<Box<BackendMediaStream>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MediaStream {
|
impl MediaStream {
|
||||||
pub fn new_inherited() -> MediaStream {
|
pub fn new_inherited(tracks: Vec<Box<BackendMediaStream>>) -> MediaStream {
|
||||||
MediaStream {
|
MediaStream {
|
||||||
eventtarget: EventTarget::new_inherited(),
|
eventtarget: EventTarget::new_inherited(),
|
||||||
|
tracks,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(global: &GlobalScope) -> DomRoot<MediaStream> {
|
pub fn new(global: &GlobalScope, tracks: Vec<Box<BackendMediaStream>>) -> DomRoot<MediaStream> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(MediaStream::new_inherited()),
|
Box::new(MediaStream::new_inherited(tracks)),
|
||||||
global,
|
global,
|
||||||
MediaStreamBinding::Wrap,
|
MediaStreamBinding::Wrap,
|
||||||
)
|
)
|
||||||
|
|
|
@ -167,6 +167,7 @@ impl NavigatorMethods for Navigator {
|
||||||
|
|
||||||
/// https://w3c.github.io/mediacapture-main/#dom-navigator-mediadevices
|
/// https://w3c.github.io/mediacapture-main/#dom-navigator-mediadevices
|
||||||
fn MediaDevices(&self) -> DomRoot<MediaDevices> {
|
fn MediaDevices(&self) -> DomRoot<MediaDevices> {
|
||||||
self.mediadevices.or_init(|| MediaDevices::new(&self.global()))
|
self.mediadevices
|
||||||
|
.or_init(|| MediaDevices::new(&self.global()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ partial interface Navigator {
|
||||||
|
|
||||||
partial interface MediaDevices {
|
partial interface MediaDevices {
|
||||||
// MediaTrackSupportedConstraints getSupportedConstraints();
|
// MediaTrackSupportedConstraints getSupportedConstraints();
|
||||||
// Promise<MediaStream> getUserMedia(optional MediaStreamConstraints constraints);
|
Promise<MediaStream> getUserMedia(optional MediaStreamConstraints constraints);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue