9

Is it possible to use WebRTC Data Channels on Node.js in a way that mimics the functionality of WebSockets except using UDP?

In essence I want to have a server running Node.js with which browser clients can establish a full duplex bi directional UDP connection via JavaScript.

My question is the same as this one from 8 months ago. I repost it because the only answer was :

Yes, in theory you should be able to to do this. However, you'll need a node module that supports WebRTC data channels, so that you can connect to it like any other peer. Unfortunately, scanning through the current modules, I don't see one that implements the data channel.

Any of you know of such a module ? In my search I found some node modules with the words "webrtc" and "datachannel", but they didn't look like what was needed, they looked like they were meant for specific needs.

Community
  • 1
  • 1
user3147646
  • 131
  • 1
  • 5

2 Answers2

4

This project is very active, and seem to undertake the mission of importing the entire WebRTC stack into node.js There's also this project but it looks pretty inactive.

Would love to know if that was satisfying and if you're doing such a project (as in the question) please link to github :)

shacharz
  • 213
  • 3
  • 8
  • Isn't node-webrtc focused on the peer-to-peer connections though? – Willem Jun 04 '14 at 23:48
  • 1
    @Willem They implement the peer connection, data channel, and stream stacks - It's about everything, maybe they don't do the getUserMedia - which indeed doesn't make much sense in a server. – shacharz Jun 23 '14 at 09:26
  • @ user1674942 I mean, isn't it focused on connecting peers to other peers using UDP rather than connecting the server to several peers using UDP? – Willem Jun 24 '14 at 14:05
  • 1
    @Willem Nope, it treats the server as just another peer, to connect with other peers (browser or node-webrtc servers) over WebRTC. – shacharz Jun 29 '14 at 11:59
  • I thought the server was just needed to set up the peer-to-peer connection between two browsers (because it's not possible for one peer to connect to another without aid because of security issues). But could I use the server as the single entity that ALL other peers are connected to using node-webrtc? I'm trying to accomplish a game using UDP and a server-client model. – Willem Jul 01 '14 at 15:40
  • 2
    A server is needed to establish p2p connection between two browser is correct. But that's always in WebRTC and is not what this project is about. And yes you can do server-client over SCTP over UDP with node-webrtc - That's one of the use-cases it is about. – shacharz Jul 03 '14 at 15:08
  • Server-client over SCTP over UDP is exactly what I'm looking for. Do you know if node-webrtc can handle multiple clients over UDP to the same server with data-channels? Thanks for your thorough responses by the way. – Willem Jul 05 '14 at 12:36
  • Np, +1 my Answer up there :) AFAIK You can open multiple clients to one server, just as you can open multiple clients to one client in WebRTC. You'll need to open a different peerconnection+datachannel for each client-server/client-client communication channel. – shacharz Jul 06 '14 at 15:12
  • I'm the one who did. ;) I hope they have a good API for handling multiple clients. Socket.IO is excellent in that sense but WebRTC.IO is not a mirror of that. Will see what WebRTC can do. – Willem Jul 08 '14 at 09:28
  • That's a good observation, It's out of the scope of node-webrtc to give any abstraction above WebRTC. But indeed many developers seek different abstraction layers. – shacharz Jul 08 '14 at 15:11
4

We have implemented the exact same thing: a server/client way of using WebRTC. Besides we also implemented data port multiplexing, so that server would only need to expose one data port for all rtcdata channels.

A quick summary of how it is achieved:

  • We implemented in nodejs, using wrtc library. But the same principal could be applied to other implementations.
  • The server exposes a control port, so that the client will exchange SDPs with the server for establishing their data channel.
  • To support data port multiplexing, At the server, we modify both peer's SDK, so that
    1. Client will always connect to the same server ip:data_port
    2. We implement a UDP data proxy inside the server, so that it can be the bridge between the server webrtc engine and the client.

The code is at: https://github.com/noia-network/webrtc-direct

Miao ZhiCheng
  • 617
  • 7
  • 9