rxprotoplex
Version:
A utility library for working with Plex-based connections and streams with RxJS operators.
30 lines (29 loc) • 936 B
JavaScript
import {from, map, mergeMap} from "rxjs";
import {catchError} from "rxjs/operators";
/**
* An operator that consumes a Plex stream and maps each data event into an object with metadata.
*
* @constant
* @type {OperatorFunction<Object, Object>}
*
* @param {Object} stream - The Plex stream to be consumed.
* @returns {Observable<Object>} - An Observable that emits objects containing the data,
* stream reference, stream ID, and protocol metadata.
*
* @example
* source$.pipe(consumePlexStream).subscribe(event => {
* console.log("Received data:", event.data);
* console.log("Stream ID:", event.id);
* console.log("Protocol:", event.protocol);
* });
*/
export const consumePlexStream = mergeMap(stream =>
from(stream).pipe(
map(
data => ({data, stream, plex: stream.plex, id: stream.id, protocol: stream.protocol})
),
catchError(e => {
throw e
})
)
);