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

socket.io-peer

v2.2.0

Published

WebRTC data channel communication with a socket.io-like API

Downloads

4

Readme

#Socket.io-Peer

This module provides an easy and reliable way to setup a WebRTC connection between peers and communicate using events (the socket.io-protocol). It is a fork of the socket.io-p2p package.

Socket.IO is used to transport signalling data and as a fallback for clients where WebRTC PeerConnection is not supported.

How to use

Create a socket connection, pass it to Peer. On the Client:

var Peer = require('socket.io-peer');
var io = require('socket.io-client');
var socket = io();

var peer = new Peer(socket);

peer.on('ready', function(){
  peer.usePeerConnection = true;
  peer.emit('peer-obj', { peerId: peerId });
})

// this event will be triggered over the socket transport
// until `usePeerConnection` is set to `true`
peer.on('peer-msg', function(data){
  console.log(data);
});

If you're not using browserify, then use the included standalone file socketiopeer.min.js. This exports a Peer constructor on window.

On the server, use the socket.io-peer-server to take care of signalling. All clients who support WebRTC data connections will exchange signalling data via the default / namespace.

var server = require('http').createServer();
var io = require('socket.io')(server);
var peer = require('socket.io-peer-server').Server;
io.use(peer);
server.listen(3030);

WebRTC Peer connections can also be established by exchanging signalling data within a socket.io room. Do this by calling the peer server within the connection callback:

var server = require('http').createServer();
var io = require('socket.io')(server);
var peer = require('socket.io-peer-server').Server;
server.listen(3030);

io.on('connection', function(socket){
  clients[socket.id] = socket;
  socket.join(roomName);
  peer(socket, null, room);
});

See chat app for full example.

API

peer = new Peer(socket, opts, cb)

Create a new socket.io-peer connection.

The opts object can include options for setup of the overall socket.io-peer connection as well as options for the individual peers - specified using peerOpts.

  • numClients - max number of peers each client can connect to; 5 by default.
  • autoUpgrade - upgrade to a peer connection (from a socket.io one) when peers are ready; true by default
  • peerOpts - object of options to be passed to underlying peers. See here for currently supported options. See here for an example.

cb is an optional callback. Called when connection is upgraded to a WebRTC connection.

peersocket.on('upgrade', function (data) {})

Triggered when Peer connection is converted to a WebRTC one.

peersocket.on('peer-error', function (data) {})

Triggered when a PeerConnection object errors during signalling.

Roadmap of development

  • Support for packets containing multiple binary blobs - packets can only contain one blob in this version
  • Allow a peer to act as a relay between peers that don't support PeerConnection and those that do.

PRs and issue reports are most welcome.