aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/rtcsessiondescription.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-01-31 12:14:16 -0500
committerGitHub <noreply@github.com>2019-01-31 12:14:16 -0500
commit6b648429f54b6b56546e8f744657e32bd6ac21b5 (patch)
tree9bac26cc42d412829af8040c454fd89af0e1afde /components/script/dom/rtcsessiondescription.rs
parent2b37e5c94d9207667f8a42fd4a032e2dacf9a354 (diff)
parent351723e6dab1d12eaaa2c7174e727b79795b2b46 (diff)
downloadservo-6b648429f54b6b56546e8f744657e32bd6ac21b5.tar.gz
servo-6b648429f54b6b56546e8f744657e32bd6ac21b5.zip
Auto merge of #22780 - Manishearth:webrtc, r=jdm
Initial webrtc and getUserMedia DOM support This is able to reach the point where connections are properly negotiated and ready to exchange streams. <s>The `toJSON()` stuff doesn't work yet, so most example code will need to be tweaked to manually construct JSON first before sending SDP and ICE messages over websockets. I'll add support for this soon. (This may need webidl tweaks to support `[Default]` and `toJSON()`)</s> For some reason I haven't yet figured out, connections are one-way, Servo is able to receive streams but the other end doesn't see the streams Servo sends. I don't think this is due to https://github.com/servo/media/issues/191, but that bug is making it harder to test. This implementation simply drops streams that it receives, without connecting them up to any output elements, since servo-media-player doesn't yet have mediastream support. Since servo can neither effectively send nor receive streams this implementation isn't useful yet, however it is getting large and I figured I'd get it reviewed and landed early as a base. r? @jdm <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/22780) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/rtcsessiondescription.rs')
-rw-r--r--components/script/dom/rtcsessiondescription.rs85
1 files changed, 85 insertions, 0 deletions
diff --git a/components/script/dom/rtcsessiondescription.rs b/components/script/dom/rtcsessiondescription.rs
new file mode 100644
index 00000000000..27ab4ca3b41
--- /dev/null
+++ b/components/script/dom/rtcsessiondescription.rs
@@ -0,0 +1,85 @@
+/* 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::RTCSessionDescriptionBinding;
+use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::RTCSessionDescriptionMethods;
+use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
+ RTCSdpType, RTCSessionDescriptionInit,
+};
+use crate::dom::bindings::error::Fallible;
+use crate::dom::bindings::reflector::reflect_dom_object;
+use crate::dom::bindings::reflector::{DomObject, Reflector};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::bindings::str::DOMString;
+use crate::dom::globalscope::GlobalScope;
+use crate::dom::window::Window;
+use dom_struct::dom_struct;
+use js::conversions::ToJSValConvertible;
+use js::jsapi::{JSContext, JSObject};
+use js::jsval::UndefinedValue;
+use std::ptr::NonNull;
+
+#[dom_struct]
+pub struct RTCSessionDescription {
+ reflector: Reflector,
+ ty: RTCSdpType,
+ sdp: DOMString,
+}
+
+impl RTCSessionDescription {
+ pub fn new_inherited(ty: RTCSdpType, sdp: DOMString) -> RTCSessionDescription {
+ RTCSessionDescription {
+ reflector: Reflector::new(),
+ ty,
+ sdp,
+ }
+ }
+
+ pub fn new(
+ global: &GlobalScope,
+ ty: RTCSdpType,
+ sdp: DOMString,
+ ) -> DomRoot<RTCSessionDescription> {
+ reflect_dom_object(
+ Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
+ global,
+ RTCSessionDescriptionBinding::Wrap,
+ )
+ }
+
+ pub fn Constructor(
+ window: &Window,
+ config: &RTCSessionDescriptionInit,
+ ) -> Fallible<DomRoot<RTCSessionDescription>> {
+ Ok(RTCSessionDescription::new(
+ &window.global(),
+ config.type_,
+ config.sdp.clone(),
+ ))
+ }
+}
+
+impl RTCSessionDescriptionMethods for RTCSessionDescription {
+ /// https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-type
+ fn Type(&self) -> RTCSdpType {
+ self.ty
+ }
+
+ /// https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-sdp
+ fn Sdp(&self) -> DOMString {
+ self.sdp.clone()
+ }
+
+ #[allow(unsafe_code)]
+ /// https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-tojson
+ unsafe fn ToJSON(&self, cx: *mut JSContext) -> NonNull<JSObject> {
+ let init = RTCSessionDescriptionInit {
+ type_: self.ty,
+ sdp: self.sdp.clone(),
+ };
+ rooted!(in(cx) let mut jsval = UndefinedValue());
+ init.to_jsval(cx, jsval.handle_mut());
+ NonNull::new(jsval.to_object()).unwrap()
+ }
+}