npm i --save nativescript-pubnub
- 版本:2.0.3
- GitHub: https://github.com/triniwiz/nativescript-pubnub
- NPM: https://npmjs.net.cn/package/nativescript-pubnub
- 下载
- 昨天:0
- 上周:0
- 上个月:16
nativescript-pubnub
##使用 tns plugin add nativescript-pubnub
##Android
###初始化
使用 TypeScript
import {PubNub} from 'nativescript-pubnub';
使用 JavaScript
var pn = require('nativescript-pubnub');
var pubnub = new pn.PubNub("pubKey","subKey");
使用以下任何一种方法来初始化 PubNub;
new PubNub(pubKey: String, subKey: String);
new PubNub(pubKey: String, subKey: String, enableSSL: Boolean);
new PubNub(pubKey: String, subKey: String, secretKey: String);
new PubNub(pubKey: String, subKey: String, secretKey: String, enableSSL: Boolean);
new PubNub(pubKey: String, subKey: String, secretKey: String, cipherKey: String, enableSSL: Boolean);
new PubNub(pubKey: String, subKey: String, secretKey: String, cipherKey: String, enableSSL: Boolean, iv: String);
###订阅
使用以下任何一种方法来订阅一个或多个频道;
.subscribe(channel): Promise;
.subscribe(channel:String,timetoken:Number): Promise
.subscribe(channel:String, timetoken:String): Promise
.subscribe(channels:String[], timetoken:String): Promise
.subscribe(channels:String[], timetoken:Number): Promise
.subscribe(channels:String[] ): Promise
###发布
使用以下任何一种方法来发布数据;
消息数据:message 参数可以包含任何可序列化的 JSON 数据,包括:对象、数组、整数和字符串。
.publish(channel: String, message: any, storeInHistory: Boolean, metadata:String): Promise;
.publish(channel: String, message: any, storeInHistory: Boolean): Promise;
.publish(channel: String, message: any, metadata): Promise;
.publish(channel: String, message: any): Promise;
###历史记录 使用以下任何一种方法来检索 PubNub 的历史记录;
.history(channel, count): Promise;
.history(channel, reverse): Promise;
.history(channel, start, end): Promise;
.history(channel, count, reverse): Promise;
.history(channel, start, reverse): Promise;
.history(channel, start, count): Promise;
.history(channel, includeTimetoken, count): Promise;
.history(channel, start, count, reverse): Promise;
.history(channel, start, end, count): Promise;
.history(channel, start, end, count, reverse, includeTimetoken): Promise;
.history(channel: String, start: Number, end: Number, count: Number, reverse: Boolean, includeTimetoken: Boolean): Promise;
###取消订阅
.unsubscribe(channels);
.unsubscribe(channels: String)
###Here Now
.hereNow(channel: String, state, disable_uuids): Promise;
.hereNow(state: String, disable_uuids: Boolean): Promise;
.hereNow(channel: String): Promise;
###授权
.pamGrant(channel: String, auth_key: String, read: Boolean, write: Boolean, int: number): Promise;
.pamGrant(channel: String, auth_key: String, read: Boolean, write: Boolean): Promise;
.pamGrant(channel: String, read: Boolean, write: Boolean, int: number): Promise;
.pamGrant(channel: String, read: Boolean, write: Boolean): Promise;
.pamGrant(channel, auth_key, read, write, int): Promise;
###将频道添加到频道组
.channelGroupAddChannel(group: String, channels): Promise;
.channelGroupAddChannel(group: String, channels): Promise;
###Where Now
.whereNow(uuid: String): Promise;
.whereNow(): Promise;
###审计频道组
.pamAuditChannelGroup(group): Promise;
.pamAuditChannelGroup(group, auth_key): Promise;
###频道组授权
.pamGrantChannelGroup(group, auth_key, read, management, ttl): Promise;
.pamGrantChannelGroup(group, auth_key, read, management): Promise;
.pamGrantChannelGroup(group, read, management, ttl): Promise;
.pamGrantChannelGroup(group, read, management): Promise;
###移除频道组
.channelGroupRemoveChannel(group, channels): Promise;
.channelGroupRemoveChannel(group, channel: String): Promise;