From cd211d24c54a0ba8987b4f66d9783e41ea5c9fd2 Mon Sep 17 00:00:00 2001 From: Divyun Raje Vaid Date: Mon, 18 Nov 2019 20:46:30 +0000 Subject: [PATCH] feat(pubnub): adds listener for message actions (#40437) also adds the reconnect method --- types/pubnub/index.d.ts | 33 +++++++++++++++++++++++++++++---- types/pubnub/pubnub-tests.ts | 20 ++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 355e700b7b..d973ac832a 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -88,6 +88,8 @@ declare class Pubnub { stop(): void; + reconnect(): void; + addListener(params: Pubnub.ListenerParameters): void; removeListener(params: Pubnub.ListenerParameters): void; @@ -301,6 +303,9 @@ declare namespace Pubnub { }; suppressLeaveEvents?: boolean; secretKey?: string; + requestMessageCountThreshold?: number; + autoNetworkDetection?: boolean; + listenToBrowserNetworkEvents?: boolean; } interface MessageEvent { @@ -407,6 +412,17 @@ declare namespace Pubnub { publisher: string; } + interface MessageActionEvent { + channel: string; + publisher: string; + subscription?: string; + timetoken: string; + message: { + event: string; + data: MessageAction; + }; + } + // publish interface PublishParameters { message: any; @@ -446,7 +462,9 @@ declare namespace Pubnub { interface HistoryMessage { entry: any; timetoken?: string | number; - meta?: object; + meta?: { + [key: string]: string; + }; } interface HistoryResponse { @@ -471,7 +489,9 @@ declare namespace Pubnub { [channel: string]: Array<{ message: any; timetoken: string | number; - meta?: object; + meta?: { + [key: string]: any; + }; actions: { [type: string]: { [value: string]: Array<{ @@ -634,6 +654,8 @@ declare namespace Pubnub { space?(spaceEvent: SpaceEvent): void; membership?(membershipEvent: MembershipEvent): void; + + messageAction?(messageActionEvent: MessageActionEvent): void; } // hereNow @@ -710,7 +732,9 @@ declare namespace Pubnub { eTag: string; created: string; updated: string; - custom?: object | null; + custom?: { + [key: string]: string; + } | null; } interface GetObjectsParameters { @@ -920,7 +944,8 @@ declare namespace Pubnub { PNUnknownCategory: string; PNReconnectedCategory: string; PNConnectedCategory: string; - PNRequestMessageCountExceededCategory: string; + PNRequestMessageCountExceedCategory: string; + PNMalformedResponseCategory: string; } interface Operations { diff --git a/types/pubnub/pubnub-tests.ts b/types/pubnub/pubnub-tests.ts index 25886fb720..e050633ac6 100644 --- a/types/pubnub/pubnub-tests.ts +++ b/types/pubnub/pubnub-tests.ts @@ -75,6 +75,26 @@ pubnub.addListener({ data: { userId, spaceId, eTag, created, updated, custom }, }, }) => console.log({ userId, spaceId, eTag, created, updated, custom }), + messageAction: ({ + channel, + publisher, + subscription, + timetoken, + message: { + event, + data: { type, value, uuid, actionTimetoken, messageTimetoken }, + }, + }) => + console.log({ + channel, + publisher, + subscription, + timetoken, + message: { + event, + data: { type, value, uuid, actionTimetoken, messageTimetoken }, + }, + }), }); pubnub.unsubscribe({ channels: ['channel-1'] });