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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@d-buckner/peer-pressure

v0.2.0

Published

Simple one-to-one WebRTC video/voice and data channels

Downloads

11

Readme

peer-pressure

Simple WebRTC video/voice and data channels for the browser.

Forked from simple-peer and rewritten in TypeScript with zero runtime dependencies and modern tooling.

Features

  • 79% smaller bundle - 6.1 KB gzipped vs 28.4 KB for simple-peer
  • Zero runtime dependencies - uses browser-native APIs
  • Full TypeScript support - complete type definitions included
  • Modular architecture - signaling, ICE, data-channel, media, stats modules
  • API compatible - drop-in replacement for simple-peer
  • Modern ES2020+ output - optimized for current browsers

Install

npm install @d-buckner/peer-pressure

Usage

import Peer from '@d-buckner/peer-pressure'

const peer1 = new Peer({ initiator: true })
const peer2 = new Peer()

peer1.on('signal', data => peer2.signal(data))
peer2.on('signal', data => peer1.signal(data))

peer1.on('connect', () => {
  peer1.send('hello from peer1')
})

peer2.on('data', data => {
  console.log('received:', data)
})

API

peer = new Peer([opts])

Create a new WebRTC peer connection.

A "data channel" for text/binary communication is always established, because it's cheap and often useful. For video/voice communication, pass the stream option.

If opts is specified, then the default options (shown below) will be overridden.

{
  initiator: false,
  channelConfig: {},
  channelName: '<random string>',
  config: { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:global.stun.twilio.com:3478?transport=udp' }] },
  offerOptions: {},
  answerOptions: {},
  sdpTransform: function (sdp) { return sdp },
  stream: false,
  streams: [],
  trickle: true,
  allowHalfTrickle: false,
  wrtc: {}, // RTCPeerConnection/RTCSessionDescription/RTCIceCandidate
  objectMode: false
}

The options do the following:

  • initiator - set to true if this is the initiating peer

  • channelConfig - custom webrtc data channel configuration (used by createDataChannel)

  • channelName - custom webrtc data channel name

  • config - custom webrtc configuration (used by RTCPeerConnection constructor)

  • offerOptions - custom offer options (used by createOffer method)

  • answerOptions - custom answer options (used by createAnswer method)

  • sdpTransform - function to transform the generated SDP signaling data (for advanced users)

  • stream - if video/voice is desired, pass stream returned from getUserMedia

  • streams - an array of MediaStreams returned from getUserMedia

  • trickle - set to false to disable trickle ICE and get a single 'signal' event (slower)

  • wrtc - custom webrtc implementation, mainly useful in node to specify in the wrtc package. Contains an object with the properties:

  • objectMode - set to true to create the stream in Object Mode. In this mode, incoming string data is not automatically converted to Buffer objects.

peer.signal(data)

Call this method whenever the remote peer emits a peer.on('signal') event.

The data will encapsulate a webrtc offer, answer, or ice candidate. These messages help the peers to eventually establish a direct connection to each other. The contents of these strings are an implementation detail that can be ignored by the user of this module; simply pass the data from 'signal' events to the remote peer and call peer.signal(data) to get connected.

peer.send(data)

Send text/binary data to the remote peer. data can be any of several types: String, Buffer (see buffer), ArrayBufferView (Uint8Array, etc.), ArrayBuffer, or Blob (in browsers that support it).

Note: If this method is called before the peer.on('connect') event has fired, then an exception will be thrown. Use peer.write(data) (which is inherited from the node.js duplex stream interface) if you want this data to be buffered instead.

peer.addStream(stream)

Add a MediaStream to the connection.

peer.removeStream(stream)

Remove a MediaStream from the connection.

peer.addTrack(track, stream)

Add a MediaStreamTrack to the connection. Must also pass the MediaStream you want to attach it to.

peer.removeTrack(track, stream)

Remove a MediaStreamTrack from the connection. Must also pass the MediaStream that it was attached to.

peer.replaceTrack(oldTrack, newTrack, stream)

Replace a MediaStreamTrack with another track. Must also pass the MediaStream that the old track was attached to.

peer.addTransceiver(kind, init)

Add a RTCRtpTransceiver to the connection. Can be used to add transceivers before adding tracks. Automatically called as neccesary by addTrack.

peer.destroy([err])

Destroy and cleanup this peer connection.

If the optional err parameter is passed, then it will be emitted as an 'error' event on the stream.

Peer.WEBRTC_SUPPORT

Detect native WebRTC support in the javascript environment.

import Peer from '@d-buckner/peer-pressure'

if (Peer.WEBRTC_SUPPORT) {
  // webrtc support!
} else {
  // fallback
}

Events

peer.on('signal', data => {})

Fired when the peer has signaling data. You must send this to the remote peer via your signaling channel (e.g., WebSocket server).

peer.on('connect', () => {})

Fired when the peer connection and data channel are ready to use.

peer.on('data', data => {})

Received data from the remote peer. data is a Uint8Array (or String in objectMode).

peer.on('stream', stream => {})

Received a remote media stream.

peer.on('track', (track, stream) => {})

Received a remote media track.

peer.on('close', () => {})

Peer connection closed.

peer.on('error', (err) => {})

Fatal error occurred.