Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upWebRTC data channels backend #350
Conversation
| .map_err(|e| e.to_string())?; | ||
|
|
||
| let channel = InnerDataChannel { | ||
| channel: glib::SendWeakRef::from(channel.downgrade()), |
This comment has been minimized.
This comment has been minimized.
sdroege
May 31, 2020
Contributor
This is going to explode sooner or later. The datachannel object is thread-safe, but until https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/issues/1168 is solved you'll have to put your own wrapper struct around it on which Send/Sync are implemented.
| Ok(()) | ||
| self.channel | ||
| .0 | ||
| .emit("send-string", &[&Value::from(message)]) |
This comment has been minimized.
This comment has been minimized.
sdroege
Jun 1, 2020
Contributor
While at it, you could also hide the signal emission things in functions inside impl DataChannel :)
…eakRef
|
Overall this seems good, but I'm not quite sure of the callback model. It kind of would be nice if the actual data channel was completely backend-side, and never exposed to the client as InternalDataChannel, and the backend just kept track of DataChannelIds that it returned to the frontend. This also means that data channel events can simply be another trait method on WebRTCSignaller!:
How does this sound? The signaller/controller distinction exists precisely so that this kind of stuff is easy to do without |
| } | ||
|
|
||
| impl WebRtcDataChannel for GStreamerWebRtcDataChannel { | ||
| fn set_on_open(&self, cb: SendBoxFnOnce<'static, ()>) { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Jun 2, 2020
Member
This feels potentially racy, what if the client sets the callbacks after the channel is created?
Perhaps we should pass in the WebRtcDataChannelCallbacks in at construction? As an added bonus, this means we don't need the arc/mutex/trait at all! We can just have something like
struct DataChannelCallbacks {
pub open: Box<FnOnce<...>>,
pub on_message: Box<FnMut<...>,
// ...
}
and split out each field when setting callbacks.
This comment has been minimized.
This comment has been minimized.
Manishearth
Jun 2, 2020
Member
We do something similar in regular webrtc, we pass in a "signaller" object at creation.
This comment has been minimized.
This comment has been minimized.
| channel: Sender<Box<dyn WebRtcDataChannelBackend>>, | ||
| ) -> WebRtcResult; | ||
|
|
||
| fn create_data_channel(&mut self, id: &DataChannelId, init: &DataChannelInit) -> WebRtcResult; |
This comment has been minimized.
This comment has been minimized.
| } | ||
| None | ||
| }) | ||
| .map_err(|e| e.to_string())?; | ||
|
|
||
| let callbacks_ = callbacks.clone(); | ||
| let id_ = id.clone(); | ||
| let thread_ = Mutex::new(thread.clone()); |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
Jun 4, 2020
•
Member
@sdroege should the on-message-string , on-open, on-close, and on-error` callbacks require Sync here? I recall we fixed some of these cases earlier: sdroege/gstreamer-rs#154
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
Jun 8, 2020
Member
Yeah sorry this is the Sync requirement that I think needs to be removed upstream. No worries for now
| use std::sync::{Arc, Mutex}; | ||
| use uuid::Uuid; | ||
|
|
||
| lazy_static! { |
This comment has been minimized.
This comment has been minimized.
Manishearth
Jun 4, 2020
Member
I think these ids should just be numbers and individual webrtc implementations should produce and consume them
We shouldn't have a DataChannelBackend trait at all, all of this should be internal to the webrtc impl
| ) { | ||
| match event { | ||
| DataChannelEvent::NewChannel => { | ||
| println!("New channel {:?}", id); |
This comment has been minimized.
This comment has been minimized.
|
this looks good, but I don't think we should have a |
|
@bors-servo r+ |
|
|
|
|
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
WebRTC data channels support - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #26212 This depends on servo/media#350 and contains the basic pieces to make a simple test like https://ferjm.github.io/samples/src/content/datachannel/basic/ work
ferjm commentedMay 31, 2020
This is not entirely spec compliant, but it contains the basic stuff to make data channels work. It allows sending only strings for now.