From 6afa523842bef234a4bcd8fc2e9d297fa0b8170e Mon Sep 17 00:00:00 2001 From: Rami Jarrar Date: Fri, 23 Dec 2022 17:28:01 +0400 Subject: [PATCH] Add typescript declaration file Resolves #105 --- index.d.ts | 1047 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 1048 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..9155663 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,1047 @@ +declare module 'react-native-voximplant' { + import React from 'react'; + import { ViewProps } from 'react-native'; + + namespace Voximplant { + export function getInstance(clientConfig?: ClientConfig): Client; + export function getMessenger(): Messaging.Messenger; + + export class Client { + public setLoggerCallback(callback: () => void): void; + + public on( + event: K, + handler: (event: ClientHandlerEvents[K]) => void, + ): void; + + public off( + event: K, + handler?: (event: ClientHandlerEvents[K]) => void, + ): void; + + public connect( + options?: ConnectOptions, + ): Promise; + + public disconnect(): Promise; + + public getClientState(): Promise; + + public login( + username: string, + password: string, + ): Promise; + + public loginWithOneTimeKey( + username: string, + hash: string, + ): Promise; + + public loginWithToken( + username: string, + token: string, + ): Promise; + + public requestOneTimeLoginKey( + username: string, + ): Promise; + + public tokenRefresh( + username: string, + refreshToken: string, + ): Promise; + + public registerPushNotificationsToken(token: string): void; + + public registerIMPushNotificationsTokenIOS(token: string): void; + + public unregisterPushNotificationsToken(token: string): void; + + public unregisterIMPushNotificationsTokenIOS(token: string): void; + + public handlePushNotification(notification: object): void; + + public call(number: string, callSettings?: CallSettings): Promise; + + public callConference( + number: string, + callSettings?: CallSettings, + ): Promise; + } + + export class Call { + public callId: string; + public localVideoStreams: VideoStream[]; + public callKitUUID?: string | null; + public qualityIssues: QualitySubscriber; + + public on( + event: K, + handler: (event: CallHandlerEvents[K]) => void, + ): void; + + public off( + event: K, + handler?: (event: CallHandlerEvents[K]) => void, + ): void; + + public answer(callSettings?: CallSettings): void; + + public decline(headers?: object): void; + + public reject(headers?: object): void; + + public sendAudio(enable: boolean): void; + + public sendTone(key: string): void; + + public sendVideo( + enable: boolean, + ): Promise; + + public hold(enable: boolean): Promise; + + public receiveVideo(): Promise; + + public hangup(headers?: object): void; + + public sendMessage(message: string): void; + + public sendInfo( + mimeType: string, + body: string, + extraHeaders?: object, + ): void; + + public getEndpoints(): Endpoint[]; + + public getDuration(): Promise; + + public currentQualityIssues(): Promise<{[key in QualityEvents]?: QualityIssueLevel} | CallError>; + } + export class QualitySubscriber { + public on( + event: K, + handler: (event: QualityHandlerEvents[K]) => void, + ): void; + + public off( + event: K, + handler?: (event: QualityHandlerEvents[K]) => void, + ): void; + } + + export enum CallEvents { + Connected = 'Connected', + Disconnected = 'Disconnected', + EndpointAdded = 'EndpointAdded', + Failed = 'Failed', + ICECompleted = 'ICECompleted', + ICETimeout = 'ICETimeout', + InfoReceived = 'InfoReceived', + LocalVideoStreamAdded = 'LocalVideoStreamAdded', + LocalVideoStreamRemoved = 'LocalVideoStreamRemoved', + MessageReceived = 'MessageReceived', + ProgressToneStart = 'ProgressToneStart', + ProgressToneStop = 'ProgressToneStop', + CallReconnecting = 'CallReconnecting', + CallReconnected = 'CallReconnected', + } + export interface CallHandlerEvents { + [CallEvents.Connected]: CallHeadersEvent; + [CallEvents.Disconnected]: CallDisconnectedEvent; + [CallEvents.EndpointAdded]: CallEndpointAddedEvent; + [CallEvents.Failed]: CallFailedEvent; + [CallEvents.ICECompleted]: CallDefaultEvent; + [CallEvents.ICETimeout]: CallDefaultEvent; + [CallEvents.InfoReceived]: CallInfoReceivedEvent; + [CallEvents.LocalVideoStreamAdded]: CallLocalVideoStreamEvent; + [CallEvents.LocalVideoStreamRemoved]: CallLocalVideoStreamEvent; + [CallEvents.MessageReceived]: CallMessageReceivedEvent; + [CallEvents.ProgressToneStart]: CallHeadersEvent; + [CallEvents.ProgressToneStop]: CallDefaultEvent; + [CallEvents.CallReconnecting]: CallDefaultEvent; + [CallEvents.CallReconnected]: CallDefaultEvent; + } + // -- Event Handlers + // Call Event + export interface CallDefaultEvent { + name: + | CallEvents.CallReconnected + | CallEvents.CallReconnecting + | CallEvents.ICECompleted + | CallEvents.ICETimeout + | CallEvents.ProgressToneStop; + call: Call; + } + // Call Event With Headers + export interface CallHeadersEvent { + name: CallEvents.Connected | CallEvents.ProgressToneStart; + call: Call; + headers?: object; + } + // Disconnected + export interface CallDisconnectedEvent { + name: CallEvents.Disconnected; + call: Call; + headers?: object; + answeredElsewhere: boolean; + } + // Failed + export interface CallFailedEvent { + name: CallEvents.Failed; + call: Call; + headers?: object; + code: number; + reason: string; + } + // Info Received + export interface CallInfoReceivedEvent { + name: CallEvents.InfoReceived; + call: Call; + headers?: object; + mimeType: string; + body: string; + } + // Message Received + export interface CallMessageReceivedEvent { + name: CallEvents.MessageReceived; + call: Call; + text: string; + } + // Local Video Stream Added, Local Video Stream Removed + export interface CallLocalVideoStreamEvent { + name: + | CallEvents.LocalVideoStreamAdded + | CallEvents.LocalVideoStreamRemoved; + call: Call; + videoStream: VideoStream; + } + // Call Operation Failed + export interface CallOperationFailedEvent { + name: string; + code: CallError; + message: string; + } + + export class Endpoint { + public id: string; + public displayName: string; + public sipUri: string; + public userName: string; + public videoStreams: VideoStream[]; + + public on( + eventType: K, + handler: (event: EndpointHandlerEvents[K]) => void, + ): void; + + public off( + eventType?: K, + handler?: (event: EndpointHandlerEvents[K]) => void, + ): void; + + public requestVideoSize( + streamId: string, + width: number, + height: number, + ): Promise; + + public startReceiving( + streamId: string, + ): Promise; + + public stopReceiving( + streamId: string, + ): Promise; + } + + export class VideoStream { + public id: string; + public isLocal: boolean; + public type: VideoStreamType; + } + + export class VideoView extends React.Component {} + export interface VideoViewProps extends ViewProps { + scaleType?: RenderScaleType; + videoStreamId?: string; + showOnTop?: boolean; + } + + export enum EndpointEvents { + InfoUpdated = 'InfoUpdated', + RemoteVideoStreamAdded = 'RemoteVideoStreamAdded', + RemoteVideoStreamRemoved = 'RemoteVideoStreamRemoved', + Removed = 'Removed', + VoiceActivityStarted = 'VoiceActivityStarted', + VoiceActivityStopped = 'VoiceActivityStopped', + } + export interface EndpointHandlerEvents { + [EndpointEvents.InfoUpdated]: EndpointDefaultEvent; + [EndpointEvents.RemoteVideoStreamAdded]: EndpointVideoStreamEvent; + [EndpointEvents.RemoteVideoStreamRemoved]: EndpointVideoStreamEvent; + [EndpointEvents.Removed]: EndpointDefaultEvent; + [EndpointEvents.VoiceActivityStarted]: EndpointDefaultEvent; + [EndpointEvents.VoiceActivityStopped]: EndpointDefaultEvent; + } + // -- Event Handlers + // Endpoint Added + export interface CallEndpointAddedEvent { + name: CallEvents.EndpointAdded; + call: Call; + endpoint: Endpoint; + } + // Info Updated, Removed + export interface EndpointDefaultEvent { + name: + | EndpointEvents.InfoUpdated + | EndpointEvents.Removed + | EndpointEvents.VoiceActivityStarted + | EndpointEvents.VoiceActivityStopped; + call: Call; + endpoint: Endpoint; + } + // Remote Video Stream Added, Remote Video Stream Removed + export interface EndpointVideoStreamEvent { + name: + | EndpointEvents.RemoteVideoStreamAdded + | EndpointEvents.RemoteVideoStreamRemoved; + call: Call; + endpoint: Endpoint; + videoStream: VideoStream; + } + + export enum ClientEvents { + ConnectionEstablished = 'ConnectionEstablished', + ConnectionFailed = 'ConnectionFailed', + ConnectionClosed = 'ConnectionClosed', + AuthResult = 'AuthResult', + RefreshTokenResult = 'RefreshTokenResult', + IncomingCall = 'IncomingCall', + Reconnecting = 'Reconnecting', + Reconnected = 'Reconnected', + } + export interface ClientHandlerEvents { + [ClientEvents.ConnectionEstablished]: ClientConnectionEvent; + [ClientEvents.ConnectionFailed]: ClientConnectionFailedEvent; + [ClientEvents.ConnectionClosed]: ClientConnectionEvent; + [ClientEvents.AuthResult]: ClientAuthResultEvent; + [ClientEvents.RefreshTokenResult]: ClientRefreshTokenResultEvent; + [ClientEvents.IncomingCall]: ClientIncomingCallEvent; + [ClientEvents.Reconnecting]: ClientConnectionEvent; + [ClientEvents.Reconnected]: ClientConnectionEvent; + } + // -- Event Handlers + // Auth Result + export interface ClientAuthResultEvent { + name: ClientEvents.AuthResult; + result: boolean; + code: number; + displayName: string; + key: string; + tokens: LoginTokens; + } + // Auth Token Result + export interface ClientRefreshTokenResultEvent { + name: ClientEvents.RefreshTokenResult; + result: boolean; + code: number; + tokens: LoginTokens; + } + // Connection Failed + export interface ClientConnectionFailedEvent { + name: ClientEvents.ConnectionFailed; + message: string; + } + // Connection Established, Connection Closed, Reconnecting, Reconnected + export interface ClientConnectionEvent { + name: + | ClientEvents.ConnectionClosed + | ClientEvents.ConnectionEstablished + | ClientEvents.Reconnected + | ClientEvents.Reconnecting; + } + // Incoming Call + export interface ClientIncomingCallEvent { + name: ClientEvents.IncomingCall; + call: Call; + headers?: object; + video: boolean; + } + + export enum ClientState { + DISCONNECTED = 'disconnected', + CONNECTING = 'connecting', + CONNECTED = 'connected', + LOGGING_IN = 'logging_in', + LOGGED_IN = 'logged_in', + RECONNECTING = 'reconnecting', + } + + export enum CameraType { + FRONT = 'front', + BACK = 'back', + } + + export enum RenderScaleType { + SCALE_FILL = 'fill', + SCALE_FIT = 'fit', + } + + export enum CallError { + ALREADY_IN_THIS_STATE = 'ALREADY_IN_THIS_STATE', + FUNCTIONALITY_IS_DISABLED = 'FUNCTIONALITY_IS_DISABLED', + INCORRECT_OPERATION = 'INCORRECT_OPERATION', + INTERNAL_ERROR = 'INTERNAL_ERROR', + MEDIA_IS_ON_HOLD = 'MEDIA_IS_ON_HOLD', + MISSING_PERMISSION = 'MISSING_PERMISSION', + NOT_LOGGED_IN = 'NOT_LOGGED_IN', + REJECTED = 'REJECTED', + TIMEOUT = 'TIMEOUT', + RECONNECTING = 'RECONNECTING', + } + + export enum LogLevel { + ERROR = 'error', + WARNING = 'warning', + INFO = 'info', + DEBUG = 'debug', + VERBOSE = 'verbose', + } + + export enum VideoCodec { + VP8 = 'VP8', + H264 = 'H264', + AUTO = 'AUTO', + } + + export enum RequestAudioFocusMode { + REQUEST_ON_CALL_START = 'REQUEST_ON_CALL_START', + REQUEST_ON_CALL_CONNECTED = 'REQUEST_ON_CALL_CONNECTED', + } + + export enum VideoStreamType { + VIDEO = 'Video', + SCREEN_SHARING = 'ScreenSharing', + } + + export enum QualityEvents { + PacketLoss = 'PacketLoss', + CodecMismatch = 'CodecMismatch', + LocalVideoDegradation = 'LocalVideoDegradation', + IceDisconnected = 'IceDisconnected', + HighMediaLatency = 'HighMediaLatency', + NoAudioSignal = 'NoAudioSignal', + NoAudioReceive = 'NoAudioReceive', + NoVideoReceive = 'NoVideoReceive', + } + export interface QualityHandlerEvents { + [QualityEvents.PacketLoss]: QualityPacketLossEvent, + [QualityEvents.CodecMismatch]: QualityCodecMismatchEvent, + [QualityEvents.LocalVideoDegradation]: QualityLocalVideoDegradationEvent, + [QualityEvents.IceDisconnected]: QualityDefaultEvent, + [QualityEvents.HighMediaLatency]: QualityHighMediaLatencyEvent, + [QualityEvents.NoAudioSignal]: QualityDefaultEvent, + [QualityEvents.NoAudioReceive]: QualityNoReceiveEvent, + [QualityEvents.NoVideoReceive]: QualityNoReceiveEvent, + } + // -- Event Handlers + export interface QualityEvent { + callId: string, + issueLevel: QualityIssueLevel, + } + // Packet Loss Event + export interface QualityPacketLossEvent extends QualityEvent { + name: QualityEvents.PacketLoss, + packetLoss: number, + } + // Codec Mismatch Event + export interface QualityCodecMismatchEvent extends QualityEvent{ + name: QualityEvents.CodecMismatch, + codec: string | null, + } + // Local Video Degradation Event + export interface QualityLocalVideoDegradationEvent extends QualityEvent { + name: QualityEvents.LocalVideoDegradation, + actualSize: object, + targetSize: object, + } + // Ice Disconnected Event, No Audio Signal Event + export interface QualityDefaultEvent extends QualityEvent { + name: QualityEvents.IceDisconnected | QualityEvents.NoAudioSignal, + } + // High Media Latency Event + export interface QualityHighMediaLatencyEvent extends QualityEvent { + name: QualityEvents.HighMediaLatency, + latency: number, + } + // No Audio Receive Event, No Video Receive Event + export interface QualityNoReceiveEvent extends QualityEvent { + name: QualityEvents.NoAudioReceive | QualityEvents.NoVideoReceive, + audioStreamId: string, + endpointId: string, + } + + // -- Structures + // Client Config + export interface ClientConfig { + enableVideo?: boolean; + enableCameraMirroring?: boolean; + enableLogcatLogging?: boolean; + preferredVideoCodec?: VideoCodec, + enableDebugLogging?: boolean; + logLevel?: LogLevel; + bundleId?: string | null; + requestAudioFocusMode?: boolean, + h264RecoveryMode?: boolean; + forceRelayTraffic?: boolean; + } + // Connect Options + export interface ConnectOptions { + connectivityCheck?: boolean; + servers?: string[]; + } + // Login Tokens + export interface LoginTokens { + accessExpire: number; + accessToken: string; + refreshExpire: number; + refreshToken: string; + } + // Video Flags + export interface VideoFlags { + receiveVideo?: boolean; + sendVideo?: boolean; + } + // Call Settings + export interface CallSettings { + preferredVideoCodec?: VideoCodec; + customData?: string | null; + extraHeaders?: { [key: string]: string } | null; + video: VideoFlags; + setupCallKit?: boolean; + enableSimulcast?: boolean; + } + + // -- Enums + // Quality Issue Level + export enum QualityIssueLevel { + NONE = "None", + MINOR = "Minor", + MAJOR = "Major", + CRITICAL = "Critical" + } + } + + namespace Voximplant.Hardware { + export class AudioDeviceManager { + public static getInstance(): AudioDeviceManager; + + public on( + event: K, + handler: (event: AudioDeviceHandlerEvents[K]) => void, + ): void; + + public off( + event: K, + handler?: (event: AudioDeviceHandlerEvents[K]) => void, + ): void; + + public getActiveDevice(): Promise; + + public getAudioDevices(): Promise; + + public selectAudioDevice(audioDevice: AudioDevice): void; + + public callKitConfigureAudioSession(): void; + + public callKitReleaseAudioSession(): void; + + public callKitStartAudio(): void; + + public callKitStopAudio(): void; + } + + export enum AudioDeviceEvents { + DeviceChanged = 'DeviceChanged', + DeviceListChanged = 'DeviceListChanged', + } + export interface AudioDeviceHandlerEvents { + [AudioDeviceEvents.DeviceChanged]: AudioDeviceDeviceChangedEvent; + [AudioDeviceEvents.DeviceListChanged]: AudioDeviceDeviceListChangedEvent; + } + // -- Event Handlers + // Device Changed + export interface AudioDeviceDeviceChangedEvent { + name: AudioDeviceEvents.DeviceChanged; + currentDevice: AudioDevice; + } + // Device List Changed + export interface AudioDeviceDeviceListChangedEvent { + name: AudioDeviceEvents.DeviceListChanged; + newDeviceList: AudioDevice[]; + } + + export class CameraManager { + public static getInstance(): CameraManager; + + public switchCamera(cameraType: Voximplant.CameraType): void; + + public setCameraResolution(width: number, height: number): void; + + public useOrientationEventListener(use: boolean): void; + + public on( + event: K, + handler: (event: CameraHandlerEvents[K]) => void, + ): void; + + public off( + event: K, + handler?: (event: CameraHandlerEvents[K]) => void, + ): void; + } + + export enum CameraEvents { + CameraDisconnected = 'CameraDisconnected', + CameraError = 'CameraError', + CameraSwitchDone = 'CameraSwitchDone', + CameraSwitchError = 'CameraSwitchError', + } + export interface CameraHandlerEvents { + [CameraEvents.CameraDisconnected]: CameraDisconnectedEvent; + [CameraEvents.CameraError]: CameraErrorEvent; + [CameraEvents.CameraSwitchError]: CameraErrorEvent; + [CameraEvents.CameraSwitchDone]: CameraSwitchDoneEvent; + } + // -- Event Handlers + // Camera Disconnected + export interface CameraDisconnectedEvent { + name: CameraEvents.CameraDisconnected; + } + // Camera Error, Camera Switch Error + export interface CameraErrorEvent { + name: CameraEvents.CameraError | CameraEvents.CameraSwitchError; + error: string; + } + // Camera Switch Done + export interface CameraSwitchDoneEvent { + name: CameraEvents.CameraSwitchDone; + isFrontCamera: boolean; + } + + export class AudioFile { + public url: string; + public looped: boolean; + public name: string; + + public initWithLocalFile( + name: string, + type: string, + usage: AudioFileUsage, + ): Promise; + + public loadFile(url: string, usage: AudioFileUsage): Promise; + + public play(looped: boolean): Promise; + + public stop(): Promise; + + public releaseResources(): void; + + public on( + event: AudioFileEventTypes, + handler: (event: AudioFileEvent) => void, + ): void; + + public off( + event: AudioFileEventTypes, + handler?: (event: AudioFileEvent) => void, + ): void; + } + + export enum AudioFileEventTypes { + Started = 'Started', + Stopped = 'Stopped', + } + // -- Event Handlers + // Audio File Started, Audio File Stopped + export interface AudioFileEvent { + name: AudioFileEventTypes.Started | AudioFileEventTypes.Stopped; + audioFile: AudioFile; + result: boolean; + error: string; + } + + export enum AudioDevice { + BLUETOOTH = 'Bluetooth', + EARPIECE = 'Earpiece', + NONE = 'None', + SPEAKER = 'Speaker', + WIRED_HEADSET = 'WiredHeadset', + } + + export enum AudioFileUsage { + IN_CALL = 'incall', + NOTIFICATION = 'notification', + RINGTONE = 'ringtone', + UNKNOWN = 'unknown', + } + } + + namespace Voximplant.Messaging { + export class Messenger { + public on( + eventType: K, + event: (event: MessengerHandlerEvents[K]) => void, + ): void; + + public off( + eventType: K, + event?: (event: MessengerHandlerEvents[K]) => void, + ): void; + + public getMe(): string | null; + + public getUserByName( + username: string, + ): Promise; + + public getUserByIMId( + userId: number, + ): Promise; + + public getUsersByName( + users: string[], + ): Promise; + + public getUsersByIMId( + users: number[], + ): Promise; + + public editUser( + customData: object | null, + privateCustomData: object | null, + ): Promise; + + public setStatus( + online: boolean, + ): Promise; + + public subscribe( + users: number[], + ): Promise; + + public unsubscribe( + users: number[], + ): Promise; + + public unsubscribeFromAll(): Promise< + MessengerSubscriptionEvent | MessengerErrorEvent + >; + + public getSubscriptions(): Promise< + MessengerSubscriptionEvent | MessengerErrorEvent + >; + + public managePushNotifications( + notifications: MessengerNotification[], + ): Promise; + + public createConversation( + conversationConfig?: ConversationConfig, + ): Promise; + + public getConversation( + uuid: string, + ): Promise; + + public getConversations( + uuids: string[], + ): Promise; + + public getPublicConversations(): Promise< + MessengerGetPublicConversationsEvent | MessengerErrorEvent + >; + + public joinConversation( + uuid: string, + ): Promise; + + public leaveConversation( + uuid: string, + ): Promise; + } + + export class Conversation { + public createdTime: number; + public customData: object; + public direct: boolean; + public lastSequence: number; + public lastUpdateTime: number; + public participants: ConversationParticipant[]; + public publicJoin: boolean; + public title: string; + public uuid: string; + public uber: boolean; + + public setCustomData(customData: object): void; + + public setPublicJoin(publicJoin: boolean): void; + + public setTitle(title: string): void; + + public addParticipants( + participants: ConversationParticipant[], + ): Promise; + + public editParticipants( + participants: ConversationParticipant[], + ): Promise; + + public removeParticipants( + participants: ConversationParticipant[], + ): Promise; + + public update(): Promise; + + public typing(): Promise; + + public sendMessage( + text: string, + payload?: object[], + ): Promise; + + public markAsRead( + sequence: number, + ): Promise; + + public retransmitEvents( + from: number, + to: number, + ): Promise; + + public retransmitEventsFrom( + from: number, + count: number, + ): Promise; + + public retransmitEventsTo( + to: number, + count: number, + ): Promise; + } + + export class Message { + public conversation: string; + public payload: { [key: string]: any }[]; + public sequence: number; + public text: string; + public uuid: string; + + public update( + text: string | null, + payload: { [key: string]: any }[] | null, + ): Promise; + + public remove(): Promise; + } + + export enum MessengerEventTypes { + CreateConversation = 'CreateConversation', + EditConversation = 'EditConversation', + EditMessage = 'EditMessage', + EditUser = 'EditUser', + Error = 'Error', + GetConversation = 'GetConversation', + GetPublicConversations = 'GetPublicConversations', + GetSubscriptions = 'GetSubscriptions', + GetUser = 'GetUser', + Read = 'Read', + RemoveConversation = 'RemoveConversation', + RemoveMessage = 'RemoveMessage', + RetransmitEvents = 'RetransmitEvents', + SendMessage = 'SendMessage', + SetStatus = 'SetStatus', + Subscribe = 'Subscribe', + Typing = 'Typing', + Unsubscribe = 'Unsubscribe', + } + export interface MessengerHandlerEvents { + [MessengerEventTypes.CreateConversation]: MessengerConversationEvent; + [MessengerEventTypes.EditConversation]: MessengerConversationEvent; + [MessengerEventTypes.EditMessage]: MessengerMessageEvent; + [MessengerEventTypes.EditUser]: MessengerUserEvent; + [MessengerEventTypes.Error]: MessengerErrorEvent; + [MessengerEventTypes.GetConversation]: MessengerConversationEvent; + [MessengerEventTypes.GetPublicConversations]: MessengerGetPublicConversationsEvent; + [MessengerEventTypes.GetSubscriptions]: MessengerSubscriptionEvent; + [MessengerEventTypes.GetUser]: MessengerUserEvent; + [MessengerEventTypes.Read]: MessengerReadEvent; + [MessengerEventTypes.RemoveConversation]: MessengerConversationEvent; + [MessengerEventTypes.RemoveMessage]: MessengerMessageEvent; + [MessengerEventTypes.RetransmitEvents]: MessengerRetransmitEventsEvent; + [MessengerEventTypes.SendMessage]: MessengerMessageEvent; + [MessengerEventTypes.SetStatus]: MessengerSetStatusEvent; + [MessengerEventTypes.Subscribe]: MessengerSubscriptionEvent; + [MessengerEventTypes.Typing]: MessengerTypingEvent; + [MessengerEventTypes.Unsubscribe]: MessengerSubscriptionEvent; + } + // -- Event Handlers + // User Event + export interface MessengerUserEvent { + action: MessengerAction; + eventType: MessengerEventTypes.EditUser | MessengerEventTypes.GetUser; + imUserId: number; + user: User; + } + // Status Event + export interface MessengerSetStatusEvent { + action: MessengerAction; + eventType: MessengerEventTypes.SetStatus; + imUserId: number; + online: boolean; + } + // Subscription Event + export interface MessengerSubscriptionEvent { + action: MessengerAction; + eventType: + | MessengerEventTypes.GetSubscriptions + | MessengerEventTypes.Subscribe + | MessengerEventTypes.Unsubscribe; + imUserId: number; + users: number[]; + } + // Conversation Event + export interface MessengerConversationEvent { + action: MessengerAction; + eventType: + | MessengerEventTypes.CreateConversation + | MessengerEventTypes.EditConversation + | MessengerEventTypes.RemoveConversation + | MessengerEventTypes.GetConversation; + imUserId: number; + conversation: Conversation; + sequence: number; + timestamp: number; + } + // Conversation List Event + export interface MessengerGetPublicConversationsEvent { + action: MessengerAction; + eventType: MessengerEventTypes.GetPublicConversations; + imUserId: number; + conversationList: string[]; + } + // Conversation Service Event + export interface MessengerTypingEvent { + action: MessengerAction; + eventType: MessengerEventTypes.Typing; + imUserId: number; + conversationUUID: string; + } + export interface MessengerReadEvent { + action: MessengerAction; + eventType: MessengerEventTypes.Read; + imUserId: number; + conversationUUID: string; + sequence: number; + } + // Message Event + export interface MessengerMessageEvent { + action: MessengerAction; + eventType: + | MessengerEventTypes.EditMessage + | MessengerEventTypes.SendMessage + | MessengerEventTypes.RemoveMessage; + imUserId: number; + message: Message; + sequence: number; + timestamp: number; + } + // Retransmit Event + export interface MessengerRetransmitEventsEvent { + action: MessengerAction; + eventType: MessengerEventTypes.RetransmitEvents; + imUserId: number; + from: number; + to: number; + events: object[]; + } + // Error Event + export interface MessengerErrorEvent { + action: MessengerAction; + eventType: MessengerEventTypes.Error; + code: number; + description: string; + } + + export enum MessengerAction { + addParticipants = 'addParticipants', + createConversation = 'createConversation', + editConversation = 'editConversation', + editMessage = 'editMessage', + editParticipants = 'editParticipants', + editUser = 'editUser', + getConversation = 'getConversation', + getConversations = 'getConversations', + getPublicConversations = 'getPublicConversations', + getSubscriptions = 'getSubscriptions', + getUser = 'getUser', + getUsers = 'getUsers', + joinConversation = 'joinConversation', + leaveConversation = 'leaveConversation', + manageNotifications = 'manageNotifications', + read = 'read', + removeConversation = 'removeConversation', + removeMessage = 'removeMessage', + removeParticipants = 'removeParticipants', + retransmitEvents = 'retransmitEvents', + sendMessage = 'sendMessage', + setStatus = 'setStatus', + subscribe = 'subscribe', + typing = 'typing', + unsubscribe = 'unsubscribe', + } + + export enum MessengerNotification { + EditMessage = 'EditMessage', + SendMessage = 'SendMessage', + } + + // -- Structures + // User + export interface User { + name: string; + imId: number; + displayName: string; + customData: object; + privateCustomData: object; + conversationList: string[]; + leaveConversationList: string[]; + notifications: object[]; + isDeleted: boolean; + } + // Conversation Config + export interface ConversationConfig { + customData?: object; + direct?: boolean; + publicJoin?: boolean; + participants: ConversationParticipant[]; + title?: string; + uber?: boolean; + } + // Conversation Participant + export interface ConversationParticipant { + imUserId: number; + canWrite?: boolean, + canManageParticipants?: boolean; + canEditMessages?: boolean; + canEditAllMessages?: boolean; + canRemoveMessages?: boolean; + canRemoveAllMessages?: boolean; + owner?: boolean; + lastReadEventSequence?: number; + } + } +} diff --git a/package.json b/package.json index 7f3f9ac..4760c33 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.37.0", "description": "VoxImplant Mobile SDK for embedding voice and video communication into React Native apps.", "nativePackage": true, + "types": "index.d.ts", "keywords": [ "react-native", "react",