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

realtime-rxjs

v2.1.2

Published

Realtime Messaging SDK for JavaScript Reactive Extensions (RxJS)

Downloads

3

Readme

Realtime Messaging SDK for JavaScript Reactive Extensions (RxJS)

Part of the The Realtime® Framework, Realtime Cloud Messaging (aka ORTC) is a secure, fast and highly scalable cloud-hosted Pub/Sub real-time message broker for web and mobile apps.

If your application has data that needs to be updated in the user’s interface as it changes (e.g. real-time stock quotes or ever changing social news feed) Realtime Cloud Messaging is the reliable, easy, unbelievably fast, “works everywhere” solution.

Overview

This project provides Reactive Extensions for JavaScript (RxJS) bindings for the Realtime Messaging JavaScript SDK, allowing easy channel subscription as Rx Observables.

This project can be easily used within Angular2 and Ionic2 apps.

Installing with NPM

npm install realtime-rxjs --save

Usage example

import * as RealtimeRx from 'realtime-rxjs';
import { Observable } from 'rxjs/Rx';
...
// Instantiates a new Realtime client connection
const rxConnection = new RealtimeRx.ObservableConnection();

// Sets the connection metadata (optional)
rxConnection.setConnectionMetadata("Realtime RxJs example");

// Establishes the connection to the Realtime server
rxConnection.connect("YOUR_APP_KEY", "token");

// Observe channel and subscribe to receive messages
rxConnection.observeChannel("myChannel")
  .subscribe((message) => {
    console.log("Received message: " + message);
  });
  
// Send a message
rxConnection.send("myChannel", "This is the message ...");

Note that you don't need to manage the connection state yourself (e.g. waiting for the onConnected event before subscribing a channekl) as it's performed internally (subscriptions and sends will be pending until the underlying Realtime connection is ready).

API Reference

connect(appkey: string, token: string): void

Establishes a connection to a Realtime server using the given appkey and security token.

rxConnection.connect("YOUR_APP_KEY", "token");

observeConnection(): Observable<ConnectionEvent>

Returns an Observable of connection events (e.g. onSubscribed, onReconneting, ...).

rxConnection.observeConnection()
	.subscribe((event) => {
      console.log("Realtime connection event:", event);
    });

observeChannel(channel: string): Observable<string>

Returns an Observable for a Realtime channel. Each message received on the channel will emit a next event for each subscribed observer.

rxConnection.observeChannel("myChannel")
  .subscribe((message) => {
    console.log("Received message: " + message);
  });

Note: the underlying Realtime channel unsubscription is performed automatically when there are no more observers subscribing the channel.

observeChannelWithOptions(channel: string, subscriberId?: string, filter?: string, autoUnsubscribe?: boolean): Observable<MessageOptions>

Same as observeChannel but uses other subscription options like buffered messages and filters.

rxConnection.observeChannelWithOptions("myChannel", "mySubscriberId")
	.subscribe((m) => {
    	console.log("Received message: " + m.message);
    	console.log("Message id: " + m.seqId);
    });

The default unsubscribe behaviour is the same as observeChannel (unsubscribe from the channel when there no more active channel observers), but passing autoUnsubscribe = false will not perform unsubscribes at all (useful for buffered subscriptions).

send(channel: string, message: string): void

Sends a message to the given channel using the "at-most-once" delivery contract.

rxConnection.send("myChannel", JSON.stringify({ foo: "bar" }));

publish(channel: string, message: string, ttl: number): Observable<string>

Publishes a message to the given channel using the "at-least-once" delivery contract.

rxConnection.publish("myChannel", JSON.stringify({ foo: "bar" }), 60)
	.subscribe((seqId) => {
    	console.log("Message published with seqId: " + seqId);
    },
    (error) => console.log("Error publishing: " + error));

Note: Don't forget to subscribe to get the publish result otherwise the message publish won't be performed at all.

disconnect(): void

Disconnects from the Realtime server.

rxConnection.disconnect();

Other methods

This project wraps all public methods of the underlying Realtime JavaScript SDK. Complete reference can be found at http://messaging-public.realtime.co/documentation/javascript/2.1.0/OrtcClient.html

Authors

Realtime.co