Git Product home page Git Product logo

tws-tcm's Introduction

Node.js SDK of TWS (Teambition Web Service) cloud messaging service.

NPM version Build Status Downloads

Installation

npm i --save tws-tcm

Usage

'use strict'
const { TCMClient } = require('tws-tcm')

;(async function () {
  const client = new TCMClient({
    host: process.env.TCM_HOST,
    appId: process.env.APP_ID,
    appSecrets: [process.env.APP_SECRET]
  })

  // HTTP
  await client.subscribe('some_topic', 'some_session_id')
  await client.send([{
    to: 'some_topic',
    collapse_key: 'collapse_key',
    time_to_live: 60,
    data: 'data1'
  }, {
    to: 'some_topic',
    collapse_key: 'collapse_key',
    time_to_live: 60,
    data: 'data2'
  }])
})(console.error)

Documentation

const { TCMClient } = require('tws-tcm')

new Client({ appId, appSecret[, host, timeout, cacheStore, rootCert, privateKey, certChain] })

  • appId String : The ID of your TWS application.
  • appSecrets: []String : The secret passwords of your TWS application.
  • host String : Host URL of TCM service.
  • timeout Number : Optional, requst timeout in milliseconds, by default is 3000.
  • rootCert Buffer : Optional, the client root certificate.
  • privateKey Buffer : Optional, the client certificate private key.
  • certChain Buffer : Optional, the client certificate cert chain.
  • maxSockets Number : Optional, the client sockets.
  • time Boolean : Optional, enable timing for request.
  • retryDelay Number : Optional, delay time for retry, default to 200 ms.
  • maxAttempts Number : Optional, max attempts for a request, default to 3 times.
  • retryErrorCodes []String : Optional, error codes that should retry, default to ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH', 'EPIPE', 'EAI_AGAIN'].

TCMClient API

/**
 * Client for TWS (Teambition Web Service) cloud messaging service..
 */
export declare class TCMClient {
    private _client;
    constructor(options: TCMOptions);
    /**
     * subscribe a topic with given sessionId.
     * @param topic message topic.
     * @param sessionId user session ID.
     */
    subscribe(topic: string, sessionId: string): Promise<void>;
    /**
     * unsubscribe a topic with given sessionId.
     * @param topic message topic.
     * @param sessionId user session ID.
     */
    unsubscribe(topic: string, sessionId: string): Promise<void>;
    /**
     * send one or more messages.
     * @param body message array.
     */
    send(body: Message[]): Promise<void>;
    /**
     * get online info for given user.
     * @param userId user ID.
     */
    getUserClients(userId: string): Promise<UserClients>;
    /**
     * get a TCM token for given user.
     * @param userId user ID.
     * @param source client label.
     */
    sign(userId: string, source: string): Promise<Token>;
    /**
     * Just heart beat.
     */
    heartBeat(): Promise<HeartBeat>;
}

License

tws-tcm is licensed under the MIT license. Copyright © 2017-2019 Teambition.

tws-tcm's People

Contributors

davidcai1111 avatar isayme avatar usagiring avatar zensh avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

sensitivemix

tws-tcm's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.