Node.js SDK of TWS (Teambition Web Service) cloud messaging service.
npm i --save tws-tcm
'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)
const { TCMClient } = require('tws-tcm')
String
: The ID of your TWS application.[]String
: The secret passwords of your TWS application.String
: Host URL of TCM service.Number
: Optional, requst timeout in milliseconds, by default is 3000
.Buffer
: Optional, the client root certificate.Buffer
: Optional, the client certificate private key.Buffer
: Optional, the client certificate cert chain.Number
: Optional, the client sockets.Boolean
: Optional, enable timing for request.Number
: Optional, delay time for retry, default to 200 ms.Number
: Optional, max attempts for a request, default to 3 times.[]String
: Optional, error codes that should retry, default to ['ECONNRESET', 'ENOTFOUND', 'ESOCKETTIMEDOUT', 'ETIMEDOUT', 'ECONNREFUSED', 'EHOSTUNREACH', 'EPIPE', 'EAI_AGAIN']
./**
* 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>;
}
tws-tcm
is licensed under the MIT license.
Copyright © 2017-2019 Teambition.
Generated using TypeDoc