UNPKG

rxprotoplex-peers

Version:

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

25 lines (22 loc) 806 B
import {ID_SYMBOL} from "../constants.js"; import {interfacesEntitiesRef, onStoreReset$, store} from "../store.js"; import {addEntities} from "@ngneat/elf-entities"; import {enableLocalSocketPair} from "../socket/socket.js"; import {take} from "rxjs"; import {connect} from "./web-socket-network-interface.js"; export let lo = undefined; export const enableLocalHostInterface = (config = {}) => { if (lo) return "lo"; const id = `lo`; // Unique identifier for this interface const iface = { [ID_SYMBOL]: id, ip: `127.0.0.1`, rpc: null, }; // Store the interface store.update(addEntities(iface, {ref: interfacesEntitiesRef})); enableLocalSocketPair(); lo = iface; onStoreReset$.pipe(take(1)).subscribe(() => lo = undefined); return "lo"; };