
Product
Rust Support Now in Beta
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
webrtc-fullmesh-signaling-server
Advanced tools
A signaling server for a full-mesh WebRTC network - runs in Node.js
npm i -S webrtc-fullmesh-signaling-server
Just require it in your node server entry file (the default port is 2013):
require( 'webrtc-fullmesh-signaling-server' )
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 );
}
}
}
FAQs
A full-mesh signaling server for WebRTC connections.
We found that webrtc-fullmesh-signaling-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.