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

webrtc-fullmesh-signaling-server

v1.0.6

Published

A full-mesh signaling server for WebRTC connections.

Downloads

3

Readme

webrtc-fullmesh-signaling-server

A signaling server for a full-mesh WebRTC network - runs in Node.js

Install

npm i -S webrtc-fullmesh-signaling-server

Usage

Just require it in your node server entry file (the default port is 2013):

require( 'webrtc-fullmesh-signaling-server' )

Client Code

The following is an example using the npm package simple-peer:

import SimplePeer from 'simple-peer';

const peers = {};
const uuid = /*myCoolUUIDGeneratorFunction()*/
var socket;

function startup() {
    socket = io.connect( /*SIGNALING_SERVER_ADDRESS*/, {
        transports: ['websocket'],
        reconnection: true,
        reconnectionDelay: 1000,
        reconnectionDelayMax : 5000,
        reconnectionAttempts: 99999
    });

    socket.on( 'connected', (data)=>{
        console.log( 'got "connected" message from signaling server - data:' );
        console.log( data ); // should contain all the uuid's of extant clients

        for( var i = 0; i < data.allClientIds.length; ++i ) {
            var clientId = data.allClientIds[ i ];
            if( clientId===uuid ) {
            	// don't store my own uuid as a peer
                continue;
            }

            var p = peers[clientId] = new SimplePeer({
                initiator: true,
                channelName: 'my_cool_channel_name'
            });

            addPeerListeners( p, clientId );
        }
        
        // send my uuid to the signaling server
        socket.emit( 'uuid', {uuid} );
    });

    socket.on( 'new_peer', (data)=>{
        if( data.newPeerId === uuid ) {
        	// don't do anything if i got my own uuid
            return;
        }

        var p = peers[data.newPeerId] = new SimplePeer({
            initiator: false,
            channelName: 'my_cool_channel_name'
        });

        addPeerListeners( p, data.newPeerId );
    });

    socket.on( 'signal', (data)=>{
        console.log( 'got signal from signaling server:' );
        console.log( data );

        if( peers[data.senderId] ) {
            peers[data.senderId].signal( JSON.stringify(data) );
        }
    });
}

function addPeerListeners( p, peerId ) {
    p.on('error', function (err) { console.error(err); });

    p.on('signal', function (data) {
      data.senderId = uuid;
      data.receiverId = peerId;
      console.log('SIGNAL', JSON.stringify(data));
      socket.emit( 'signal', data );
    });

    p.on('connect', function () {
      console.log('WebRTC connection!');
    });

    p.on('data', function (data) {
      data = JSON.parse( data );
      console.log( 'data: ' );
      console.log( data );
      // do whatever you want with the data now
    });

    p.on( 'close', ()=>{
        delete peers[ peerId ];
    });
}

function sendDataToPeers( data ) {
	// will send the data to every single peer in the network

    for( var peerId in peers ) {
        try {
            peers[peerId].send( JSON.stringify(data) );
        } catch( error ) {
            console.warn( error );
        }
    }
}