From 41c06737ee79864e1c79a2819e9a8203b6249558 Mon Sep 17 00:00:00 2001 From: Dang Date: Tue, 31 Oct 2017 18:58:14 +0900 Subject: [PATCH] pubnub type definitions wip --- types/pubnub/index.d.ts | 153 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 143 insertions(+), 10 deletions(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index de99a5a71b..0bbbfe44a0 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -2,36 +2,87 @@ // Project: https://github.com/pubnub/javascript // Definitions by: bitbankinc // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration declare class Pubnub { constructor(config: Pubnub.PubnubConfig); + setAuthKey(authKey: string): void; + + setFilterExpression(filterExpression: string): void; + + getFilterExpression(): string; + publish( - params: {channel: string, message: any}, - callback: (status: any, response: any) => void + params: Pubnub.PublishParameters, + callback: (status: any, response: Pubnub.PublishResponse) => void ): void; - subscribe(params: {channels: string[]}): void; + publish( + params: Pubnub.PublishParameters + ): Promise; - unsubscribe(params: {channels: string[]}): void; + fire( + params: Pubnub.FireParameters, + callback: (status: any, response: Pubnub.PublishResponse) => void + ): void; - addListener(params: { - status?: (statusEvent: Pubnub.StatusEvent) => void; - message?: (data: Pubnub.PubnubData) => void; - presence?: (presenceEvent: any) => void; - }): void; + fire( + params: Pubnub.FireParameters + ): Promise; + + subscribe(params: Pubnub.SubscribeParameters): void; + + unsubscribe(params: Pubnub.UnsubscribeParameters): void; + + unsubscribeAll(): void; + + addListener(params: Pubnub.ListenerParameters): void; + + removeListener(params: Pubnub.ListenerParameters): void; + + hereNow( + params: Pubnub.HereNowParameters, + callback: (status: any, response: Pubnub.HereNowResponse) => void + ): void; + + hereNow( + params: Pubnub.HereNowParameters + ): Promise; + + whereNow( + params: {uuid: string}, + callback: (status: Pubnub.WhereNowStatus, response: Pubnub.WhereNowResponse) => void + ): void; } declare namespace Pubnub { interface PubnubConfig { subscribeKey: string; publishKey?: string; - secretKey?: string; + cipherKey?: string; authKey?: string; + logVerbosity?: boolean; + uuid?: string; ssl?: boolean; + origin?: string; + presenceTimeout?: number; + heartbeatInterval?: number; + restore?: boolean; + keepAlive?: boolean; + keepAliveSettings: { + keepAliveMsecs?: number; + freeSocketKeepAliveTimeout?: number; + timeout?: number; + maxSockets?: number; + maxFreeSockets?: number; + }; + suppressLeaveEvents?: boolean; + secretKey?: string; } interface PubnubData { + actualChannel: string; channel: string; message: any; } @@ -45,6 +96,88 @@ declare namespace Pubnub { lastTimetoken: number | string; currentTimetoken: number | string; } + + // publish + interface PublishParameters { + message: any; + channel: string; + storeInHistory?: boolean; + sendByPost?: boolean; + meta?: any; + ttl?: number; + } + + interface PublishResponse { + timetoken: number; + } + + // fire + interface FireParameters { + message: any; + channel: string; + sendByPost?: boolean; + meta?: any; + } + + // subscribe + interface SubscribeParameters { + channels?: string[]; + channelGroups?: string[]; + withPresence?: boolean; + timetoken?: number; + } + + // unsubscribe + interface UnsubscribeParameters { + channels?: string[]; + channelGroups?: string[]; + } + + // addListener + interface ListenerParameters { + status?: (statusEvent: StatusEvent) => void; + message?: (data: PubnubData) => void; + presence?: (presenceEvent: any) => void; + } + + // hereNow + interface HereNowParameters { + channels?: string[]; + channelGroups?: string[]; + includeUUIDs?: boolean; + includeState?: boolean; + } + + interface HereNowResponse { + totalChannels: number; + totalOccupancy: number; + channels: {[channel: string]: any}; + } + + // whereNow + interface WhereNowStatus { + error: boolean; + operation: string; + statusCode: number; + } + + interface WhereNowResponse { + channels: string[]; + } + + // setState + interface SetStateParameters { + channels?: string[]; + channelGroups?: string[]; + state?: any; + } + + // getState + interface GetStateParameters { + uuid?: string; + channels?: string[]; + channelGroups?: string[]; + } } export default Pubnub;