mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Fix data channels borrowing errors
This commit is contained in:
parent
b968852456
commit
7eb44f81f2
2 changed files with 18 additions and 14 deletions
|
@ -30,6 +30,7 @@ use script_traits::serializable::BlobImpl;
|
||||||
use servo_media::webrtc::{
|
use servo_media::webrtc::{
|
||||||
DataChannelId, DataChannelInit, DataChannelMessage, DataChannelState, WebRtcError,
|
DataChannelId, DataChannelInit, DataChannelMessage, DataChannelState, WebRtcError,
|
||||||
};
|
};
|
||||||
|
use std::cell::Cell;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -45,7 +46,7 @@ pub struct RTCDataChannel {
|
||||||
protocol: USVString,
|
protocol: USVString,
|
||||||
negotiated: bool,
|
negotiated: bool,
|
||||||
id: Option<u16>,
|
id: Option<u16>,
|
||||||
ready_state: DomRefCell<RTCDataChannelState>,
|
ready_state: Cell<RTCDataChannelState>,
|
||||||
binary_type: DomRefCell<DOMString>,
|
binary_type: DomRefCell<DOMString>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +81,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),
|
ready_state: Cell::new(RTCDataChannelState::Connecting),
|
||||||
binary_type: DomRefCell::new(DOMString::from("blob")),
|
binary_type: DomRefCell::new(DOMString::from("blob")),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -209,11 +210,11 @@ impl RTCDataChannel {
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
};
|
};
|
||||||
*self.ready_state.borrow_mut() = state.into();
|
self.ready_state.set(state.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send(&self, source: &SendSource) -> Fallible<()> {
|
fn send(&self, source: &SendSource) -> Fallible<()> {
|
||||||
if *self.ready_state.borrow() != RTCDataChannelState::Open {
|
if self.ready_state.get() != RTCDataChannelState::Open {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +305,7 @@ impl RTCDataChannelMethods for RTCDataChannel {
|
||||||
|
|
||||||
// https://www.w3.org/TR/webrtc/#dom-datachannel-readystate
|
// https://www.w3.org/TR/webrtc/#dom-datachannel-readystate
|
||||||
fn ReadyState(&self) -> RTCDataChannelState {
|
fn ReadyState(&self) -> RTCDataChannelState {
|
||||||
*self.ready_state.borrow()
|
self.ready_state.get()
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX We need a way to know when the underlying data transport
|
// XXX We need a way to know when the underlying data transport
|
||||||
|
|
|
@ -311,17 +311,20 @@ impl RTCPeerConnection {
|
||||||
event.upcast::<Event>().fire(self.upcast());
|
event.upcast::<Event>().fire(self.upcast());
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(ref channel) = self.data_channels.borrow().get(&channel_id) {
|
let channel = if let Some(channel) = self.data_channels.borrow().get(&channel_id) {
|
||||||
match event {
|
DomRoot::from_ref(&**channel)
|
||||||
DataChannelEvent::Open => channel.on_open(),
|
|
||||||
DataChannelEvent::Close => channel.on_close(),
|
|
||||||
DataChannelEvent::Error(error) => channel.on_error(error),
|
|
||||||
DataChannelEvent::OnMessage(message) => channel.on_message(message),
|
|
||||||
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");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
|
match event {
|
||||||
|
DataChannelEvent::Open => channel.on_open(),
|
||||||
|
DataChannelEvent::Close => channel.on_close(),
|
||||||
|
DataChannelEvent::Error(error) => channel.on_error(error),
|
||||||
|
DataChannelEvent::OnMessage(message) => channel.on_message(message),
|
||||||
|
DataChannelEvent::StateChange(state) => channel.on_state_change(state),
|
||||||
|
DataChannelEvent::NewChannel => unreachable!(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue