From 84c8a9d2d9276669bb107c83a1732872bb286332 Mon Sep 17 00:00:00 2001 From: Daniel Ostrovsky Date: Tue, 1 Jan 2019 11:51:19 +0200 Subject: [PATCH] [pubnub] Added "history" method with following interfaces: HistoryParameters, HistoryMessage, HistoryResponse, HistoryStatus --- types/pubnub/index.d.ts | 41 +++++++++++++++++++++++++++++++++++- types/pubnub/pubnub-tests.ts | 5 +++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 257ca3cd44..c10cd506b9 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -1,6 +1,10 @@ // Type definitions for pubnub 4.0 // Project: https://github.com/pubnub/javascript -// Definitions by: bitbankinc , rollymaduk , vitosamson , FlorianDr +// Definitions by: bitbankinc , +// rollymaduk , +// vitosamson , +// FlorianDr , +// 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; + 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; } diff --git a/types/pubnub/pubnub-tests.ts b/types/pubnub/pubnub-tests.ts index 50660bd942..96dd4202ba 100644 --- a/types/pubnub/pubnub-tests.ts +++ b/types/pubnub/pubnub-tests.ts @@ -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',