rns-nativecall 0.6.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,4 +33,5 @@ override fun getTaskConfig(intent: Intent?): HeadlessJsTaskConfig? {
33
33
  LinearCountingRetryPolicy(3, 1000)
34
34
  )
35
35
  }
36
- }
36
+ }
37
+
package/index.d.ts CHANGED
@@ -1,34 +1,109 @@
1
+ /**
2
+ * Represents the data payload for an incoming or active call.
3
+ */
1
4
  export interface CallData {
5
+ /** Unique identifier for the call (UUID) */
2
6
  callUuid: string;
7
+ /** Display name of the caller */
3
8
  name?: string;
9
+ /** Specify if the call is voice-only or video-enabled */
4
10
  callType?: 'audio' | 'video';
11
+ /** Internal flag: true if the system is currently processing another call */
5
12
  isBusySignal?: boolean;
13
+ /** Additional custom data passed from FCM/Push payload */
6
14
  [key: string]: any;
7
15
  }
8
16
 
9
- export type CallEventType = 'INCOMING_CALL' | 'BUSY';
17
+ /**
18
+ * Types of events emitted to the Headless JS task.
19
+ */
20
+ export type CallEventType =
21
+ | 'INCOMING_CALL' // A new valid call needs to be displayed
22
+ | 'BUSY' // System is busy, developer should notify caller via API
23
+ | 'ABORTED_CALL'; // Call was canceled or invalid before it could start
24
+
25
+ /**
26
+ * Response object for basic call validation.
27
+ */
28
+ export interface ValidityStatus {
29
+ /** True if the call exists and is eligible to be displayed */
30
+ isValid: boolean;
31
+ /** True if a CANCEL signal has already been received for this UUID */
32
+ isCanceled: boolean;
33
+ }
34
+
35
+ /**
36
+ * Detailed status of a specific call's lifecycle.
37
+ */
38
+ export interface CallStatus {
39
+ /** True if the call has been terminated or canceled */
40
+ isCanceled: boolean;
41
+ /** True if this specific UUID is currently the "active" call tracked by Native */
42
+ isActive: boolean;
43
+ /** Logic helper: returns true if (isActive && !isCanceled) */
44
+ shouldDisplay: boolean;
45
+ }
10
46
 
11
47
  export interface CallHandlerType {
12
48
  /**
13
- * Registers the Headless JS task.
14
- * Handles Busy signals and Call Validity automatically.
49
+ * Registers the background "Headless" task.
50
+ * This is the bridge between a Native push notification and your React Native UI.
51
+ * * @param callback Async function receiving call data and the event type.
15
52
  */
16
53
  registerHeadlessTask(
17
54
  callback: (data: CallData, eventType: CallEventType) => Promise<void>
18
55
  ): void;
19
56
 
57
+ /**
58
+ * Displays the full-screen Native Incoming Call UI.
59
+ * Usually called inside registerHeadlessTask after validating the call.
60
+ * * @param uuid The unique call ID.
61
+ * @param name Name to display on the call screen.
62
+ * @param callType Defaults to 'audio'.
63
+ * @returns Promise resolving to true if the UI was successfully launched.
64
+ */
20
65
  displayCall(
21
66
  uuid: string,
22
67
  name: string,
23
68
  callType: 'audio' | 'video',
24
69
  ): Promise<boolean>;
25
70
 
71
+ /** * Checks if a call is still valid and has not been canceled.
72
+ * Useful for Splash screen "Interceptors" to prevent ghost calls.
73
+ */
74
+ checkCallValidity(uuid: string): Promise<ValidityStatus>;
75
+
76
+ /** * Detailed check of a call's status.
77
+ * Useful for determining if the UI should remain visible.
78
+ */
79
+ checkCallStatus(uuid: string): Promise<CallStatus>;
80
+
81
+ /**
82
+ * Forcefully dismisses the native call UI, stops the ringtone, and clears state.
83
+ * Use this when the call is hung up or timed out.
84
+ */
26
85
  destroyNativeCallUI(uuid: string): void;
27
86
 
87
+ /**
88
+ * Stops the "Connecting..." Foreground Service.
89
+ * MUST be called after displayCall() or when a BUSY signal is handled to
90
+ * remove the persistent system notification.
91
+ */
28
92
  stopForegroundService(): Promise<void>;
29
93
 
94
+ /**
95
+ * Retrieves call data if the app was launched directly from an interaction
96
+ * with a notification while the app was in a "Killed" state.
97
+ */
30
98
  getInitialCallData(): Promise<any | null>;
31
99
 
100
+ /**
101
+ * Subscribes to user interactions on the Native Call UI.
102
+ * * @param onAccept Callback when user presses the Answer button.
103
+ * @param onReject Callback when user presses the Decline button.
104
+ * @param onFailed Callback for system errors (optional).
105
+ * @returns A cleanup function to unsubscribe.
106
+ */
32
107
  subscribe(
33
108
  onAccept: (data: CallData) => void,
34
109
  onReject: (data: CallData) => void,
@@ -36,5 +111,8 @@ export interface CallHandlerType {
36
111
  ): () => void;
37
112
  }
38
113
 
114
+ /**
115
+ * Main handler for Native VoIP Call interactions.
116
+ */
39
117
  declare const CallHandler: CallHandlerType;
40
118
  export default CallHandler;
package/index.js CHANGED
@@ -8,49 +8,54 @@ const { CallModule } = NativeModules;
8
8
  const callEventEmitter = CallModule ? new NativeEventEmitter(CallModule) : null;
9
9
 
10
10
  export const CallHandler = {
11
- /**
12
- * INTERNAL GATEKEEPER: Moves headless logic into the package.
13
- * The dev just passes their "NativeCall" function.
14
- */
15
11
  registerHeadlessTask: (onAction) => {
16
12
  AppRegistry.registerHeadlessTask('ColdStartCallTask', () => async (data) => {
17
13
  const { callUuid, isBusySignal } = data;
18
14
  const uuid = callUuid?.toLowerCase().trim();
19
15
 
20
16
  try {
21
- // 1. Handle Busy Signal (Second Caller)
22
17
  if (isBusySignal) {
23
- console.log(`[RNSNativeCall] System busy. Informing app to send busy signal for: ${uuid}`);
24
18
  if (onAction) await onAction(data, 'BUSY');
25
19
  return;
26
20
  }
27
21
 
28
- // 2. Gatekeeping: Check Validity with Native logic
22
+ // CallModule.checkCallValidity is now accessible via the native bridge
29
23
  const status = await CallModule.checkCallValidity(uuid);
30
24
  if (!status.isValid) {
31
- console.log(`[RNSNativeCall] Aborting task: ${uuid} no longer valid or canceled.`);
32
25
  if (onAction) await onAction(data, 'ABORTED_CALL');
33
26
  return;
34
27
  }
35
28
 
36
- // 3. Valid Incoming Call: Pass to Developer's UI logic
37
29
  if (onAction) {
38
30
  await onAction(data, 'INCOMING_CALL');
39
31
  }
40
-
41
32
  } catch (error) {
42
33
  console.error('[RNSNativeCall] Headless Task Error:', error);
43
34
  }
44
35
  });
45
36
  },
46
37
 
38
+ // --- Added missing bridge methods ---
39
+ checkCallValidity: async (uuid) => {
40
+ if (!CallModule?.checkCallValidity) return { isValid: false, isCanceled: true };
41
+ return await CallModule.checkCallValidity(uuid.toLowerCase().trim());
42
+ },
43
+
44
+ checkCallStatus: async (uuid) => {
45
+ if (!CallModule?.checkCallStatus) return { isCanceled: true, isActive: false, shouldDisplay: false };
46
+ return await CallModule.checkCallStatus(uuid.toLowerCase().trim());
47
+ },
48
+ // ------------------------------------
49
+
47
50
  displayCall: async (uuid, name, callType = "audio") => {
48
51
  if (!CallModule) return false;
49
52
  return await CallModule.displayIncomingCall(uuid.toLowerCase().trim(), name, callType);
50
53
  },
51
54
 
52
55
  stopForegroundService: async () => {
53
- await CallModule.stopForegroundService(true)
56
+ if (CallModule?.stopForegroundService) {
57
+ await CallModule.stopForegroundService();
58
+ }
54
59
  },
55
60
 
56
61
  destroyNativeCallUI: (uuid) => {
@@ -66,16 +71,13 @@ export const CallHandler = {
66
71
 
67
72
  subscribe: (onAccept, onReject, onFailed) => {
68
73
  if (!callEventEmitter) return () => { };
69
-
70
74
  const subs = [
71
75
  callEventEmitter.addListener('onCallAccepted', (data) => onAccept(data)),
72
76
  callEventEmitter.addListener('onCallRejected', (data) => onReject(data)),
73
77
  ];
74
-
75
78
  if (onFailed) {
76
79
  subs.push(callEventEmitter.addListener('onCallFailed', onFailed));
77
80
  }
78
-
79
81
  return () => subs.forEach(s => s.remove());
80
82
  }
81
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.6.8",
3
+ "version": "0.7.0",
4
4
  "description": "High-performance React Native module for handling native VoIP call UI on Android and iOS.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",