Skip to content

DEMO: Demonstrates how rtc.io can work with the wrtc package to implement WebRTC data channel communication on a server that communicates with browsers

Notifications You must be signed in to change notification settings

rtc-io/demo-datachannel-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rtc.io serverside datachannel example

This is a simple example that demonstrates how rtc-quickconnect can be used in conjunction with the wrtc package to provide simple, server-side implementations of WebRTC (only datachannels at this stage).

Running the Example

To run this example, first clone the repository and install dependencies:

git clone https://github.com/rtc-io/demo-datachannel-node.git
cd demo-datachannel-node
npm install

Assuming the dependencies have installed correctly (NOTE: it's early days for the wrtc package so not all platforms are supported for the prebuilt binaries), then you should be able to start the server:

npm start

Now open a browser to:

http://localhost:3000/

This will run a demo similar to other quickconnect demos:

var quickconnect = require('rtc-quickconnect');
var qc = quickconnect(location.origin, { room: 'test' });

qc.createDataChannel('chat').on('channel:opened:chat', function(id, dc) {
    console.log('channel opened with peer: ' + id);
});

The difference with this particular demo is that the rtc-switchboard has been configured to monitor when rooms are created on the server, and when they are a "bot" joins the room. The bot code (which runs on the server) looks very similar to the code that runs on the client:

var quickconnect = require('rtc-quickconnect');
var plugins = [
  require('rtc-plugin-node')
];

exports.add = function(room) {
  var qc = quickconnect('http://localhost:3000', { room: room, plugins: plugins });

  qc.createDataChannel('chat').on('channel:opened:chat', function(id, dc) {
    console.log('dc opened with ' + id);
  });
};

Now this isn't a bot that does anything clever, but it could easily be configured to stream logs out to a file or db (as one example). The main thing that this demo is seeking to illustrate is how code can be written for the rtc.io suite of modules that works on the server (thanks to wrtc and rtc-plugin-node packages). As previously stated, this is only for data channels at this stage, but as the wrtc package evolves media streams will be catered for also.

License

This example code is licensed under MIT. Packages used are subject to their own licenses (rtc.io is Apache 2.0).

About

DEMO: Demonstrates how rtc.io can work with the wrtc package to implement WebRTC data channel communication on a server that communicates with browsers

Resources

Stars

Watchers

Forks

Packages

No packages published