JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q48890F
  • License MIT

Realtime Cloud Messaging Client (websocket + xhr-streaming fallback)

Package Exports

  • realtime-messaging

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (realtime-messaging) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Realtime Cloud Messaging JavaScript SDK

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.

We have included the source code and licence for the sockjs-client library.

Installation

If you're using Realtime on a web page, you can install the library via:

CDN

<script src="//messaging-public.realtime.co/js/2.1.0/ortc.js"></script>

Usage:

var client = RealtimeMessaging.createClient();
client.setClusterUrl("http://ortc-developers.realtime.co/server/2.1/");
client.connect('YOUR_APPKEY', 'token');

client.onConnected = function(client) {
    console.log("realtime connected");
    client.subscribe("channel", true, function(client, channel, message) {
        console.log("Received message:", message);
    });
}

Bower

bower install realtime

and then

<script src="bower_components/realtime/dist/ortc-min.js"></script>

More about Bower at http://bower.io/

NPM

npm install realtime-messaging --save

and then

import * as RealtimeMessaging from 'realtime-messaging';

const client = RealtimeMessaging.createClient();
client.setClusterUrl("http://ortc-developers.realtime.co/server/2.1/");
client.connect('YOUR_APPKEY', 'token');

client.onConnected = (client) => {
    console.log("realtime connected");
    client.subscribe("channel", true, (client, channel, message) => {
        console.log("Received message:", message);
    });
}

TypeScript usage in Angular4

import {Component, OnInit} from '@angular/core';
import * as Realtime from 'realtime-messaging';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent  {
  
  constructor() {
    const realtime = Realtime.createClient();
    realtime.setClusterUrl("https://ortc-developers.realtime.co/server/ssl/2.1/");
    realtime.connect("YOUR_APPKEY", "SomeSecurityToken");

    realtime.onConnected = (client: Realtime.Client) => {
      console.log("connected");
      
      // subscribe a channel to receive message
      client.subscribe("myChannel", true, this.onMessage);
    } 
  }

  // A new message was received
  onMessage(client: Realtime.Client, channel: string, message: string) {
    console.log("Received message:", message);
  }
}

Quick Start Guide

http://messaging-public.realtime.co/documentation/starting-guide/quickstart-js.html

API Reference

http://messaging-public.realtime.co/documentation/javascript/2.1.0/OrtcClient.html

Authors

Realtime.co