Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebRTC data channels backend #350

Merged
merged 12 commits into from Jun 9, 2020
Merged

WebRTC data channels backend #350

merged 12 commits into from Jun 9, 2020

Conversation

@ferjm
Copy link
Member

ferjm commented May 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.

@ferjm ferjm requested a review from Manishearth May 31, 2020
.map_err(|e| e.to_string())?;

let channel = InnerDataChannel {
channel: glib::SendWeakRef::from(channel.downgrade()),

This comment has been minimized.

@sdroege

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.

@sdroege

sdroege Jun 1, 2020

Contributor

While at it, you could also hide the signal emission things in functions inside impl DataChannel :)

@ferjm ferjm force-pushed the ferjm:datachannels branch from 97f0670 to 2a8b762 Jun 1, 2020
@ferjm ferjm force-pushed the ferjm:datachannels branch from 2a8b762 to 83b3485 Jun 1, 2020
@ferjm ferjm mentioned this pull request Jun 2, 2020
3 of 3 tasks complete
Copy link
Member

Manishearth left a comment

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!:

trait WebRtcSignaller {
    ....
    fn on_data_channel_event(id: DataChannelId, event: DataChannelEvent);
}

enum DataChannelEvent {
    NewChannel,
    Open,
    Close,
    Error(WebRtcError),
    OnMessage(String),
}

trait WebRtcControllerBackend {
     fn create_data_channel(DataChannelInit) -> DataChannelId;
     fn send_data(id: DataChannelId, msg: String);
}

How does this sound? The signaller/controller distinction exists precisely so that this kind of stuff is easy to do without Arc<Mutex<Callbacks>>. This was quite intentional; I considered quite a few alternative designs when desigining webrtc threading and this seemed to be the most robust. I'd prefer if we use it if at all possible.

}

impl WebRtcDataChannel for GStreamerWebRtcDataChannel {
fn set_on_open(&self, cb: SendBoxFnOnce<'static, ()>) {

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@Manishearth

Manishearth Jun 2, 2020

Member

send() can be called by the controller instead

@ferjm ferjm force-pushed the ferjm:datachannels branch from aef4806 to 31b217d Jun 4, 2020
channel: Sender<Box<dyn WebRtcDataChannelBackend>>,
) -> WebRtcResult;

fn create_data_channel(&mut self, id: &DataChannelId, init: &DataChannelInit) -> WebRtcResult;

This comment has been minimized.

@Manishearth

Manishearth Jun 4, 2020

Member

the controller probably can manage ids itself and return an id here.

}
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.

@Manishearth

Manishearth Jun 4, 2020

Member

the outer mutex doesn't seem necessary?

This comment has been minimized.

@Manishearth

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.

@ferjm

ferjm Jun 8, 2020

Author Member

rustc complains if I don't add the outer mutex

This comment has been minimized.

@Manishearth

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.

@Manishearth

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.

@Manishearth

Manishearth Jun 4, 2020

Member

probably should be removed or turned into debug!()

Copy link
Member

Manishearth left a comment

this looks good, but I don't think we should have a DataChannel trait at all, webrtc implementations should deal with that internally and just surface ids for referring to them

@Manishearth
Copy link
Member

Manishearth commented Jun 9, 2020

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2020

📌 Commit 512c76f has been approved by Manishearth

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2020

Testing commit 512c76f with merge 64e4507...

@bors-servo
Copy link
Contributor

bors-servo commented Jun 9, 2020

☀️ Test successful - checks-travis
Approved by: Manishearth
Pushing 64e4507 to master...

@bors-servo bors-servo merged commit 64e4507 into servo:master Jun 9, 2020
3 checks passed
3 checks passed
Travis CI - Pull Request Build Passed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
homu Test successful
Details
@ferjm ferjm deleted the ferjm:datachannels branch Jun 10, 2020
bors-servo added a commit to servo/servo that referenced this pull request Jun 12, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 16, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 16, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 17, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
bors-servo added a commit to servo/servo that referenced this pull request Jun 30, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.