npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rtc-stream

v1.0.0

Published

Webrtc P2P through regular NodeJS stream

Downloads

9

Readme

WebRTC Stream

Webrtc P2P through regular NodeJS stream

Client Example

var net = require('net');
var rtcStream = require('rtc-stream');

var socket = net.connect({ host: 'localhost', port: 1337 }, function() {
  socket.setNoDelay(true);
  var rtc = new rtcStream(socket);
  
  rtc.addStun('stun.l.google.com:19302');

  rtc.on('end', function() {
    console.log('Peer closed :(');
  });

  rtc.on('error', function(error) {
    console.log('Peer error:', error.toString());
  });

  rtc.on('open', function() {
    console.log('Peer Connected :)');
  });
  
  rtc.createChannel('echo', function(channel) {
    channel.setEncoding('utf8');
    
    channel.on('data', function(data) {
      console.log(data);
      channel.end();
    });
  
    channel.on('error', function(error) {
      console.log('Channel error:', error.toString());
    });

    channel.on('end', function() {
      console.log('Channel closed :(');
      rtc.end();
    });

    channel.write('HELLO SERVER!\n');
  });
});

Server Example

var net = require('net');
var rtcStream = require('rtc-stream');

var server = net.createServer(function(socket) {
  socket.setNoDelay(true);
  
  var rtc = new rtcStream(socket);

  rtc.addStun('stun.l.google.com:19302');

  rtc.on('end', function() {
    console.log('Peer closed :(');
  });

  rtc.on('error', function(error) {
    console.log('Peer error:', error.toString());
  });

  rtc.on('open', function() {
    console.log('Peer Connected :)');
  });

  rtc.on('channel', function(channel) {
    channel.pipe(process.stdout);
  
    channel.on('error', function(error) {
      console.log('Channel error:', error.toString());
    });

    channel.on('end', function() {
      console.log('Channel closed :(');
      rtc.end();
    });

    channel.write('EHLO FROM SERVER!\n');
  });
  
  socket.on('end', function() {
    console.log('Disconnected...');
  });
});

server.listen({
  host: 'localhost',
  port: 1337,
});

Examples

https://github.com/vmolsa/rtc-stream/tree/master/examples

Prototype

  var rtc = new rtcStream([stream]) // returns Stream object

   rtc.write(data, encoding, callback)
   rtc.end(data, encoding, callback)

   rtc.addStun('url', 'username', 'password')
   rtc.addTurn('url', 'username', 'password')
 
   rtc.useAudio(boolean);
     - enables / disables for receiving audio stream
     - default: disabled
     - on media webrtc connection: enabled

   rtc.useVideo(boolean);
     - enables / disables for receiving video stream
     - default: disabled
     - on media webrtc connection: enabled

   rtc.onChannel('channelName', callback(channel))
   rtc.offChannel('channelName');

   rtc.createMedia([options], [callback(media)])
     - Opens another webrtc stream by using primary webrtc connection for signaling.
     - defaults on media is useAudio(true) and useVideo(true) 
       rest of settings are inherits with primary webrtc stream.
 
   rtc.createChannel(['channelName'], [callback(channel)], [timeout])
     - Opens webrtc datachannel
     - on success 'channel' / callback is called with channel object.
     - on error media / primary webrtc stream 'error' event is called with Error object and 
         callback is called with null.
 
   rtc.createStream([options], [callback(stream)])
     - https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getUserMedia
     - on success 'stream' / callback is called with stream object.
     - on error media / primary webrtc stream 'error' event is called with Error object and 
       callback is called with null.
 
   rtc.addStream(stream)
     - add audio / video stream to webrtc.
     - both ends must have audio or video enabled using useAudio(true) / useVideo(true)

   rtc.removeStream(stream) 
     - removes stream from webrtc connection

   rtc.getLocalStreams()
     - returns array of active audio / video local streams.

   rtc.getRemoteStreams()
     - returns array of active audio / video remote streams.

Events

  'error', callback(error)
  'close', callback()
  'end',   callback()

  'media', callback(media)
  'channel', callback(channel)

Datachannel Prototype

http://nodejs.org/api/stream.html

License

MIT