dom: Add WebRTC transceiver stubs.

This commit is contained in:
Josh Matthews 2020-07-14 12:10:13 -04:00
parent 1ae117f67b
commit 84efd56e57
9 changed files with 220 additions and 4 deletions

View file

@ -256,6 +256,9 @@ mod gen {
enabled: bool,
},
webrtc: {
transceiver: {
enabled: bool,
},
#[serde(default)]
enabled: bool,
},

View file

@ -498,6 +498,8 @@ pub mod rtcerrorevent;
pub mod rtcicecandidate;
pub mod rtcpeerconnection;
pub mod rtcpeerconnectioniceevent;
pub(crate) mod rtcrtpsender;
pub(crate) mod rtcrtptransceiver;
pub mod rtcsessiondescription;
pub mod rtctrackevent;
pub mod screen;

View file

@ -8,12 +8,12 @@ use crate::dom::bindings::codegen::Bindings::RTCIceCandidateBinding::RTCIceCandi
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::RTCPeerConnectionMethods;
use crate::dom::bindings::codegen::Bindings::RTCPeerConnectionBinding::{
RTCAnswerOptions, RTCBundlePolicy, RTCConfiguration, RTCIceConnectionState,
RTCIceGatheringState, RTCOfferOptions, RTCSignalingState,
RTCIceGatheringState, RTCOfferOptions, RTCRtpTransceiverInit, RTCSignalingState,
};
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit,
};
use crate::dom::bindings::codegen::UnionTypes::StringOrStringSequence;
use crate::dom::bindings::codegen::UnionTypes::{MediaStreamTrackOrString, StringOrStringSequence};
use crate::dom::bindings::error::Error;
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::inheritance::Castable;
@ -32,6 +32,7 @@ use crate::dom::rtcdatachannel::RTCDataChannel;
use crate::dom::rtcdatachannelevent::RTCDataChannelEvent;
use crate::dom::rtcicecandidate::RTCIceCandidate;
use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent;
use crate::dom::rtcrtptransceiver::RTCRtpTransceiver;
use crate::dom::rtcsessiondescription::RTCSessionDescription;
use crate::dom::rtctrackevent::RTCTrackEvent;
use crate::dom::window::Window;
@ -744,6 +745,15 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
) -> DomRoot<RTCDataChannel> {
RTCDataChannel::new(&self.global(), &self, label, init, None)
}
/// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
fn AddTransceiver(
&self,
_track_or_kind: MediaStreamTrackOrString,
init: &RTCRtpTransceiverInit,
) -> DomRoot<RTCRtpTransceiver> {
RTCRtpTransceiver::new(&self.global(), init.direction)
}
}
impl From<SessionDescription> for RTCSessionDescriptionInit {

View file

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
use crate::dom::bindings::codegen::Bindings::RTCRtpSenderBinding::RTCRtpSenderMethods;
use crate::dom::bindings::codegen::Bindings::RTCRtpSenderBinding::{
RTCRtcpParameters, RTCRtpParameters, RTCRtpSendParameters,
};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use dom_struct::dom_struct;
use std::rc::Rc;
#[dom_struct]
pub struct RTCRtpSender {
reflector_: Reflector,
}
impl RTCRtpSender {
fn new_inherited() -> Self {
Self {
reflector_: Reflector::new(),
}
}
pub(crate) fn new(global: &GlobalScope) -> DomRoot<Self> {
reflect_dom_object(Box::new(Self::new_inherited()), global)
}
}
impl RTCRtpSenderMethods for RTCRtpSender {
// https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-getparameters
fn GetParameters(&self) -> RTCRtpSendParameters {
RTCRtpSendParameters {
parent: RTCRtpParameters {
headerExtensions: vec![],
rtcp: RTCRtcpParameters {
cname: None,
reducedSize: None,
},
codecs: vec![],
},
transactionId: DOMString::new(),
encodings: vec![],
}
}
// https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-setparameters
fn SetParameters(&self, _parameters: &RTCRtpSendParameters) -> Rc<Promise> {
let promise = Promise::new(&self.global());
promise.resolve_native(&());
promise
}
}

View file

@ -0,0 +1,55 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
use crate::dom::bindings::codegen::Bindings::RTCRtpTransceiverBinding::{
RTCRtpTransceiverDirection, RTCRtpTransceiverMethods,
};
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::rtcrtpsender::RTCRtpSender;
use dom_struct::dom_struct;
use std::cell::Cell;
#[dom_struct]
pub struct RTCRtpTransceiver {
reflector_: Reflector,
sender: Dom<RTCRtpSender>,
direction: Cell<RTCRtpTransceiverDirection>,
}
impl RTCRtpTransceiver {
fn new_inherited(global: &GlobalScope, direction: RTCRtpTransceiverDirection) -> Self {
let sender = RTCRtpSender::new(global);
Self {
reflector_: Reflector::new(),
direction: Cell::new(direction),
sender: Dom::from_ref(&*sender),
}
}
pub(crate) fn new(
global: &GlobalScope,
direction: RTCRtpTransceiverDirection,
) -> DomRoot<Self> {
reflect_dom_object(Box::new(Self::new_inherited(global, direction)), global)
}
}
impl RTCRtpTransceiverMethods for RTCRtpTransceiver {
/// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
fn Direction(&self) -> RTCRtpTransceiverDirection {
self.direction.get()
}
/// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-direction
fn SetDirection(&self, direction: RTCRtpTransceiverDirection) {
self.direction.set(direction);
}
/// https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-sender
fn Sender(&self) -> DomRoot<RTCRtpSender> {
DomRoot::from_ref(&*self.sender)
}
}

View file

@ -115,6 +115,22 @@ enum RTCSignalingState {
"closed"
};
dictionary RTCRtpCodingParameters {
DOMString rid;
};
dictionary RTCRtpEncodingParameters : RTCRtpCodingParameters {
boolean active = true;
unsigned long maxBitrate;
double scaleResolutionDownBy;
};
dictionary RTCRtpTransceiverInit {
RTCRtpTransceiverDirection direction = "sendrecv";
sequence<MediaStream> streams = [];
sequence<RTCRtpEncodingParameters> sendEncodings = [];
};
partial interface RTCPeerConnection {
// sequence<RTCRtpSender> getSenders();
// sequence<RTCRtpReceiver> getReceivers();
@ -122,8 +138,9 @@ partial interface RTCPeerConnection {
// RTCRtpSender addTrack(MediaStreamTrack track,
// MediaStream... streams);
// void removeTrack(RTCRtpSender sender);
// RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind,
// optional RTCRtpTransceiverInit init);
[Pref="dom.webrtc.transceiver.enabled"]
RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind,
optional RTCRtpTransceiverInit init = {});
attribute EventHandler ontrack;
};

View file

@ -0,0 +1,47 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
// https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender
dictionary RTCRtpHeaderExtensionParameters {
required DOMString uri;
required unsigned short id;
boolean encrypted = false;
};
dictionary RTCRtcpParameters {
DOMString cname;
boolean reducedSize;
};
dictionary RTCRtpCodecParameters {
required octet payloadType;
required DOMString mimeType;
required unsigned long clockRate;
unsigned short channels;
DOMString sdpFmtpLine;
};
dictionary RTCRtpParameters {
required sequence<RTCRtpHeaderExtensionParameters> headerExtensions;
required RTCRtcpParameters rtcp;
required sequence<RTCRtpCodecParameters> codecs;
};
dictionary RTCRtpSendParameters : RTCRtpParameters {
required DOMString transactionId;
required sequence<RTCRtpEncodingParameters> encodings;
};
[Exposed=Window, Pref="dom.webrtc.transceiver.enabled"]
interface RTCRtpSender {
//readonly attribute MediaStreamTrack? track;
//readonly attribute RTCDtlsTransport? transport;
//static RTCRtpCapabilities? getCapabilities(DOMString kind);
Promise<void> setParameters(RTCRtpSendParameters parameters);
RTCRtpSendParameters getParameters();
//Promise<void> replaceTrack(MediaStreamTrack? withTrack);
//void setStreams(MediaStream... streams);
//Promise<RTCStatsReport> getStats();
};

View file

@ -0,0 +1,24 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
// https://w3c.github.io/webrtc-pc/#rtcrtptransceiver-interface
[Exposed=Window, Pref="dom.webrtc.transceiver.enabled"]
interface RTCRtpTransceiver {
//readonly attribute DOMString? mid;
[SameObject] readonly attribute RTCRtpSender sender;
//[SameObject] readonly attribute RTCRtpReceiver receiver;
attribute RTCRtpTransceiverDirection direction;
//readonly attribute RTCRtpTransceiverDirection? currentDirection;
//void stop();
//void setCodecPreferences(sequence<RTCRtpCodecCapability> codecs);
};
enum RTCRtpTransceiverDirection {
"sendrecv",
"sendonly",
"recvonly",
"inactive",
"stopped"
};

View file

@ -30,6 +30,7 @@
"dom.webgl2.enabled": false,
"dom.webgpu.enabled": false,
"dom.webrtc.enabled": false,
"dom.webrtc.transceiver.enabled": false,
"dom.webvr.enabled": false,
"dom.webvr.event_polling_interval": 500,
"dom.webvr.test": false,