The state of Go and WebRTC (especially RTCDataChannel)

2,983 views
Skip to first unread message

Dmitri Shuralyov

unread,
Mar 9, 2015, 11:26:22 PM3/9/15
to golan...@googlegroups.com
Hi,

Go has pretty good support for WebSockets. There are at least two usable backends packages:


And there's a working, tested wrapper for the WebSocket JavaScript API in the browser:


Combined together, it's possible to establish an effectively-TCP bidirectional connection between Go (or JavaScript) code in the browser and Go code in backend server.

In fact, I've done so recently and I have a working proof of concept here: https://twitter.com/shurcooL/status/574796944264003584

Now, TCP connections are great, but there are situations where you really want a less reliable but more performant UDP transport. Some examples include sending real-time video/audio, or latest player positions, etc.

From what I understand, the WebRTC web API has a RTCDataChannel component that allows establishing a UDP-like connection between peers (peers can be browsers or backend servers). More precisely, it's SCTP, but it's configurable so you can achieve UDP-like qualities. See http://www.html5rocks.com/en/tutorials/webrtc/datachannels/ for more details.

---

Anyway, in my pursuit of being able to achieve more cool things with Go (both in the backend and frontend), I want to be able to use RTCDataChannel to have UDP-like connections between backend and frontend.

On that note, I wanted to inquire on the status of WebRTC/RTCDataChannel and Go. Has anyone done this before? Is anyone interested in this? What are some existing relevant/useful packages, if any? Has anyone tested/used such packages and can vouch they work?

Here are a few things I've found so far, but I haven't had a chance to try these yet:

https://godoc.org/github.com/fd/webrtc - seems to be a cgo-based package that wraps around the C++ library at webrtc.googlecode.com. In the long run I would prefer a pure Go library but cgo is better than nothing. Haven't tried it yet, but this is probably first thing I'll try. Last update 9 months ago.

https://github.com/mehrvarz/rtcchat2 - seems to be some Go code that implements some part of WebRTC. But last update 2 years ago and it imports "code.google.com/p/go.net/websocket" so unsure how easy it'd be to update it to usable state.

https://github.com/coreos/go-webrtc-datachannel - a planning / brainstorming initiative around RTCDataChannel and has coreos in the name, but last update 2 years ago and not seeing final results.

Please share anything that might be helpful here, or if you're also interested in Go + WebRTC. Thanks!

Jason E. Aten

unread,
Mar 11, 2015, 3:00:32 AM3/11/15
to golan...@googlegroups.com
Hi Dmitri,

I'm also interested in Go + WebRTC.

- Jason

Juan Benet

unread,
Mar 11, 2015, 5:57:18 AM3/11/15
to golan...@googlegroups.com
Hey Dmitri,

We -- the authors of IPFS -- are very interested too. I see three paths to making a standalone libdc:

a) extract the relevant code from libwebrtc or openwebrtc and make a static lib.
b) import libsctp, libsrtp, natty (below), + other libs ourselves, and make the wrapping "implementation" in go.
c) implement _everything_ (dtls, sctp, nat traversal, ...) in Go, which may take years.

I suggest (a). Which is what https://github.com/fd/webrtc does, but the status is not promising. We could ask @fd again, and/or contribute.


Other relevant things:

http://www.openwebrtc.io/ -- an effort to make an open source, modular webrtc implementation. DataChannel support merged 8 days ago.

https://github.com/meetecho/janus-gateway -- open source WebRTC gateway in c. creators very interested in standalone datachannels.

- https://github.com/getlantern/natty -- natty is WebRTC based NAT traversal. It does not expose peerdatachannels, but it is an extraction of portions of libwebrtc, and there are go bindings for it: https://github.com/getlantern/go-natty/ from the team at Lantern

https://github.com/webrtcftw -- a lose org (mostly js folk) forming around making an effort to make some of this happen. nothing of note has happened, but worth watching. I want an interop test suite.

https://github.com/jbenet/random-ideas/issues/13 has some thoughts and other people interested in this problem. A few days ago, we saw a posting for librtcdc:

https://github.com/xhs/librtcdc - a standalone c "implementation" of WebRTC DataChannel, using libnice, usrsctp, openssl (dtls). very alpha, but just appeared. bindings for this would be easy to make.

Henry Bubert

unread,
Mar 11, 2015, 6:51:55 AM3/11/15
to golan...@googlegroups.com
Hey Dimitry,

also very interested in webrtc and big fan of your work! The net/rpc through gopherjs demo is really inspiring as well as the web/desktop gl work you do.

To pick up where Juan left of: 

With unbound amounts of help I'd prefer (c) but it also won't help you in the browser (or only partially) since i don't think we will be seeing a native js sctp socket api anytime soon.

To me it seems like (b) might give you a better shot at composing different layers of implementation, like using native browser bindings in js through gopherjs, similar to gopherjs/websocket

(a) might work out similarly to my suggestion (b) but would mean to maintain a lot of code, not reusing community efforts (I think we have seen enough NIH) but each part would have to be vetted and possibly changed to fit, returning you back to (a).

I'm very curious to hear your opinion and see where this goes.


Kind regards,

Henry

Dmitri Shuralyov

unread,
Mar 15, 2015, 8:31:46 PM3/15/15
to golan...@googlegroups.com
Thanks for the replies and useful information everyone! It's great that I'm not the only one who's excited about seeing Go gain wider support for WebRTC and related tech.

I'm looking through all the mentioned resources, playing/learning with things and figuring out the best plan of attack. There are quite a few interesting leads.

I will post updates here as I make progress. But the entirety of WebRTC is a pretty large and complex beast, and given that my spare time is limited, I have to choose and pick what I work on very carefully. So I cannot make promises about my ability to contribute. We'll see - I just don't want to set incorrect expectations.

At the very least, this thread can serve to unite/inform people interested in this space.

anthony...@gmail.com

unread,
Jun 3, 2015, 9:35:39 PM6/3/15
to golan...@googlegroups.com
Hello Dmitri,

I'm very much interested in seeing WebRTC on golang, and would be love to work on anything in this respect... 

Dmitri Shuralyov

unread,
Jun 4, 2015, 5:25:32 AM6/4/15
to golan...@googlegroups.com, anthony...@gmail.com
Hey Anthony,

I haven't had the opportunity to spend time on this since my last update. However, there are quite a few leads posted above (and people also interested), which is great.

IMO, the best lead would be this one:

https://github.com/xhs/librtcdc - a standalone c "implementation" of WebRTC DataChannel, using libnice, usrsctp, openssl (dtls). very alpha, but just appeared. bindings for this would be easy to make.

It seems to have made progress since then, and it sounds like it might be functional. I would suggest trying it out, and if it works, either making bindings or porting it to pure Go. It's less than 2k of C code, should be quite doable.

Another new lead I have (not quite WebRTC but similar functionality) is a proposal for TCP and UDP Sockets in browsers, see:


It's still a WIP proposal, but it appears that Firefox has some initial implementation work, and I was able to send a UDP packet from Firefox developer edition with that feature enabled - https://twitter.com/shurcooL/status/605218976969261056. Learn more about current implementation status at https://github.com/sysapps/tcp-udp-sockets/issues/88.

globali...@gmail.com

unread,
Sep 5, 2016, 7:06:31 PM9/5/16
to golang-nuts
And on pure C how to use your librtcdc?
Reply all
Reply to author
Forward
0 new messages