项目作者: realtime-framework

项目描述 :
Realtime Cloud Messaging JavaScript SDK
高级语言: JavaScript
项目地址: git://github.com/realtime-framework/RealtimeMessaging-Javascript.git
创建时间: 2016-08-17T11:24:30Z
项目社区:https://github.com/realtime-framework/RealtimeMessaging-Javascript

开源协议:MIT License

下载


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

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

Usage:

  1. var client = RealtimeMessaging.createClient();
  2. client.setClusterUrl("http://ortc-developers.realtime.co/server/2.1/");
  3. client.connect('YOUR_APPKEY', 'token');
  4. client.onConnected = function(client) {
  5. console.log("realtime connected");
  6. client.subscribe("channel", true, function(client, channel, message) {
  7. console.log("Received message:", message);
  8. });
  9. }

Bower

  1. bower install realtime

and then

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

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

NPM

  1. npm install realtime-messaging --save

and then

  1. import * as RealtimeMessaging from 'realtime-messaging';
  2. const client = RealtimeMessaging.createClient();
  3. client.setClusterUrl("http://ortc-developers.realtime.co/server/2.1/");
  4. client.connect('YOUR_APPKEY', 'token');
  5. client.onConnected = (client) => {
  6. console.log("realtime connected");
  7. client.subscribe("channel", true, (client, channel, message) => {
  8. console.log("Received message:", message);
  9. });
  10. }

TypeScript usage in Angular4

  1. import {Component, OnInit} from '@angular/core';
  2. import * as Realtime from 'realtime-messaging';
  3. @Component({
  4. selector: 'app-root',
  5. templateUrl: './app.component.html',
  6. styleUrls: ['./app.component.css']
  7. })
  8. export class AppComponent {
  9. constructor() {
  10. const realtime = Realtime.createClient();
  11. realtime.setClusterUrl("https://ortc-developers.realtime.co/server/ssl/2.1/");
  12. realtime.connect("YOUR_APPKEY", "SomeSecurityToken");
  13. realtime.onConnected = (client: Realtime.Client) => {
  14. console.log("connected");
  15. // subscribe a channel to receive message
  16. client.subscribe("myChannel", true, this.onMessage);
  17. }
  18. }
  19. // A new message was received
  20. onMessage(client: Realtime.Client, channel: string, message: string) {
  21. console.log("Received message:", message);
  22. }
  23. }

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