Merge pull request #31820 from danduh/master

[pubnub] Added "history" method with required interfaces
This commit is contained in:
Sheetal Nandi
2019-01-02 11:55:16 -08:00
committed by GitHub
2 changed files with 45 additions and 1 deletions
+40 -1
View File
@@ -1,6 +1,10 @@
// Type definitions for pubnub 4.0
// Project: https://github.com/pubnub/javascript
// Definitions by: bitbankinc <https://github.com/bitbankinc>, rollymaduk <https://github.com/rollymaduk>, vitosamson <https://github.com/vitosamson>, FlorianDr <https://github.com/FlorianDr>
// Definitions by: bitbankinc <https://github.com/bitbankinc>,
// rollymaduk <https://github.com/rollymaduk>,
// vitosamson <https://github.com/vitosamson>,
// FlorianDr <https://github.com/FlorianDr>,
// danduh <https://github.com/danduh>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration
// TypeScript Version: 2.2
@@ -42,6 +46,11 @@ declare class Pubnub {
params: Pubnub.FireParameters
): Promise<Pubnub.PublishResponse>;
history(
params: Pubnub.HistoryParameters,
callback: (status: Pubnub.HistoryStatus, response: Pubnub.HistoryResponse) => void
): void;
subscribe(params: Pubnub.SubscribeParameters): void;
unsubscribe(params: Pubnub.UnsubscribeParameters): void;
@@ -193,6 +202,34 @@ declare namespace Pubnub {
timetoken: number;
}
interface HistoryParameters {
channel: string;
count: number;
stringifiedTimeToken?: boolean;
includeTimetoken?: boolean;
reverse?: boolean;
start?: number; // timetoken
end?: number; // timetoken
}
interface HistoryMessage {
entry: any;
timetoken?: string | number;
}
interface HistoryResponse {
endTimeToken?: number;
startTimeToken?: number;
messages: HistoryMessage[];
}
interface HistoryStatus {
error: boolean;
errorData?: Error;
operation: string; // see Pubnub.Operations
statusCode?: number;
}
interface PublishStatus {
operation: string; // see Pubnub.Operations
category: string; // see Pubnub.Categories;
@@ -225,7 +262,9 @@ declare namespace Pubnub {
// addListener
interface ListenerParameters {
status?(statusEvent: StatusEvent): void;
message?(messageEvent: MessageEvent): void;
presence?(presenceEvent: PresenceEvent): void;
}
+5
View File
@@ -87,6 +87,11 @@ pubnub.setState({ channels: [] }).then(res => {
console.log(res.state);
});
pubnub.history({channel: 'channel-1', count: 2}, (status, res) => {
console.log(status);
console.log(res);
});
const cryptoOptions = {
encryptKey: true,
keyEncoding: 'utf8',