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-pair-socket

v0.1.5

Published

A WebSocket-like api for secure P2P communication.

Downloads

30

Readme

RTC Pair Socket

RtcPairSocket is a lightweight TypeScript class for establishing encrypted peer-to-peer communication between two parties (Alice and Bob) using PeerJS and an encryption layer. This library facilitates encrypted message exchange over WebRTC, with events to handle connection, data, and errors.

Features

  • Secure peer-to-peer communication using WebRTC and PeerJS.
  • Symmetric encryption using a pairing code.
  • Event-based architecture for handling connection, messages, and errors.
  • Minimal dependencies.

Installation

To install the dependencies, run:

npm install

Usage

import RtcPairSocket from './RtcPairSocket';

const pairingCode = 'your-secret-code';
const party = 'alice'; // or 'bob'

const socket = new RtcPairSocket(pairingCode, party);

socket.on('open', () => {
  console.log('Connection opened!');
});

socket.on('message', (data) => {
  console.log('Received message:', data);
});

socket.on('error', (err) => {
  console.error('Error:', err);
});

socket.on('close', () => {
  console.log('Connection closed.');
});

// To send a message
socket.send('Hello, Bob!');

// You can also send structures and they'll be reconstructed on the other side
// (not classes though, basically json plus undefined and Uint8Array)
socket.send([1, 2, 'three']);

Events

  • open: Emitted when the connection is successfully established.
  • message: Emitted when an encrypted message is received.
  • error: Emitted when an error occurs.
  • close: Emitted when the connection is closed.

Methods

  • send(data: unknown): Sends encrypted data to the connected peer.
  • close(): Closes the connection.
  • isClosed(): Returns true if the connection is closed.

How it Works

  • Pairing Code: A shared secret is used as the seed for generating a symmetric encryption key. This ensures that only Alice and Bob can decrypt each other's messages.
  • Peer Connection: Depending on the party (alice or bob), the socket establishes a WebRTC connection to the other party.
  • Encryption: All messages sent over the connection are encrypted using the Cipher class, which encrypts and decrypts data using the shared key.

License

This project is licensed under the MIT License.