Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

peer-lite

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-lite

Lightweight WebRTC browser library that supports video, audio and data channels

  • 2.0.0-alpha.1
  • npm
  • Socket score

Version published
Weekly downloads
191
increased by112.22%
Maintainers
1
Weekly downloads
 
Created
Source

PeerLite

CircleCI

Lightweight WebRTC browser library that supports video, audio and data channels.

Features

  • Lightweight! 7kb in size (< 3kb gzip)
  • Zero dependencies
  • Using modern WebRTC APIs with TypeScript Types
  • "Perfect negotiation" pattern
  • Support for renegotiation of connection
  • ICE candidate batching

Installation

yarn add peer-lite

Usage

Example of two peers connecting to each other locally, see more examples here.

import Peer from 'peer-lite';

const peer1 = new Peer();
const peer2 = new Peer();

peer1.on('signal', async (description) => {
  await peer2.signal(description);
})

peer2.on('signal', async (description) => {
  await peer1.signal(description);
})

peer1.on('onicecandidates', async (candidates) => {
  const promises = candidates.map(async candidate => peer2.addIceCandidate(candidate));
  await Promise.all(promises);
});

peer2.on('onicecandidates', async (candidates) => {
  const promises = candidates.map(async candidate => peer1.addIceCandidate(candidate));
  await Promise.all(promises);
});

peer1.on('streamRemote', (stream) => {
  document.querySelector('#video1').srcObject = stream;
});

peer2.on('streamRemote', (stream) => {
  document.querySelector('#video2').srcObject = stream;
});

(async () => {
  const stream = await Peer.getUserMedia();
  peer1.addStream(stream);
  peer2.addStream(stream);
  peer1.start();
})();

API

Constructor

new Peer(Options)

Options

Typescript Options Definition

export interface PeerOptions {
  batchCandidates?: boolean;
  batchCandidatesTimeout?: number;
  enableDataChannels?: boolean;
  name?: string;
  config?: RTCConfiguration;
  constraints?: MediaStreamConstraints;
  offerOptions?: RTCOfferOptions;
  answerOptions?: RTCAnswerOptions;
  channelName?: string;
  channelOptions?: RTCDataChannelInit;
  sdpTransform?: (sdp: string) => string;
}

Testing

The tests run inside a headless Chrome with Playwright using @playwright/test with Jest. These run quickly and allow testing of real WebRTC APIs in a real browser.

yarn test

Similar Projects

Keywords

FAQs

Package last updated on 22 May 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc