Skip to content

Commit df8649b

Browse files
authored
Merge pull request #657 from avorra/handler-types
Types: Describe event handlers
2 parents 489a4c2 + ddcebc5 commit df8649b

File tree

1 file changed

+62
-2
lines changed

1 file changed

+62
-2
lines changed

index.d.ts

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,63 @@ declare module 'react-native-callkeep' {
1717
'silenceIncomingCall' |
1818
'createIncomingConnectionFailed';
1919

20+
export type InitialEvent<Event extends Events> = {
21+
name: NativeEvents[Event],
22+
data: EventHandlers[Event]
23+
}
24+
export type InitialEvents = Array<InitialEvent<Events>>;
25+
26+
export type NativeEvents = {
27+
didReceiveStartCallAction: 'RNCallKeepDidReceiveStartCallAction';
28+
answerCall: 'RNCallKeepPerformAnswerCallAction';
29+
endCall: 'RNCallKeepPerformEndCallAction';
30+
didActivateAudioSession: 'RNCallKeepDidActivateAudioSession';
31+
didDeactivateAudioSession: 'RNCallKeepDidDeactivateAudioSession';
32+
didDisplayIncomingCall: 'RNCallKeepDidDisplayIncomingCall';
33+
didPerformSetMutedCallAction: 'RNCallKeepDidPerformSetMutedCallAction';
34+
didToggleHoldCallAction: 'RNCallKeepDidToggleHoldAction';
35+
didChangeAudioRoute: 'RNCallKeepDidChangeAudioRoute';
36+
didPerformDTMFAction: 'RNCallKeepDidPerformDTMFAction';
37+
didLoadWithEvents: 'RNCallKeepDidLoadWithEvents';
38+
showIncomingCallUi: 'RNCallKeepShowIncomingCallUi';
39+
silenceIncomingCall: 'RNCallKeepOnSilenceIncomingCall';
40+
createIncomingConnectionFailed: 'RNCallKeepOnIncomingConnectionFailed';
41+
checkReachability: 'RNCallKeepCheckReachability';
42+
didResetProvider: 'RNCallKeepProviderReset';
43+
}
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: {
63+
output: string,
64+
reason?: number,
65+
handle?: string,
66+
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;
75+
}
76+
2077
type HandleType = 'generic' | 'number' | 'email';
2178

2279
export type AudioRoute = {
@@ -70,11 +127,14 @@ declare module 'react-native-callkeep' {
70127
};
71128

72129
export default class RNCallKeep {
73-
static getInitialEvents(): Promise<Array<Object>>
130+
static getInitialEvents(): Promise<InitialEvents>
74131

75132
static clearInitialEvents(): void
76133

77-
static addEventListener(type: Events, handler: (args: any) => void): void
134+
static addEventListener<Event extends Events>(
135+
type: Event,
136+
handler: EventHandlers[Event],
137+
): void
78138

79139
static removeEventListener(type: Events): void
80140

0 commit comments

Comments
 (0)