realtime-messaging
TypeScript icon, indicating that this package has built-in type declarations

2.1.42 • Public • Published

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

Package Sidebar

Install

npm i realtime-messaging

Weekly Downloads

3

Version

2.1.42

License

MIT

Last publish

Collaborators

  • ortc