All Projects → jbaudanza → rxremote

jbaudanza / rxremote

Licence: MIT license
Subscribe to RxJs Observables on a remote server through a WebSocket

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to rxremote

Blog
旧书常读出新意,俗见尽弃作雅人!
Stars: ✭ 173 (+540.74%)
Mutual labels:  rxjs
Rxjs Ultimate Cn
RxJS Ultimate 中文版
Stars: ✭ 219 (+711.11%)
Mutual labels:  rxjs
Model
Angular Model - Simple state management with minimalist API, one way data flow, multiple model support and immutable data exposed as RxJS Observable.
Stars: ✭ 242 (+796.3%)
Mutual labels:  rxjs
Mikronode
Mikrotik API for Node
Stars: ✭ 186 (+588.89%)
Mutual labels:  rxjs
Typeless
A complete toolkit for building scalable React apps with Typescript.
Stars: ✭ 215 (+696.3%)
Mutual labels:  rxjs
React Streams
Stars: ✭ 226 (+737.04%)
Mutual labels:  rxjs
Angular Nodejs Mongodb Customersservice
Code for the Integrating Angular with Node.js RESTful Services Pluralsight course.
Stars: ✭ 164 (+507.41%)
Mutual labels:  rxjs
Rxdb
🔄 A client side, offline-first, reactive database for JavaScript Applications
Stars: ✭ 16,670 (+61640.74%)
Mutual labels:  rxjs
Jetlinks Ui Antd
jetlinks community ant design 演示地址:http://demo.jetlinks.cn 账号/密码: test/test123456
Stars: ✭ 213 (+688.89%)
Mutual labels:  rxjs
Stuhome
📱 An iOS client for https://bbs.uestc.edu.cn/ written in react-native, redux and redux-observable.
Stars: ✭ 241 (+792.59%)
Mutual labels:  rxjs
Router Store
Bindings to connect the Angular Router to @ngrx/store
Stars: ✭ 187 (+592.59%)
Mutual labels:  rxjs
Rxjs Course
RxJs In Practice Course - https://angular-university.io/course/rxjs-course
Stars: ✭ 213 (+688.89%)
Mutual labels:  rxjs
Api
Promise and RxJS APIs around Polkadot and any Substrate-based chain RPC calls. It is dynamically generated based on what the Substrate runtime provides in terms of metadata. Full documentation & examples available
Stars: ✭ 232 (+759.26%)
Mutual labels:  rxjs
Rxjs Grpc
Typesafe gRPC with RxJS in TypeScript
Stars: ✭ 184 (+581.48%)
Mutual labels:  rxjs
Angularfire Lite
⚡️ Lightweight library to use Firebase API 🔥 with Angular
Stars: ✭ 245 (+807.41%)
Mutual labels:  rxjs
Ng Projects
🌐 A list of open source Angular Projects
Stars: ✭ 167 (+518.52%)
Mutual labels:  rxjs
Angular Ru Interview Questions
Вопросы на собеседовании по Angular
Stars: ✭ 224 (+729.63%)
Mutual labels:  rxjs
ts-action-operators
TypeScript action operators for NgRx and redux-observable
Stars: ✭ 34 (+25.93%)
Mutual labels:  rxjs
Rxjs Websockets
A very flexible and simple websocket library for rxjs
Stars: ✭ 248 (+818.52%)
Mutual labels:  rxjs
Blog Angular
Angular 笔记
Stars: ✭ 238 (+781.48%)
Mutual labels:  rxjs

RxRemote

RXRemote is a module that allows a client to subscribe to RxJs Observables on a remote server. Clients can be either node or browser instances.

On disconnect, RxRemote will attempt to reconnect and restart observables where they left off.

Installing with NPM

$ npm install rxremote

Why RxRemote?

RxRemote provides functionality that is similar to a WebSocketSubject. However, RxRemote adds the concept of cursors to your Observables. This allows RxRemote to handle reconnections transparently to the client application.

Simple example

server:

import http from 'http';
import ObservablesServer from 'rxremote/observables_server';

const httpServer = http.createServer();
httpServer.listen(5000);

const observablesServer = new ObservablesServer(httpServer, {
  counter() {
    return Rx.Observable.of(1,2,3);
  }
});

client:

import ObservablesClient from 'rxremote/observables_client';

const client = new ObservablesClient('ws://localhost:5000');
const source = client.observable('counter')

const subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 1
// => Next: 2
// => Next: 3
// => Completed

Continuing a subscription after reconnection

Usually when a disconnection event happens, an error will be emitted on all open observables and it will be up to the client application to resubscribe.

You can have the ObservableClient handle this resubscription transparently by structuring your observable to emit objects that look like:

{
  cursor: 1      // Some value that can be used to resume your observable
  value: 'hello' // The main value object that you are observing
}

A cursor can be any number, string or JSON-serializable object that your observable can use to resume where it left off.

For example:

server:

const observablesServer = new ObservablesServer(httpServer, {
  counter(cursor) {
    return Rx.Observable.interval(1000).map(x => ({
      cursor: x,
      value: cursor + x
    }));
  }
});

client:

const client = new ObservablesClient('ws://localhost:5000');
const source = client.observable('counter')

const subscription = source.subscribe(
    function (x) {
        console.log('Next: ' + x);
    },
    function (err) {
        console.log('Error: ' + err);
    },
    function () {
        console.log('Completed');
    });

// => Next: 1
// => Next: 2
// => Next: 3

// -- Network event causes a reconnection

// => Next: 4
// => Next: 5
// => Next: 6

Server API

.logs

This observable emits text strings suitable for sending to a log file

.events

This observable emits an event object when a connection is open or closed. The objects look like:

  {
    type:         'string',          // 'connection-closed' or 'connection-open',
    connectionId: 'number',          // a numberic value that is unique to this connection
    sessionId:    'string',          // a uuid that is generated on the client and reused to call connections
    ipAddress:    'string'           // The IP address of the remote connection
  }

.wss

This is a reference to the internal WebSocketServer.

Client API

.observable(name)

Returns an observable that will marshall subscriptions to the remote server.

.reconnect()

If the client in a disconnected state, this will attempt to reconnect. This does nothing if the client already in a connected or connecting state.

.connected

This is an observable that emits a true boolean value when the client is connected and a false boolean value when the client is disconnected.

.reconnectingAt

If this client is in a disconnected state, this observable will emit a timestamp that represents when the client will try to make a new connection.

.sessionId

This is a UUID that is generated once per instance of the client VM. It will stay the same for each connection that is established. This is useful for generating "presence" lists of connected clients.

Related

If you're building an RxJs based application in node, you might find these other modules handy:

  • rxnotifier - Notification channels backed by redis and/or PostgreSQL
  • rxeventstore - Persist and query your data using the Event Sourcing pattern
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].