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

reliable-signaler

v1.0.2

Published

Reliable signaling implementation for RTCMultiConnection.js, DataChannel.js and WebRTC Experiments.

Downloads

16

Readme

Reliable Signaler npm downloads

It is a node.js and socket.io based reliable signaling implementation. Remember, reliable doesn't mean "scalable"; reliable simply means that it auto reconnects in any kind of failure or internet disconnect. It is having following features:

  1. Auto reconnects if node.js gets down out of any reason.
  2. Auto reconnects if internet connection disconnects.
  3. It provides custom-signaling for your RTCMultiConnection and DataChannel applications!
npm install reliable-signaler

How it works?

  1. You can store a room-id on server using createNewRoomOnServer method.
  2. You can get that room-id using getRoomFromServer method.

How to use?

  1. In your Node.js server, invoke require('reliable-signaler') and pass HTTP-Server object.
  2. In your HTML file, link this script: /reliable-signaler/signaler.js
  3. In your <script> tag, invoke initReliableSignaler constructor.
  4. Invoke createNewRoomOnServer method for room-moderator.
  5. Invoke getRoomFromServer method from room-participants (multiple participants).

Demos

  • rtcmulticonnection-client: npm downloads
  • datachannel-client: npm downloads
  • videoconferencing-client: npm downloads
# install rtcmulticonnection-client
npm install rtcmulticonnection-client
node ./node_modules/rtcmulticonnection-client/server.js

# or intall datachannel-client
npm install datachannel-client
node ./node_modules/datachannel-client/server.js

# or intall videoconferencing-client
npm install videoconferencing-client
node ./node_modules/videoconferencing-client/server.js

Now open localhost port:8080.

1st Step: Node.js Server-side code

To use it in your node.js code: (required)

var httpServer = require('http').createServer(callback);

require('reliable-signaler')(httpServer || expressServer || portNumber, {
    // for custom socket handlers
    socketCallback: function(socket) {
        socket.on('custom-handler', function(message) {
            socket.broadcast.emit('custom-handler', message);
        });
    }
});

Constructor of the module reliable-signaler takes an config object where you can pass socketCallback and other configurations:

var config = {
    socketCallback: function(socket) {}
};
require('reliable-signaler')(httpServer, config);

*. socketCallback: If you want to attach custom handlers over socket object.

2nd Step: Browser-side code

To use it in the browser: (required)

<script src="/reliable-signaler/signaler.js"></script>

And your client-side javascript code:

var connection = new RTCMultiConnection();

// invoke "initReliableSignaler" and pass "connection" or "channel" object
var signaler = initReliableSignaler(connection, 'http://domain:port/');

Call createNewRoomOnServer method as soon as you'll call open method. You can even call createNewRoomOnServer earlier than open however it isn't suggested:

For RTCMultiConnection:

// for data-only sessions
connection.open();
signaler.createNewRoomOnServer(connection.sessionid);

// or (not recommended)
signaler.createNewRoomOnServer(connection.sessionid, function() {
    connection.open();
});

// or --- recommended.
connection.open({
    onMediaCaptured: function() {
        signaler.createNewRoomOnServer(connection.sessionid);
    }
});

For DataChannel:

channel.open('room-id');
signaler.createNewRoomOnServer('room-id', successCallback);

For participants, call getRoomFromServer method:

// RTCMultiConnection
signaler.getRoomFromServer('sessioin-id', function(roomid) {
    // invoke "join" in callback
    connection.join({
        sessionid: roomid,
        userid: roomid,
        extra: {},
        session: connection.session
    });
    
    // or simply
    connection.join(roomid);
    
    // or
    connection.connect(roomid);
});

// DataChannel
signaler.getRoomFromServer('sessioin-id', function(roomid) {
    channel.join({
        id: roomid,
        owner: roomid
    });
    
    // or
    channel.connect(roomid);
});

Complete Client-Side Example for RTCMultiConnection

<script src="/reliable-signaler/signaler.js"></script>
<script>
var connection = new RTCMultiConnection();

var signaler = initReliableSignaler(connection, '/');

btnOpenRoom.onclick = function() {
    connection.channel = connection.sessionid = connection.userid = sessionid;
    connection.open({
        onMediaCaptured: function() {
            signaler.createNewRoomOnServer(connection.sessionid);
        }
    });
};

btnJoinRoom.onclick = function() {
    signaler.getRoomFromServer(roomid, function(roomid){
        connection.channel = connection.sessionid = roomid;
        connection.join({
            sessionid: roomid,
            userid: roomid,
            extra: {},
            session: connection.session
        });
    });
};
</script>

Complete Client-Side Example for DataChannel

<script src="/reliable-signaler/signaler.js"></script>
<script>
var channel = new DataChannel();

var signaler = initReliableSignaler(channel, '/');

btnOpenRoom.onclick = function() {
    signaler.createNewRoomOnServer(roomid, function() {
        channel.channel = channel.userid = roomid;
        channel.open(roomid);
    });
};

btnJoinRoom.onclick = function() {
    signaler.getRoomFromServer(roomid, function(roomid){
        channel.channel = roomid;
        channel.join({
            id: roomid,
            owner: roomid
        });
    });
};
</script>

API Reference

Constructor takes either RTCMultiConnection instance or a config object:

# 1st option: Pass RTCMultiConnection object
var signaler = initReliableSignaler(connection);

# 2nd option: Pass "config" object
var signaler = initReliableSignaler(connection, '/');

initReliableSignaler global-function exposes/returns 3-objects:

  1. socket
  2. createNewRoomOnServer
  3. getRoomFromServer
// "socket" object
signaler.socket.emit('message', 'hello');

// "createNewRoomOnServer" method
signaler.createNewRoomOnServer(connection.sessionid, successCallback);

// "getRoomFromServer" object
signaler.getRoomFromServer('sessioin-id', callback);

createNewRoomOnServer

This method simply takes sessioin-id and stores in node.js server. You can even pass successCallback.

signaler.createNewRoomOnServer(roomid, successCallback);

getRoomFromServer

This method looks for active sessioin-id in node.js server. Node.js server will fire callback only when session is found.

If session is absent, then node.js server will wait until someone opens that session; and node.js will fire getRoomFromServer-callback as soon a session is opened.

signaler.getRoomFromServer(roomid, successCallback);

License

Reliable-Signaler is released under MIT licence . Copyright (c) Muaz Khan.