mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
RTCDataChannel.readyState getter
This commit is contained in:
parent
9d456d5d17
commit
7db485aeb2
4 changed files with 47 additions and 4 deletions
|
@ -16,6 +16,7 @@ characteristicvaluechanged
|
||||||
checkbox
|
checkbox
|
||||||
click
|
click
|
||||||
close
|
close
|
||||||
|
closing
|
||||||
color
|
color
|
||||||
complete
|
complete
|
||||||
compositionend
|
compositionend
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
* 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::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelInit;
|
use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelInit;
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelMethods;
|
use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelMethods;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::RTCDataChannelBinding::RTCDataChannelState;
|
||||||
use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{RTCErrorDetailType, RTCErrorInit};
|
use crate::dom::bindings::codegen::Bindings::RTCErrorBinding::{RTCErrorDetailType, RTCErrorInit};
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||||
|
@ -20,7 +22,9 @@ use dom_struct::dom_struct;
|
||||||
use js::conversions::ToJSValConvertible;
|
use js::conversions::ToJSValConvertible;
|
||||||
use js::jsapi::JSAutoRealm;
|
use js::jsapi::JSAutoRealm;
|
||||||
use js::jsval::UndefinedValue;
|
use js::jsval::UndefinedValue;
|
||||||
use servo_media::webrtc::{DataChannelId, DataChannelInit, DataChannelMessage, WebRtcError};
|
use servo_media::webrtc::{
|
||||||
|
DataChannelId, DataChannelInit, DataChannelMessage, DataChannelState, WebRtcError,
|
||||||
|
};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct RTCDataChannel {
|
pub struct RTCDataChannel {
|
||||||
|
@ -35,6 +39,7 @@ pub struct RTCDataChannel {
|
||||||
protocol: USVString,
|
protocol: USVString,
|
||||||
negotiated: bool,
|
negotiated: bool,
|
||||||
id: Option<u16>,
|
id: Option<u16>,
|
||||||
|
ready_state: DomRefCell<RTCDataChannelState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RTCDataChannel {
|
impl RTCDataChannel {
|
||||||
|
@ -68,6 +73,7 @@ impl RTCDataChannel {
|
||||||
protocol: options.protocol.clone(),
|
protocol: options.protocol.clone(),
|
||||||
negotiated: options.negotiated,
|
negotiated: options.negotiated,
|
||||||
id: options.id,
|
id: options.id,
|
||||||
|
ready_state: DomRefCell::new(RTCDataChannelState::Connecting),
|
||||||
};
|
};
|
||||||
|
|
||||||
peer_connection.register_data_channel(servo_media_id, &channel);
|
peer_connection.register_data_channel(servo_media_id, &channel);
|
||||||
|
@ -158,6 +164,22 @@ impl RTCDataChannel {
|
||||||
DataChannelMessage::Binary(_) => {},
|
DataChannelMessage::Binary(_) => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_state_change(&self, state: DataChannelState) {
|
||||||
|
match state {
|
||||||
|
DataChannelState::Closing => {
|
||||||
|
let event = Event::new(
|
||||||
|
&self.global(),
|
||||||
|
atom!("closing"),
|
||||||
|
EventBubbles::DoesNotBubble,
|
||||||
|
EventCancelable::NotCancelable,
|
||||||
|
);
|
||||||
|
event.upcast::<Event>().fire(self.upcast());
|
||||||
|
},
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
*self.ready_state.borrow_mut() = state.into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for RTCDataChannel {
|
impl Drop for RTCDataChannel {
|
||||||
|
@ -219,7 +241,13 @@ impl RTCDataChannelMethods for RTCDataChannel {
|
||||||
self.id
|
self.id
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn ReadyState(&self) -> RTCDataChannelState;
|
fn ReadyState(&self) -> RTCDataChannelState {
|
||||||
|
*self.ready_state.borrow()
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX We need a way to know when the underlying data transport
|
||||||
|
// actually sends data from its queue to decrease buffered amount.
|
||||||
|
|
||||||
// fn BufferedAmount(&self) -> u32;
|
// fn BufferedAmount(&self) -> u32;
|
||||||
// fn BufferedAmountLowThreshold(&self) -> u32;
|
// fn BufferedAmountLowThreshold(&self) -> u32;
|
||||||
// fn SetBufferedAmountLowThreshold(&self, value: u32) -> ();
|
// fn SetBufferedAmountLowThreshold(&self, value: u32) -> ();
|
||||||
|
@ -268,3 +296,16 @@ impl From<&RTCDataChannelInit> for DataChannelInit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<DataChannelState> for RTCDataChannelState {
|
||||||
|
fn from(state: DataChannelState) -> RTCDataChannelState {
|
||||||
|
match state {
|
||||||
|
DataChannelState::New |
|
||||||
|
DataChannelState::Connecting |
|
||||||
|
DataChannelState::__Unknown(_) => RTCDataChannelState::Connecting,
|
||||||
|
DataChannelState::Open => RTCDataChannelState::Open,
|
||||||
|
DataChannelState::Closing => RTCDataChannelState::Closing,
|
||||||
|
DataChannelState::Closed => RTCDataChannelState::Closed,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -320,7 +320,8 @@ impl RTCPeerConnection {
|
||||||
DataChannelEvent::Close => channel.on_close(),
|
DataChannelEvent::Close => channel.on_close(),
|
||||||
DataChannelEvent::Error(error) => channel.on_error(error),
|
DataChannelEvent::Error(error) => channel.on_error(error),
|
||||||
DataChannelEvent::OnMessage(message) => channel.on_message(message),
|
DataChannelEvent::OnMessage(message) => channel.on_message(message),
|
||||||
_ => unreachable!(),
|
DataChannelEvent::StateChange(state) => channel.on_state_change(state),
|
||||||
|
DataChannelEvent::NewChannel => unreachable!(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug_assert!(false, "Got an event for an unregistered data channel");
|
debug_assert!(false, "Got an event for an unregistered data channel");
|
||||||
|
|
|
@ -13,7 +13,7 @@ interface RTCDataChannel : EventTarget {
|
||||||
readonly attribute USVString protocol;
|
readonly attribute USVString protocol;
|
||||||
readonly attribute boolean negotiated;
|
readonly attribute boolean negotiated;
|
||||||
readonly attribute unsigned short? id;
|
readonly attribute unsigned short? id;
|
||||||
//readonly attribute RTCDataChannelState readyState;
|
readonly attribute RTCDataChannelState readyState;
|
||||||
//readonly attribute unsigned long bufferedAmount;
|
//readonly attribute unsigned long bufferedAmount;
|
||||||
//attribute unsigned long bufferedAmountLowThreshold;
|
//attribute unsigned long bufferedAmountLowThreshold;
|
||||||
attribute EventHandler onopen;
|
attribute EventHandler onopen;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue