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

@maca134/rxjs-remote

v1.0.10

Published

Observerables over the network

Downloads

11

Readme

RxJs Remote

This is basically RxJs observable over some kind of network connection. It should work over pretty much any long living connection, i've had it working with socket.io and UDP. Observables get cleanup when things go wrong or something disconnects.

Client files are here https://github.com/maca134/rxjs-remote-client

Install use npm install --save @maca134/rxjs-remote

Quick Start (using Socket.io)

server

// server.ts
import 'reflect-metadata';
import { timer } from 'rxjs';
import * as ioServer from 'socket.io';
import { finalize } from 'rxjs/operators';
import { RxjsRemote, roc } from '@maca134/rxjs-remote';

class SomeClass {
	@roc()
	timer1() {
		console.log('timer1 called');
		return timer(0, 1000).pipe(finalize(() => console.log('timer complete')));
	}

	@roc<ioServer.Socket>({
		// adds the object give in attach as the first params (you may need the socket for something?)
		inject: true, 

		// change the name of the call, in this case the call name is 'SomeClass.notTimer3'
		name: 'notTimer2', 

		// an array of middleware to run before call the method. throw something to prevent the call
		middleware: [ 
			socket => {
				console.log(socket.id);
				// throw new Error('you do not have access here');
			}
		]
	})
	timer2() {
		console.log('timer2 called');
		return timer(0, 1000).pipe(finalize(() => console.log('timer complete')));
	}
}

// new instance with generic as the obj you want to "inject"
const rxjsRemoteServer = new RxjsRemote<ioServer.Socket>(); 

// register some class instances
rxjsRemoteServer.registerClasses([new SomeClass]); 

// socket.io
const io = ioServer(9895);

// when a new connection happens, attach the server to the socket
io.of('roc').on('connection', socket => {
	// connect things together
	rxjsRemoteServer.attach(
		{
			onMessage: listener => socket.on('message', listener),
			onClose: listener => socket.on('disconnect', listener),
			send: data => socket.send(data)
		}, 
		socket // the "inject" obj
	);
});

client

// client.ts
import 'socket.io-client';
import { timer } from 'rxjs';
import { RxjsRemoteClient } from '@maca134/rxjs-remote-client';
import { retryWhen, take, delayWhen, tap } from 'rxjs/operators';

// socket io
const client = io('http://localhost:9895/roc');

// new instance of client
const rxjsRemoteClient = new RxjsRemoteClient({
	onMessage: listener => client.on('message', listener),
	onClose: listener => client.on('disconnect', listener),
	send: data => client.send(data)
});


// do rxjs things
rxjsRemoteClient.observable<number>('SomeClass.timer')
	.pipe(
		take(5),
		retryWhen(err => err.pipe(
			tap(val => console.log(val)),
			delayWhen(val => timer(1000))
		))
	)
	.subscribe(
		next => console.log('next', next),
		error => console.log('error', error),
		() => console.log('complete'),
	);