Skip to content

Commit 1fa33c6

Browse files
committed
Improve type definitions
- Fix 'didLoadWithEvents' and 'didReceiveStartCallAction' event payloads - Specify 'setSettings' and 'setForegroundServiceSettings' input shapes - Fix 'getCalls' return type (close #680, close #696)
1 parent 55263b2 commit 1fa33c6

File tree

1 file changed

+45
-63
lines changed

1 file changed

+45
-63
lines changed

index.d.ts

Lines changed: 45 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,4 @@
11
declare module 'react-native-callkeep' {
2-
export type Events =
3-
'didReceiveStartCallAction' |
4-
'answerCall' |
5-
'endCall' |
6-
'didActivateAudioSession' |
7-
'didDeactivateAudioSession' |
8-
'didDisplayIncomingCall' |
9-
'didToggleHoldCallAction' |
10-
'didPerformDTMFAction' |
11-
'didResetProvider' |
12-
'checkReachability' |
13-
'didPerformSetMutedCallAction' |
14-
'didChangeAudioRoute' |
15-
'didLoadWithEvents' |
16-
'showIncomingCallUi' |
17-
'silenceIncomingCall' |
18-
'createIncomingConnectionFailed';
19-
20-
export type InitialEvent<Event extends Events> = {
21-
name: NativeEvents[Event],
22-
data: EventHandlers[Event]
23-
}
24-
export type InitialEvents = Array<InitialEvent<Events>>;
25-
262
export type NativeEvents = {
273
didReceiveStartCallAction: 'RNCallKeepDidReceiveStartCallAction';
284
answerCall: 'RNCallKeepPerformAnswerCallAction';
@@ -34,44 +10,50 @@ declare module 'react-native-callkeep' {
3410
didToggleHoldCallAction: 'RNCallKeepDidToggleHoldAction';
3511
didChangeAudioRoute: 'RNCallKeepDidChangeAudioRoute';
3612
didPerformDTMFAction: 'RNCallKeepDidPerformDTMFAction';
37-
didLoadWithEvents: 'RNCallKeepDidLoadWithEvents';
3813
showIncomingCallUi: 'RNCallKeepShowIncomingCallUi';
3914
silenceIncomingCall: 'RNCallKeepOnSilenceIncomingCall';
4015
createIncomingConnectionFailed: 'RNCallKeepOnIncomingConnectionFailed';
4116
checkReachability: 'RNCallKeepCheckReachability';
4217
didResetProvider: 'RNCallKeepProviderReset';
18+
didLoadWithEvents: 'RNCallKeepDidLoadWithEvents';
4319
}
44-
export type EventHandlers = {
45-
didReceiveStartCallAction: (args: { handle: string, callUUID: string, name: string }) => void;
46-
answerCall: (args: { callUUID: string }) => void;
47-
endCall: (args: { callUUID: string }) => void;
48-
didActivateAudioSession: () => void;
49-
didDeactivateAudioSession: () => void;
50-
didDisplayIncomingCall: (args: {
51-
error?: string,
52-
errorCode?: 'Unentitled' | 'CallUUIDAlreadyExists' | 'FilteredByDoNotDisturb' | 'FilteredByBlockList' | 'Unknown',
53-
callUUID: string,
54-
handle: string,
55-
localizedCallerName: string,
56-
hasVideo: '1' | '0',
57-
fromPushKit: '1' | '0',
58-
payload: object,
59-
}) => void;
60-
didPerformSetMutedCallAction: (args: { muted: boolean, callUUID: string }) => void;
61-
didToggleHoldCallAction: (args: { hold: boolean, callUUID: string }) => void;
62-
didChangeAudioRoute: (args: {
20+
21+
export type InitialEvents = Array<{
22+
[Event in Events]: { name: NativeEvents[Event], data: EventsPayload[Event] }
23+
}[Events]>
24+
25+
export type Events = keyof NativeEvents;
26+
export type EventsPayload = {
27+
didReceiveStartCallAction: { handle: string, callUUID?: string, name?: string };
28+
answerCall: { callUUID: string };
29+
endCall: { callUUID: string };
30+
didActivateAudioSession: undefined;
31+
didDeactivateAudioSession: undefined;
32+
didDisplayIncomingCall: {
33+
error?: string,
34+
errorCode?: 'Unentitled' | 'CallUUIDAlreadyExists' | 'FilteredByDoNotDisturb' | 'FilteredByBlockList' | 'Unknown',
35+
callUUID: string,
36+
handle: string,
37+
localizedCallerName: string,
38+
hasVideo: '1' | '0',
39+
fromPushKit: '1' | '0',
40+
payload: object,
41+
};
42+
didPerformSetMutedCallAction: { muted: boolean, callUUID: string };
43+
didToggleHoldCallAction: { hold: boolean, callUUID: string };
44+
didChangeAudioRoute: {
6345
output: string,
6446
reason?: number,
6547
handle?: string,
6648
callUUID?: string,
67-
}) => void;
68-
didPerformDTMFAction: (args: { digits: string, callUUID: string }) => void;
69-
didLoadWithEvents: (args: { events: InitialEvents }) => void;
70-
showIncomingCallUi: (args: { handle: string, callUUID: string, name: string}) => void;
71-
silenceIncomingCall: (args: { handle: string, callUUID: string, name: string}) => void;
72-
createIncomingConnectionFailed: (args: { handle: string, callUUID: string, name: string}) => void;
73-
checkReachability: () => void;
74-
didResetProvider: () => void;
49+
};
50+
didPerformDTMFAction: { digits: string, callUUID: string };
51+
showIncomingCallUi: { handle: string, callUUID: string, name: string };
52+
silenceIncomingCall: { handle: string, callUUID: string, name: string };
53+
createIncomingConnectionFailed: { handle: string, callUUID: string, name: string };
54+
checkReachability: undefined;
55+
didResetProvider: undefined;
56+
didLoadWithEvents: InitialEvents;
7557
}
7658

7759
type HandleType = 'generic' | 'number' | 'email';
@@ -109,12 +91,6 @@ declare module 'react-native-callkeep' {
10991
}
11092
}
11193

112-
export type DidReceiveStartCallActionPayload = { handle: string };
113-
export type AnswerCallPayload = { callUUID: string };
114-
export type EndCallPayload = AnswerCallPayload;
115-
export type DidDisplayIncomingCallPayload = string | undefined;
116-
export type DidPerformSetMutedCallActionPayload = boolean;
117-
11894
export const CONSTANTS: {
11995
END_CALL_REASONS: {
12096
FAILED: 1,
@@ -133,7 +109,7 @@ declare module 'react-native-callkeep' {
133109

134110
static addEventListener<Event extends Events>(
135111
type: Event,
136-
handler: EventHandlers[Event],
112+
handler: (args: EventsPayload[Event]) => void,
137113
): void
138114

139115
static removeEventListener(type: Events): void
@@ -198,18 +174,24 @@ declare module 'react-native-callkeep' {
198174

199175
static setReachable(): void
200176

201-
static setSettings(settings: Object): void;
177+
static setSettings(settings: IOptions): void;
202178

203179
/**
204180
* @description isCallActive method is available only on iOS.
205181
*/
206182
static isCallActive(uuid: string): Promise<boolean>
207183

208-
static getCalls(): Promise<object>
184+
static getCalls(): Promise<{
185+
callUUID: string,
186+
hasConnected: boolean,
187+
hasEnded: boolean,
188+
onHold: boolean,
189+
outgoing: boolean
190+
}[] | void>
209191

210192
static getAudioRoutes(): Promise<void>
211193

212-
static setAudioRoute: (uuid:string, inputName: string) => Promise<void>
194+
static setAudioRoute: (uuid: string, inputName: string) => Promise<void>
213195

214196
/**
215197
* @description supportConnectionService method is available only on Android.
@@ -253,7 +235,7 @@ declare module 'react-native-callkeep' {
253235
*/
254236
static setAvailable(active: boolean): void
255237

256-
static setForegroundServiceSettings(settings: Object): void
238+
static setForegroundServiceSettings(settings: NonNullable<IOptions['android']['foregroundService']>): void
257239

258240
static canMakeMultipleCalls(allow: boolean): void
259241

0 commit comments

Comments
 (0)