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

rxprotoplex-peers

v0.1.3

Published

A reactive peer-to-peer management library built on RxJS and Protoplex for efficient signaling, matchmaking, and multiplexing.

Downloads

848

Readme

rxprotoplex-peers

A robust library for managing WebSocket and WebRTC signaling, socket multiplexing, and peer-to-peer communication. Designed with a reactive architecture leveraging RxJS and Protoplex, rxprotoplex-peers simplifies complex networking scenarios.

Alpha !!!

Testing and implementation of ping-pong (or user-supplied) mechanisms for connection health are still in the works.

Additionally, a dependency has been flagged for potential SSRF vulnerabilities due to the ip package. However, this library does not utilize the problematic feature, and this is not a concern for most use cases.


Table of Contents


Installation

Install this library using your preferred package manager:

npm install rxprotoplex-peers

Usage

WebSocket Network Interfaces

addWebSocketNetworkInterface

Adds a WebSocket network interface for communication.

const nicId = addWebSocketNetworkInterface(url, config);

Parameters:

  • url (string): The WebSocket server URL.
  • config (object): Configuration options for the network interface.

Returns:

  • string: The ID of the created network interface.

closeInterface

Closes a WebSocket network interface and all associated sockets.

closeInterface(interfaceId, error);

Parameters:

  • interfaceId (string | object): The interface ID or object to close.
  • error (Error, optional): Error to propagate during closure.

selectInterfaceByIp$

Observable that emits the interface matching the specified IP.

selectInterfaceByIp$(ip).subscribe(iface => console.log(iface));

Parameters:

  • ip (string): The IP address to search for.

Returns:

  • Observable<object>: Emits the matching interface.

networkInterfaceConnected$

Emits when a network interface is connected and verified.

networkInterfaceConnected$(id).subscribe(iface => console.log('Connected:', iface));

Parameters:

  • id (string): The ID of the network interface.

Returns:

  • Observable<object>: Emits the connected and verified interface.

WebRTC Signaling

webrtcSignalingRelay

Manages WebRTC signaling and ICE candidate relaying.

const signaling = webrtcSignalingRelay(peerManager, socket);

Parameters:

  • peerManager (object): Manages peer connections.
  • socket (object): Associated socket instance.

Returns:

  • object: WebRTC signaling methods as RPC.

Socket Management

connect

Establishes a connection between two interfaces.

connect(localIp, remoteIp);

Parameters:

  • localIp (string): Local interface IP.
  • remoteIp (string): Remote interface IP.

listenOnSocket$

Listens on a specific channel for incoming connections.

listenOnSocket$(ip, channel).subscribe(socket => console.log(socket));

Parameters:

  • ip (string): IP address to listen on.
  • channel (string): Communication channel.

Returns:

  • Observable<object>: Emits incoming socket connections.

connectStream$

Connects to a remote socket over a specific channel.

connectStream$(remoteIp, channel).subscribe(stream => stream.write('Hello'));

Parameters:

  • remoteIp (string): Remote socket IP.
  • channel (string): Communication channel.

Returns:

  • Observable<object>: Emits the connected stream.

closeSocket

Closes a specific socket.

closeSocket(socketId, error);

Parameters:

  • socketId (string | object): Socket ID or object.
  • error (Error, optional): Error to propagate during closure.

closeSocketsOfNetworkInterface

Closes all sockets associated with a specific network interface.

closeSocketsOfNetworkInterface(interfaceId, error);

Parameters:

  • interfaceId (string): Network interface ID.
  • error (Error, optional): Error to propagate during closure.

WebSocket Utilities

webSocketServer

Sets up a WebSocket server for managing connections.

webSocketServer(wss);

Parameters:

  • wss (WebSocketServer): WebSocket server instance.

getWebSocketURL

Generates a WebSocket URL for a server.

const url = getWebSocketURL(wss);

Parameters:

  • wss (WebSocketServer): WebSocket server instance.

Returns:

  • string: WebSocket URL.

Helper Methods

idOf

Retrieves the ID of an entity.

const id = idOf(entity);

Parameters:

  • entity (object): Entity object.

Returns:

  • string: Entity ID.

receiveIce

Processes and applies an ICE candidate.

receiveIce(socketIp, candidate);

Parameters:

  • socketIp (string): Sending socket IP.
  • candidate (object): ICE candidate data.

License

This library is licensed under the MIT License.