- Notifications
You must be signed in to change notification settings - Fork 272
Add c-data-channels example #30
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
Conversation
| Fantastic work @lherman-cs when this lands we got poke some people in Slack right away! I would get rid of the |
c-data-channels/bridge.go Outdated
| "github.com/pion/webrtc/v2" | ||
| ) | ||
| | ||
| /* |
There was a problem hiding this comment.
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.
c-data-channels/data-channels.c Outdated
| | ||
| void on_message(GoDataChannel d, struct GoDataChannelMessage msg) | ||
| { | ||
| printf("%s\n", (char *)msg.data); |
There was a problem hiding this comment.
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))
c-data-channels/data-channels.c Outdated
| { | ||
| while (1) | ||
| { | ||
| GoSendText(d, "hello"); |
There was a problem hiding this comment.
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()
Sean-Der left a comment
There was a problem hiding this 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!
| @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 |
| @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 |
| @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? |
| @lherman-cs oh oops yes you are right, I would do |
| @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) } }) |
| @Sean-Der I've just updated the PR to reflect your comments. |
Sean-Der left a comment
There was a problem hiding this 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 :)
| @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! |
53d52d7 to 99a506d Compare Resolves pion#29
Relates to pion#30
| @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. |
| @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 |
Description
Reference issue
Fixes #29