Skip to content

Conversation

@lherman-cs
Copy link
Member

Description

  • Add a c-data-channels example

Reference issue

Fixes #29

@lherman-cs lherman-cs requested a review from Sean-Der November 13, 2019 03:39
@Sean-Der
Copy link
Member

Fantastic work @lherman-cs when this lands we got poke some people in Slack right away!

I would get rid of the jsfiddle folder and just point people to the DataChannel one from pion/webrtc I think that is ok! I think it might help show that this really isn't any different besides the C stuff.

"github.com/pion/webrtc/v2"
)

/*
Copy link
Member

@Sean-Der Sean-Der Nov 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be a lot simpler to just store DataChannels by label in a map in the same file. The goal for me with these examples is to make it do the most possible in the least lines of code. I worry that people will be overwhelmed when it spreads multiple files.


void on_message(GoDataChannel d, struct GoDataChannelMessage msg)
{
printf("%s\n", (char *)msg.data);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep the same format as the other ones fmt.Printf("Message from DataChannel '%s': '%s'\n", d.Label(), string(msg.Data))

{
while (1)
{
GoSendText(d, "hello");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind adding a simple C function to generate a pseudo-random string? Then just doing something like fmt.Printf("Sending '%s'\n", message)

Just put a bunch of acceptable characters in a char charset[] and then pick them out via rand()

Copy link
Member

@Sean-Der Sean-Der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great @lherman-cs. Hopefully you learned a bunch from your adventures with CGo also :)

Few minor changes, I think the overall thing is me just trying to make it as simple as possible. I think we can do multiple channels, but I don't think we need a dedicated struct since it a singleton/simple example!

@lherman-cs
Copy link
Member Author

@Sean-Der I was thinking some people might want to have multiple data channels. So, how about if I create another example? I think this is a very valuable example.

So, in the end, we have c-data-channels and c-multi-data-channels, or something like that?

@Sean-Der
Copy link
Member

@lherman-cs I say we keep this sample multi-channel!

I would still store the DataChannels keyed by label, then you can pass the string (and copy it) in the C code. I think it is easier to follow then doing the ptr lookup

@lherman-cs
Copy link
Member Author

lherman-cs commented Nov 14, 2019

@Sean-Der But, how can we differentiate these data channels if we only have 1 label?

If we had multiple labels, were you thinking of using something like UUID?

@Sean-Der
Copy link
Member

@lherman-cs oh oops yes you are right, I would do streamId that will be unique across all DataChannels

@lherman-cs
Copy link
Member Author

lherman-cs commented Nov 14, 2019

@Sean-Der You mean this guy, https://godoc.org/github.com/pion/webrtc#DataChannel.ID?

Edit: Just found this. So, I'm sure that's the one that you're talking about 😊.

sctp.OnDataChannel(func(d *DataChannel) { pc.mu.RLock() hdlr := pc.onDataChannelHandler pc.dataChannels[*d.ID()] = d pc.dataChannelsAccepted++ pc.mu.RUnlock() if hdlr != nil { hdlr(d)	}	})
@lherman-cs
Copy link
Member Author

@Sean-Der I've just updated the PR to reflect your comments.

Copy link
Member

@Sean-Der Sean-Der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic, LGTM!

I will play with it and if I hit anything will send a PR your way, but I think people are going to love this :)

@Sean-Der
Copy link
Member

@lherman-cs I think you just need to update CI to build the example before running the lint? Not sure, happy to help if you get stuck!

@lherman-cs lherman-cs force-pushed the master branch 5 times, most recently from 53d52d7 to 99a506d Compare November 17, 2019 00:51
@lherman-cs
Copy link
Member Author

lherman-cs commented Nov 17, 2019

@Sean-Der Thanks! Btw, I just changed the travis config to make it work. But, I honestly don't really like it, kinda hacky... So, if you have a better way to do it, please let me know 😊. I tried many options but this one seems to be the best.

@Sean-Der Sean-Der merged commit 9163237 into pion:master Nov 17, 2019
@Sean-Der
Copy link
Member

@lherman-cs merged!

Let me dig into it and see if I can find anything better, but don't want you to burn anymore time! Fantastic work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants