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

rtc-link

v0.1.21

Published

A library for managing WebRTC connections with multiplexed streams, anti-glare handling, and streamlined data channel setup.

Downloads

240

Readme

rtc-link

A lightweight library for managing WebRTC connections with multiplexed streams, anti-glare handling, and streamlined data channel setup. Useful for setting up signaling, handling offers/answers, and multiplexing over WebRTC data channels.

IN BETA TESTING PHASE

Installation

Install via npm:

npm install rtc-link

Important Notice: WebRTC Testing Segmentation Fault

🚨 Known Issue: Tests involving WebRTC functionality currently result in a segmentation fault (exit code 139) due to an issue in the @roamhq/wrtc library. This affects the establishSignalStream and establishWrtcStream functions in the Node.js testing environment, causing segmentation faults.

Browser Compatibility: This issue only impacts Node.js testing environments using @roamhq/wrtc. In the browser, we use the native WebRTC APIs, which do not encounter this issue and perform as expected.

The maintainers of @roamhq/wrtc are actively working on a fix. Until then, WebRTC-related tests in Node.js may not pass successfully.

Workaround: If your work involves other aspects of the project, you can comment out or skip WebRTC-related tests temporarily.

Thank you for your patience and understanding.


Functions

establishWrtcStream

Creates a WebRTC data channel stream, establishing a peer-to-peer connection with support for multiplexing and anti-glare protection to prevent conflicts if both peers try to initiate.

Usage

import { establishWrtcStream } from 'rtc-link';

const isInitiator = true;
const wrtcStream = establishWrtcStream(isInitiator, stream, { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] });

Parameters

  • isInitiator (boolean): Indicates if this peer initiates the connection.
  • stream (Stream): The transport stream used for WebRTC signaling.
  • config (Object, optional): Configuration for the WebRTC connection.
    • iceServers (Array): ICE servers for NAT traversal, defaulting to Google's public STUN server.

Description

establishWrtcStream configures a WebRTC connection over a given transport stream. The function initiates a data channel for duplex communication and handles offers, answers, and ICE candidate exchanges. Anti-glare protection ensures smooth connection even if both peers attempt to initiate simultaneously. It also regenerates the connection on errors, maintaining a stable communication link.

Example

const wrtcStream = establishWrtcStream(true, myStream, {
    iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
});

establishSignalStream

Establishes a signaling connection between two streams, handling WebRTC signaling messages (offer, answer, and ICE candidates) between the peers.

Usage

import { establishSignalStream } from 'rtc-link';

establishSignalStream(stream1, stream2);

Parameters

  • stream1 (Stream): The first data stream.
  • stream2 (Stream): The second data stream.

Description

establishSignalStream creates a bi-directional signaling pipeline between two data streams using multiplexing. It listens for WebRTC messages on designated channels and forwards each message type to the corresponding channel on the target stream. Additionally, this function closes signaling streams if either stream closes, ensuring reliable connection management.

  • WebRTC Channels:
    • CHANNEL.WEBRTC_OFFER: Handles WebRTC offer messages.
    • CHANNEL.WEBRTC_ANSWER: Handles WebRTC answer messages.
    • CHANNEL.WEBRTC_ICE: Handles ICE candidate messages.

Example

establishSignalStream(stream1, stream2);

Error Handling

Both functions emit any connection errors through the returned data channel, making it easy to track and manage issues.

License

This project is licensed under the MIT License.