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

v1.2.3

Published

A utility library for working with Plex-based connections and streams with RxJS operators.

Downloads

1,475

Readme

Plex Utilities

This library provides RxJS utilities for working with Plex-based connections and streams, enabling functionalities such as encoding configuration, multiplexing, event handling, and data transmission.

Installation

To install the library, run the following command:

npm install rxprotoplex

Overview of Functions

asPlex

Wraps a given stream in a Protoplex instance if it is not already multiplexed.

const plexStream = asPlex(stream, { someConfig: true });
console.log(plexStream); // Outputs either the original multiplexed stream or a new Protoplex instance

connection$

Creates an RxJS Observable that listens for connection events on a specified Plex instance, optionally filtered by channel ID and protocol. The Observable automatically completes when the Plex instance emits a "close" event.

connection$(plexInstance, "channelId", { protocol: "myProtocol" }).subscribe(connection => {
  console.log("New connection event:", connection);
});

Note: onConnection$ is deprecated. Use connection$ instead.

connectionAndRead$

Creates an RxJS Observable that listens for connection events on a specified Plex instance, filters connections based on channel ID and protocol if specified, consumes the stream data, and completes automatically when the Plex instance emits a "close" event.

connectionAndRead$(plexInstance, "channelId", { protocol: "myProtocol" }).subscribe(event => {
  console.log("Received data:", event.data);
  console.log("Stream ID:", event.id);
  console.log("Protocol:", event.protocol);
});

Note: onConnectionAndRead$ is deprecated. Use connectionAndRead$ instead.

connectAndSend

Establishes a one-time connection to a specified Plex channel, sends data, and then closes the connection.

const sendData = connectAndSend(plexInstance, "channelId", { encoding: "utf-8" });
sendData("Hello, World!");

Note: sendOnce is deprecated. Use connectAndSend instead.

consumePlexStream

An RxJS operator that consumes a Plex stream, transforming each data event into an object containing metadata.

source$.pipe(consumePlexStream).subscribe(event => {
  console.log("Received data:", event.data);
  console.log("Stream ID:", event.id);
  console.log("Protocol:", event.protocol);
});

createPlexPair

Creates a pair of Plex instances using the provided configuration.

const plexPair = createPlexPair({ bits: 256, keyPair: myKeyPair });
console.log("Plex Pair:", plexPair); // Array of two connected Plex instances

listenAndConnection$

Listens for incoming connections on a specified channel and returns an RxJS Observable for connection events.

listenAndConnection$(plexInstance, "channelId", { protocol: "myProtocol" }).subscribe(connection => {
  console.log("New connection:", connection);
});

listenAndConnectionAndRead$

Listens for incoming connections on a specified channel and consumes the connection stream, providing an Observable that emits data from the connections.

listenAndConnectionAndRead$(plexInstance, "channelId", { protocol: "myProtocol" }).subscribe(event => {
  console.log("Received data:", event.data);
  console.log("Stream ID:", event.id);
  console.log("Protocol:", event.protocol);
});

ofChannel

Creates an RxJS operator that filters Plex streams based on a specified channel ID and protocol, logging matching streams.

source$.pipe(ofChannel({ id: "myChannel", protocol: "myProtocol" })).subscribe(filteredStream => {
  console.log("Filtered stream:", filteredStream);
});

tapSend

Creates an RxJS operator that sends data to a specified Plex channel as a side effect and passes the data through.

source$.pipe(tapSend(plexInstance, "myChannel", { encoding: "utf-8" })).subscribe();

withEncoding

Creates a new configuration object with the specified encoding, merging it with an existing Plex configuration.

const config = withEncoding("utf-8", { protocol: "myProtocol" });
console.log(config); // { protocol: "myProtocol", encoding: <resolved utf-8 encoding> }

withHandshake

Merges handshake-related configuration properties into an existing Plex configuration.

const config = withHandshake({ handshake: "init", handshakeEncoding: "utf-8" }, { protocol: "myProtocol" });
console.log(config); // { protocol: "myProtocol", handshake: "init", handshakeEncoding: <resolved utf-8 encoding> }

withPlex

Temporarily sets the current Plex instance for the duration of an asynchronous callback, restoring the previous instance afterward.

await withPlex(newPlexInstance, async () => {
  // Perform actions with newPlexInstance as the current Plex
});

License

This project is licensed under the MIT License. See the LICENSE file for details.