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

unicast-definition

v3.0.1

Published

Unicast component relying on a peer-sampling protocol

Downloads

3,661

Readme

unicast-definition Build Status

Keywords: Unicast, browser-to-browser communication, WebRTC

Unicast component relying on a n2n component. Similarly to socket.io, this module provides an event-like API to send and receive messages.

Installation

npm install unicast-definition

API

The API is available here.

Usage

// require as you want the N2N module
const S = require('n2n-overlay-wrtc')
// require this module
const U = require('unicast-definition')

// #1 create 3 peers
const s1 = new S({peer: '1', config: {trickle: true}})
const s2 = new S({peer: '2', config: {trickle: true}})
const s3 = new S({peer: '3', config: {trickle: true}})
// #2 associate a unicast protocol to each peer
const u1 = new U(s1, {retry: 1, pid: 'com1'})
const u2 = new U(s2, {retry: 1, pid: 'com1'})
const u3 = new U(s3, {retry: 1, pid: 'com1'})

u1.on('meow', (from, i, am, a, cat) => console.log('@s1 from %s: %s %s %s %s', from, i, am, a, cat))
u2.on('meow', (from, i, am, a, cat) => console.log('@s2 from %s: %s %s %s %s', from, i, am, a, cat))
u3.on('meow', (from, i, am, a, cat) => console.log('@s3 from %s: %s %s %s %s', from, i, am, a, cat))

const u4 = new U(s1, {retry: 1, pid: 'com2'})
const u5 = new U(s2, {retry: 1, pid: 'com2'})
const u6 = new U(s3, {retry: 1, pid: 'com2'})

u4.on(':3', (from, i, is, cat) => console.log('@s1: miaw'))
u5.on(':3', (from, i, is, cat) => console.log('@s2: meow'))
u6.on(':3', (from, i, is, cat) => console.log('@s3: miou'))

// #4 simulate signaling server
const callback = (from, to) => {
  return (offer) => {
    to.connect((answer) => { from.connect(answer) }, offer)
  }
}

// #4 s1 contacts s2, 2-peers network
s1.connection(s2).then(() => {
  console.log('s1 <=> s2.')
  s3.connection(s2).then(() => {
    console.log('s1 <=> s2; s1 -> s3; s3 -> s2'))
    u3.emit('meow', s2.getOutviewId(), 'i', 'am', 'a', 'cat').then(() => {
      u3.emit(':3', s2.getOutviewId(), 'parameters', 'dont', 'matter')).then(() => {
        u6.emit(':3', s2.getOutviewId(), 'parameters', 'dont', 'matter')
      })
    })
  })
})