### Setup and Server Configuration Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Guides on setting up the library and configuring server-side components for sending push notifications. ```APIDOC ## configuration.md This section covers the setup process for the React Native VoIP Push Notification library and provides comprehensive guidance on server-side configuration. It includes details on APNS configuration and examples for common server environments. ### Key Features: - Server-side APNS configuration. - Server configuration examples (Node.js + cURL). - Certificate management. Refer to `configuration.md` for detailed setup and configuration instructions. ``` -------------------------------- ### Install react-native-voip-push-notification Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt Install the library using npm and then navigate to the ios directory to install pods. ```bash npm install --save react-native-voip-push-notification cd ios && pod install ``` -------------------------------- ### iOS AppDelegate.m Setup Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt Minimum native setup for iOS requires importing PushKit.h and RNVoipPushNotificationManager.h, implementing PKPushRegistryDelegate, calling voipRegistration, and implementing 3 PushKit delegate methods. ```objective-c // Import PushKit.h and RNVoipPushNotificationManager.h in AppDelegate.m // Implement PKPushRegistryDelegate // Call voipRegistration in didFinishLaunchingWithOptions // Implement 3 PushKit delegate methods ``` -------------------------------- ### Step-by-Step Implementation Guide Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt A practical guide to implementing VoIP push notifications in a React Native application. ```APIDOC ## integration-guide.md This guide provides step-by-step instructions for integrating the React Native VoIP Push Notification library into your project. It covers essential setup steps and common integration patterns. ### Key Features: - Step-by-step implementation instructions. - Xcode project setup. - AppDelegate configuration. - CallKit and PushKit framework integration. - Physical device testing guide. Refer to `integration-guide.md` for a complete implementation walkthrough. ``` -------------------------------- ### Type-Safe Integration Examples Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Examples showcasing type-safe integration of VoIP push notifications. ```typescript // Type-safe integration examples ``` -------------------------------- ### Install react-native-voip-push-notification Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/README.md Install the library using npm and run pod install for iOS. Ensure your iOS version is 8.0 or higher. ```bash npm install --save react-native-voip-push-notification # --- if using pod cd ios/ && pod install ``` -------------------------------- ### TypeScript Integration Examples Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Provides examples of how to integrate and use the library with TypeScript, leveraging type definitions. ```TypeScript // Placeholder for TypeScript integration examples. // This would demonstrate using the provided type definitions. // Example: // import RNVoipPushNotification, { EventsPayload } from 'react-native-voip-push-notification'; // // RNVoipPushNotification.addEventListener('voipNotificationReceived', (payload: EventsPayload) => { // console.log('Received typed payload:', payload); // }); ``` -------------------------------- ### Complete VoIP Integration Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/api-reference/RNVoipPushNotification.md A comprehensive example demonstrating how to integrate `react-native-voip-push-notification` into a React Native application. It covers registering for tokens, handling incoming notifications, processing cached events, and initiating registration. ```javascript import React, { useEffect } from 'react'; import { AppState } from 'react-native'; import VoipPushNotification from 'react-native-voip-push-notification'; export function VoIPManager() { useEffect(() => { // Step 1: Register for token VoipPushNotification.addEventListener('register', (token) => { console.log('VoIP Token:', token); // Send token to your push server }); // Step 2: Handle incoming notifications VoipPushNotification.addEventListener('notification', (notification) => { const { uuid, callerName, handle } = notification; // Perform your call handling logic handleIncomingCall(uuid, callerName, handle); // Signal to native side that we're done VoipPushNotification.onVoipNotificationCompleted(uuid); }); // Step 3: Handle events cached before JS bridge initialized VoipPushNotification.addEventListener('didLoadWithEvents', (events) => { if (!events || !Array.isArray(events)) { return; } events.forEach(event => { if (event.name === VoipPushNotification.RNVoipPushRemoteNotificationsRegisteredEvent) { // Handle cached register event console.log('Cached token:', event.data); } else if (event.name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent) { // Handle cached notification event console.log('Cached notification:', event.data); } }); }); // Step 4: Initiate registration VoipPushNotification.registerVoipToken(); return () => { VoipPushNotification.removeEventListener('register'); VoipPushNotification.removeEventListener('notification'); VoipPushNotification.removeEventListener('didLoadWithEvents'); }; }, []); return null; } ``` -------------------------------- ### Initialize VoIP Manager and Setup Listeners Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/integration-guide.md Sets up listeners for VoIP push notifications and registers the device token. Call `setupListeners` during app initialization. ```javascript import VoIPManager from './VoIPManager'; export function App() { useEffect(() => { VoIPManager.setupListeners(); VoipPushNotification.registerVoipToken(); }, []); return null; } ``` -------------------------------- ### cURL VoIP Push Examples Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Illustrates how to send VoIP push notifications using cURL commands. ```Shell # This is a placeholder for cURL examples. # Sending a VoIP push notification requires specific headers and payload. # Example structure: # curl -v --http2 --cert "ck.pem:PASSWORD" --cert-type P12 \ # -H "apns-topic: com.your.bundle.id" \ # -H "apns-push-type: voip" \ # -d '{"aps":{"alert":"Incoming Call","content-available":1,"voip-payload":{"uuid":"some-uuid","from":"Sender Name"}}}' \ # https://api.push.apple.com/3/device/YOUR_DEVICE_TOKEN ``` -------------------------------- ### Install Package via yarn Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/integration-guide.md Install the react-native-voip-push-notification package using yarn and then link the native iOS dependencies by running pod install. ```bash yarn add react-native-voip-push-notification cd ios && yarn install cd .. ``` -------------------------------- ### cURL Server-Side Push Examples Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Shows examples of sending push notifications using cURL from the server-side. This is useful for testing and direct interaction with the push notification services. ```bash # cURL server-side push examples # This snippet is a placeholder and would contain cURL commands for sending push notifications. ``` -------------------------------- ### Minimal Setup: Register VoIP Token Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md Use this pattern when your app only needs to register the VoIP token with the server. It sets up an event listener for registration and calls the registration function. ```javascript useEffect(() => { VoipPushNotification.addEventListener('register', sendTokenToServer); VoipPushNotification.registerVoipToken(); return () => VoipPushNotification.removeEventListener('register'); }, []); ``` -------------------------------- ### Add Completion Handler and Event Listener Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/errors.md This Objective-C and JavaScript example demonstrates how to correctly manage completion handlers for VoIP notifications. Ensure the UUIDs match between native and JavaScript to prevent silent failures. ```objective-c // AppDelegate.m - Always store completion handler NSString *uuid = payload.dictionaryPayload[@"uuid"]; [RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion]; ``` ```javascript // JavaScript - Pass exact UUID from payload VoipPushNotification.addEventListener('notification', (notification) => { const { uuid } = notification; // ... do work ... VoipPushNotification.onVoipNotificationCompleted(uuid); // Must match }); ``` -------------------------------- ### Node.js Server-Side Push Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Example code for sending server-side push notifications using Node.js. ```javascript // Server-side push examples (Node.js) ``` -------------------------------- ### Server Setup for VoIP Pushes Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt Server setup involves obtaining a VoIP push certificate from Apple Developer and sending pushes with specific headers (apns-push-type: voip, apns-topic: .voip) and a payload including 'aps', 'uuid', 'callerName', and 'handle'. ```plaintext - Obtain VoIP push certificate from Apple Developer - Send pushes with headers: apns-push-type: voip, apns-topic: .voip - Include payload: {aps: {}, uuid: "...", callerName: "...", handle: "..."} ``` -------------------------------- ### cURL Server-Side Push Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Example code for sending server-side push notifications using cURL. ```bash // Server-side push examples (cURL) ``` -------------------------------- ### VoIP Manager Module Setup Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/integration-guide.md Sets up the VoIP manager to handle token registration, incoming notifications, and cached events during app startup. Ensure your VoIP service initialization is correctly implemented. ```javascript import { useEffect } from 'react'; import VoipPushNotification from 'react-native-voip-push-notification'; import { Alert } from 'react-native'; // Your VoIP service initialization import { initializeVoIPService } from './services/voipService'; export function useVoIPNotifications() { useEffect(() => { // Step 1: Listen for token registration VoipPushNotification.addEventListener('register', (token) => { console.log('VoIP Token registered:', token); // Send token to your server sendTokenToServer(token).catch((error) => { console.error('Failed to send token:', error); }); }); // Step 2: Listen for incoming VoIP pushes VoipPushNotification.addEventListener('notification', async (notification) => { console.log('VoIP notification received:', notification); const { uuid, callerName, handle } = notification; try { // Initialize VoIP service (register with SIP, etc.) await initializeVoIPService({ uuid, callerId: handle, callerName, }); // Let CallKit know we're ready VoipPushNotification.onVoipNotificationCompleted(uuid); } catch (error) { console.error('Failed to handle VoIP notification:', error); // Still signal completion to avoid timeout VoipPushNotification.onVoipNotificationCompleted(uuid); // Show error to user Alert.alert('Call Failed', error.message); } }); // Step 3: Handle events that occurred during app startup VoipPushNotification.addEventListener('didLoadWithEvents', (events) => { if (!events || !Array.isArray(events) || events.length === 0) { console.log('No cached events on startup'); return; } console.log('Processing cached startup events:', events.length); for (let event of events) { const { name, data } = event; if (name === VoipPushNotification.RNVoipPushRemoteNotificationsRegisteredEvent) { console.log('Cached registration event, token:', data); sendTokenToServer(data).catch(console.error); } else if (name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent) { console.log('Cached notification event:', data); // Process cached notification // Note: CallKit will already have been reported for this } } }); // Step 4: Initiate VoIP push registration VoipPushNotification.registerVoipToken(); // Cleanup return () => { VoipPushNotification.removeEventListener('register'); VoipPushNotification.removeEventListener('notification'); VoipPushNotification.removeEventListener('didLoadWithEvents'); }; }, []); } // Helper function async function sendTokenToServer(token) { const response = await fetch('https://your-server/api/register-voip-token', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ voipToken: token, deviceType: 'ios', }), }); if (!response.ok) { throw new Error(`Server error: ${response.status}`); } return response.json(); } ``` -------------------------------- ### Complete AppDelegate.m for Native Integration Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Provides the full native integration code for AppDelegate.m. Ensure this file is correctly updated for native setup. ```Objective-C // Complete AppDelegate.m (native integration) // This snippet is a placeholder and would contain the full Objective-C code for AppDelegate.m integration. ``` -------------------------------- ### TypeScript Integration Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Shows how to integrate and use the VoIP push notification library with TypeScript. This example highlights type safety and improved developer experience. ```TypeScript // TypeScript integration // This snippet is a placeholder and would contain TypeScript code for integration. ``` -------------------------------- ### JavaScript Setup for VoIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md Initialize the VoipPushNotification module in your JavaScript code to register for tokens, handle incoming notifications, and manage event listeners. Ensure to clean up listeners on component unmount. ```javascript import VoipPushNotification from 'react-native-voip-push-notification'; useEffect(() => { // Register for tokens VoipPushNotification.addEventListener('register', (token) => { console.log('Token:', token); sendToServer(token); }); // Handle incoming pushes VoipPushNotification.addEventListener('notification', (notification) => { const { uuid } = notification; // Handle the call... VoipPushNotification.onVoipNotificationCompleted(uuid); }); // Handle cached events from startup VoipPushNotification.addEventListener('didLoadWithEvents', (events) => { // Process missed events }); // Initiate registration VoipPushNotification.registerVoipToken(); return () => { VoipPushNotification.removeEventListener('register'); VoipPushNotification.removeEventListener('notification'); VoipPushNotification.removeEventListener('didLoadWithEvents'); }; }, []); ``` -------------------------------- ### Example Usage of InitialEvent with addEventListener Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/types.md Demonstrates how to use the addEventListener function with the 'didLoadWithEvents' event and how to correctly type-check and access data from InitialEvent objects. ```typescript import VoipPushNotification from 'react-native-voip-push-notification'; VoipPushNotification.addEventListener('didLoadWithEvents', (events: Array) => { for (let event of events) { if (event.name === 'RNVoipPushRemoteNotificationsRegisteredEvent') { // event.data is string (token) const token: string = event.data; } else if (event.name === 'RNVoipPushRemoteNotificationReceivedEvent') { // event.data is object (notification payload) const notification: object = event.data; } } }); ``` -------------------------------- ### DidLoadWithEvents Event Payload Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/api-reference/RNVoipPushNotification.md Provides an example of the event payload for 'didLoadWithEvents', which is an array of events that occurred before the JavaScript bridge was initialized. This is used to process registration and notification events that fired during app startup. ```javascript { name: 'RNVoipPushRemoteNotificationsRegisteredEvent', data: 'a1b2c3d4e5f6...' }, { name: 'RNVoipPushRemoteNotificationReceivedEvent', data: { uuid: '...', callerName: '...' } } ``` -------------------------------- ### Node.js Server-Side Push Sending Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Example of sending a VoIP push notification from a Node.js server. ```JavaScript // This is a placeholder for Node.js server-side push sending. // It would involve using a library like 'node-apn' or similar. // Example: // const apn = require('apn'); // const options = { ... }; // APNs configuration // const provider = new apn.Provider(options); // // const notification = { // aps: { // alert: 'Incoming Call', // 'content-available': 1, // 'voip-payload': { // Custom VoIP payload // uuid: 'some-unique-id', // from: 'John Doe', // name: 'John Doe' // } // } // }; // // provider.send(notification, deviceToken).then(result => { // console.log('Push sent:', result); // }); ``` -------------------------------- ### Setup VoIP Push Notification Event Listeners Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/configuration.md Attach event listeners early in the app's lifecycle to handle registration, incoming notifications, and cached events. Remember to initiate PushKit registration and clean up listeners on unmount. ```javascript useEffect(() => { // 1. Subscribe to registration event VoipPushNotification.addEventListener('register', (token) => { console.log('VoIP Token:', token); // Send token to your push server sendTokenToServer(token); }); // 2. Subscribe to incoming push event VoipPushNotification.addEventListener('notification', async (notification) => { const { uuid, callerName, handle } = notification; // Initialize your VoIP client, register with SIP server, etc. await initializeCall({ uuid, callerName, handle }); // Signal completion to native side VoipPushNotification.onVoipNotificationCompleted(uuid); }); // 3. Subscribe to cached events (for events during startup) VoipPushNotification.addEventListener('didLoadWithEvents', (events) => { if (!events || !Array.isArray(events)) return; events.forEach(event => { if (event.name === VoipPushNotification.RNVoipPushRemoteNotificationsRegisteredEvent) { // Handle cached registration console.log('Cached token:', event.data); } else if (event.name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent) { // Handle cached notification console.log('Cached notification:', event.data); } }); }); // 4. Initiate PushKit registration VoipPushNotification.registerVoipToken(); // Cleanup return () => { VoipPushNotification.removeEventListener('register'); VoipPushNotification.removeEventListener('notification'); VoipPushNotification.removeEventListener('didLoadWithEvents'); }; }, []); ``` -------------------------------- ### AppDelegate.m Setup for VoIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md Integrate PushKit and RNVoipPushNotificationManager into your AppDelegate.m file for handling VoIP push notifications. This includes registering for tokens, updating credentials, and processing incoming push payloads. ```objective-c #import #import "RNVoipPushNotificationManager.h" @interface AppDelegate : UIResponder @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [RNVoipPushNotificationManager voipRegistration]; // ... rest of initialization } - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type { [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type]; } - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion { NSString *uuid = payload.dictionaryPayload[@"uuid"]; [RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion]; [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; [RNCallKeep reportNewIncomingCall:uuid handle:payload.dictionaryPayload[@"handle"] handleType:@"generic" hasVideo:NO localizedCallerName:payload.dictionaryPayload[@"callerName"] fromPushKit:YES payload:nil]; } @end ``` -------------------------------- ### Token Payload Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/types.md Represents the VoIP push token obtained from PushKit as a hexadecimal string. The format is a lowercase hexadecimal string, typically 32-64 characters in length. ```string "f0d0e0c0b0a090807f6f5f4f3f2f1f0e" ``` -------------------------------- ### VoIP Service Initialization Module Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Demonstrates the initialization of the VoIP service module in JavaScript. ```JavaScript // Placeholder for VoIP service initialization. // This would typically involve importing and calling a setup function. // Example: // import RNVoipPushNotification from 'react-native-voip-push-notification'; // // RNVoipPushNotification.registerVoipToken(); ``` -------------------------------- ### Complete Lifecycle Management Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Demonstrates comprehensive lifecycle management for the VoIP push notification service. ```JavaScript // Placeholder for complete lifecycle management. // This could involve setup, teardown, and handling various states. // Example: // // Initialization // RNVoipPushNotification.registerVoipToken(); // // // Event listeners // RNVoipPushNotification.addEventListener(...); // // // Cleanup on component unmount or app close // // RNVoipPushNotification.removeEventListener(...); // // RNVoipPushNotification.onVoipNotificationCompleted(...); ``` -------------------------------- ### Documentation Index and Navigation Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt The main manifest file providing an overview and navigation to all documentation sections. ```APIDOC ## MANIFEST.md The MANIFEST.md file serves as the central index for all documentation related to the React Native VoIP Push Notification library. It provides an overview and navigation links to various sections. ### Key Sections: - README.md (Quick reference, API overview) - API reference (JavaScript and Native) - Types documentation - Configuration guide - Architecture and design - Error handling - Integration guide Start with `README.md` for an overview or use `MANIFEST.md` to navigate to specific topics. ``` -------------------------------- ### Check AppDelegate Implementation Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/errors.md Verify that the necessary push registry methods are implemented in your AppDelegate.m file using grep. ```bash grep -n "pushRegistry:" ios/AppDelegate.m ``` -------------------------------- ### JavaScript useVoIPNotifications Hook Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Example of using the `useVoIPNotifications` hook in JavaScript for handling VoIP notifications within a React Native component. ```JavaScript // This is a placeholder for the useVoIPNotifications hook usage. // It would demonstrate how to subscribe to and handle notification events. // Example: // import { useVoIPNotifications } from 'react-native-voip-push-notification'; // // useVoIPNotifications({ // onVoipNotificationReceived: (notification) => { // console.log('VoIP Notification Received:', notification); // }, // onVoipDidComplete: (uuid) => { // console.log('VoIP Notification Completed:', uuid); // } // }); ``` -------------------------------- ### VoIP Manager for Custom Service Integration Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/integration-guide.md Manages VoIP call initialization from push notifications and sets up event listeners for the VoIP service. Ensure `SipClient` is correctly implemented and imported. ```javascript import VoipPushNotification from 'react-native-voip-push-notification'; import { SipClient } from './sipClient'; class VoIPManager { static async initializeFromPush(callData) { const { uuid, handle, callerName } = callData; // Initialize SIP registration await SipClient.register({ uri: handle, password: await this.getPassword(), }); // Wait for registration to complete await SipClient.waitForReady(5000); // Accept or setup for incoming call // (CallKit has already shown the UI) return uuid; } static setupListeners() { VoipPushNotification.addEventListener('notification', async (notification) => { const uuid = notification.uuid; try { await this.initializeFromPush(notification); VoipPushNotification.onVoipNotificationCompleted(uuid); } catch (error) { console.error('VoIP initialization failed:', error); VoipPushNotification.onVoipNotificationCompleted(uuid); } }); VoipPushNotification.addEventListener('register', (token) => { this.sendTokenToServer(token); }); } static async sendTokenToServer(token) { // Implementation } static async getPassword() { // Retrieve from secure storage } } export default VoIPManager; ``` -------------------------------- ### Complete AppDelegate.m Template Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md A copy-paste ready template for AppDelegate.m to integrate VoIP push notifications. ```objective-c // Complete AppDelegate.m template (copy-paste ready) ``` -------------------------------- ### Register for VoIP Push Credentials Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/api-reference/RNVoipPushNotificationManager-Native.md Call this method as early as possible in `application:didFinishLaunchingWithOptions:` within your `AppDelegate.m` to register for VoIP push credentials using PushKit. It handles registration and event dispatching. ```objective-c #import "RNVoipPushNotificationManager.h" - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Register VoIP push ASAP [RNVoipPushNotificationManager voipRegistration]; // ... rest of launch code } ``` -------------------------------- ### Node.js Server-Side Push Sending Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Provides an example of how to send push notifications from a Node.js server. This is necessary for triggering notifications to your React Native application. ```JavaScript // Node.js server-side push sending // This snippet is a placeholder and would contain the Node.js code for sending push notifications. ``` -------------------------------- ### Full Lifecycle Management Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md This pattern is recommended for production apps, as it handles the full lifecycle of VoIP push notifications, including token registration, incoming pushes, and startup events. ```javascript useEffect(() => { // Token registration VoipPushNotification.addEventListener('register', handleTokenRegistered); // Incoming pushes VoipPushNotification.addEventListener('notification', handleIncomingPush); // Startup events VoipPushNotification.addEventListener('didLoadWithEvents', handleCachedEvents); VoipPushNotification.registerVoipToken(); return () => { VoipPushNotification.removeEventListener('register'); VoipPushNotification.removeEventListener('notification'); VoipPushNotification.removeEventListener('didLoadWithEvents'); }; }, []); ``` -------------------------------- ### Cached Events Payload Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/types.md An array of events emitted before JavaScript event listeners were attached. Each event object contains a name and associated data. ```javascript [ { name: 'RNVoipPushRemoteNotificationsRegisteredEvent', data: 'f0d0e0c0b0a090807f6f5f4f3f2f1f0e' }, { name: 'RNVoipPushRemoteNotificationReceivedEvent', data: { uuid: '550e8400-e29b-41d4-a716-446655440000', callerName: 'Bob', handle: '+1-555-0456' } } ] ``` -------------------------------- ### Notification Payload Example Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/types.md A dictionary payload from a PushKit VoIP push. The structure depends on server-defined fields, but commonly includes fields for call handling like uuid, callerName, and handle. ```javascript { uuid: "550e8400-e29b-41d4-a716-446655440000", callerName: "Alice Johnson", handle: "+1-555-0123", callType: "video", conversationId: "conv_12345" } ``` -------------------------------- ### Complete AppDelegate.m with Delegate Methods Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt This snippet includes all necessary delegate methods for integrating VoIP push notifications within your AppDelegate.m file. ```Objective-C // This is a placeholder for the actual AppDelegate.m code. // It would include methods like: // - application:didFinishLaunchingWithOptions: // - userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: // - application:didReceiveRemoteNotification:fetchCompletionHandler: // - etc. // The full code is available in the generated documentation. ``` -------------------------------- ### File List for react-native-voip-push-notification Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Lists the files generated as part of the documentation project. Includes the directory structure and file names. ```text /workspace/home/output/ ├── 00-START-HERE.txt (⭐ Read this first!) ├── README.md ├── INDEX.md ├── MANIFEST.md ├── DELIVERY_SUMMARY.txt ├── api-reference/ │ ├── RNVoipPushNotification.md │ └── RNVoipPushNotificationManager-Native.md ├── types.md ├── configuration.md ├── architecture.md ├── errors.md └── integration-guide.md ``` -------------------------------- ### iOS System Architecture for VoIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/architecture.md This diagram illustrates the flow of VoIP push notifications on iOS, starting from APNs and PushKit, through the native AppDelegate, to the RNVoipPushNotificationManager native module, and finally to the JavaScript layer. ```text ┌─────────────────────────────────────────────────────────────────┐ │ iOS System (PushKit) │ │ │ │ • APNs sends VoIP push to device │ │ • iOS wakes app (or uses running instance) │ │ • PushKit framework delivers via delegate │ └─────────────────┬───────────────────────────────────────────────┘ │ │ PushKit Delegate Methods ▼ ┌─────────────────────────────────────────────────────────────────┐ │ AppDelegate (Native) │ │ ───────────────────────────────────────────────────────────── │ │ │ │ pushRegistry:didUpdatePushCredentials:forType: │ │ ├─ Calls: RNVoipPushNotificationManager.didUpdatePushCredentials │ │ │ │ pushRegistry: didReceiveIncomingPushWithPayload:forType:... │ │ ├─ Calls: RNVoipPushNotificationManager.addCompletionHandler │ │ ├─ Calls: RNVoipPushNotificationManager.didReceiveIncomingPush│ │ ├─ Calls: RNCallKeep.reportNewIncomingCall (iOS 13+) │ │ └─ Calls: completion() when JS finishes │ │ │ │ application:didFinishLaunchingWithOptions: │ │ └─ Calls: RNVoipPushNotificationManager.voipRegistration │ └─────────────────┬───────────────────────────────────────────────┘ │ │ RCTEventEmitter ▼ ┌─────────────────────────────────────────────────────────────────┐ │ RNVoipPushNotificationManager (Native Module) │ │ ───────────────────────────────────────────────────────────── │ │ │ │ • Singleton instance │ │ • Extends RCTEventEmitter + RCTBridgeModule │ │ • Caches: token, completion handlers, delayed events │ │ • Emits events: register, notification, didLoadWithEvents │ │ │ │ Static Methods: │ │ • voipRegistration() │ │ • didUpdatePushCredentials:forType: │ │ • didReceiveIncomingPushWithPayload:forType: │ │ • addCompletionHandler:completionHandler: │ │ • removeCompletionHandler: │ │ │ │ React Methods: │ │ • registerVoipToken() │ │ • onVoipNotificationCompleted: │ └─────────────────┬───────────────────────────────────────────────┘ │ │ React Native Bridge │ (NativeEventEmitter) ▼ ┌─────────────────────────────────────────────────────────────────┐ │ RNVoipPushNotification (JavaScript) │ │ ───────────────────────────────────────────────────────────── │ │ │ │ • Event listener management via _eventHandlers Map │ │ • Bridges JS ↔ Native via NativeEventEmitter │ │ • Wraps native module calls │ │ │ │ Static Methods: │ │ • addEventListener(type, handler) │ │ • removeEventListener(type) │ │ • registerVoipToken() │ │ • onVoipNotificationCompleted(uuid) │ │ │ │ Static Constants: │ │ • RNVoipPushRemoteNotificationsRegisteredEvent │ │ • RNVoipPushRemoteNotificationReceivedEvent │ │ • RNVoipPushDidLoadWithEvents │ └─────────────────┬───────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────────────┐ │ JavaScript Application │ │ │ │ • Event handlers registered via addEventListener │ ``` -------------------------------- ### Import VoIP Push Notification Module Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/configuration.md Import the necessary module at the root of your application or initialization file. ```javascript import VoipPushNotification from 'react-native-voip-push-notification'; ``` -------------------------------- ### Register VoIP Token with Server Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/errors.md Attach a 'register' event listener to send the VoIP token to your server. Includes basic error handling and retry logic suggestions. ```javascript VoipPushNotification.addEventListener('register', async (token) => { try { const response = await fetch('https://your-server/register-token', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ voipToken: token }), }); if (!response.ok) { console.error('Token registration failed:', response.status); // Retry logic } } catch (error) { console.error('Token registration error:', error); // Retry logic } }); ``` -------------------------------- ### Native Module Methods (Objective-C) Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Documentation for the native Objective-C methods exposed through the RNVoipPushNotificationManager. These methods handle core functionalities like VoIP registration, push credential updates, and receiving incoming push payloads. ```APIDOC ## RNVoipPushNotificationManager Native API (Objective-C) ### voipRegistration #### Description Handles the VoIP registration process. #### Method `+ voipRegistration` ### didUpdatePushCredentials:forType: #### Description Called when push credentials have been updated for a specific type. #### Method `- (void)didUpdatePushCredentials:(NSDictionary *)credentials forType:(NSString *)type` #### Parameters - **credentials** (NSDictionary) - Required - The updated push credentials. - **type** (NSString) - Required - The type of push credentials. ### didReceiveIncomingPushWithPayload:forType: #### Description Called when an incoming VoIP push notification payload is received. #### Method `- (void)didReceiveIncomingPushWithPayload:(NSDictionary *)payload forType:(NSString *)type` #### Parameters - **payload** (NSDictionary) - Required - The payload of the incoming push notification. - **type** (NSString) - Required - The type of the incoming push notification. ### addCompletionHandler:completionHandler: #### Description Adds a completion handler for processing notifications. #### Method `- (void)addCompletionHandler:(NSString *)uuid completionHandler:(RCTResponseSenderBlock)completionHandler` #### Parameters - **uuid** (NSString) - Required - The unique identifier for the notification. - **completionHandler** (RCTResponseSenderBlock) - Required - The block to execute upon completion. ### removeCompletionHandler: #### Description Removes a previously added completion handler. #### Method `- (void)removeCompletionHandler:(NSString *)uuid` #### Parameters - **uuid** (NSString) - Required - The unique identifier of the completion handler to remove. ### registerVoipToken (Instance/Exported) #### Description Exports the JavaScript `registerVoipToken` method to the native side. #### Method `- (void)registerVoipToken` ### onVoipNotificationCompleted: (Instance/Exported) #### Description Exports the JavaScript `onVoipNotificationCompleted` method to the native side. #### Method `- (void)onVoipNotificationCompleted:(NSString *)uuid` #### Parameters - **uuid** (NSString) - Required - The unique identifier of the completed notification. ``` -------------------------------- ### Error Handling Patterns Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Demonstrates various patterns for handling errors in VoIP push notification integration. ```javascript // Error handling patterns ``` -------------------------------- ### Error Handling Patterns Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Demonstrates various patterns for handling errors that may occur during VoIP push notification processing. ```JavaScript // Placeholder for error handling patterns. // This would show try-catch blocks, promise rejections, and specific error types. // Example: // try { // // ... code that might throw an error ... // } catch (error) { // console.error('An error occurred:', error); // // Handle the error appropriately // } ``` -------------------------------- ### Cached Event Processing Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Illustrates how the library handles events that are cached during application startup. ```JavaScript // Placeholder for cached event processing. // This would show how events received before the service is fully ready are managed. // Example: // RNVoipPushNotification.onVoipDidLoadWithEvents((events) => { // console.log('Initial cached events:', events); // // Process cached events // }); ``` -------------------------------- ### Register VoIP Token Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt Initiate the process to register the VoIP token with the native module. ```javascript registerVoipToken() ``` -------------------------------- ### Import VoipPushNotification in JavaScript Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt Import the main JavaScript module for interacting with the library's functionalities. ```javascript import VoipPushNotification from 'react-native-voip-push-notification' ``` -------------------------------- ### Native Module Access Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/00-START-HERE.txt The native module RNVoipPushNotificationManager is automatically available and does not require explicit import. ```plaintext Native: RNVoipPushNotificationManager (automatic, no import needed) ``` -------------------------------- ### Incoming Call Handling Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md This pattern is for apps that receive VoIP pushes and need to display call UI. It includes handling the 'notification' event to initialize the call and signal completion. ```javascript useEffect(() => { VoipPushNotification.addEventListener('notification', async (notification) => { const { uuid, callerName, handle } = notification; try { // Initialize VoIP service await initializeCall({ callerName, handle }); } finally { // Always signal completion VoipPushNotification.onVoipNotificationCompleted(uuid); } }); VoipPushNotification.registerVoipToken(); return () => VoipPushNotification.removeEventListener('notification'); }, []); ``` -------------------------------- ### Advanced VoIP Service Integration Patterns Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Showcases advanced patterns for integrating VoIP services, potentially including background modes and complex event handling. ```JavaScript // Placeholder for advanced integration patterns. // This could involve custom event handling, background task management, etc. // The specific code would depend on the advanced scenario being demonstrated. ``` -------------------------------- ### Register for VoIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/configuration.md Call the voipRegistration method in your application:didFinishLaunchingWithOptions: to register for VoIP push notifications as early as possible, ideally before the JavaScript bridge is initialized. ```objective-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Register VoIP push ASAP (recommended - registration before JS bridge) [RNVoipPushNotificationManager voipRegistration]; // ... rest of launch code RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@ ``` -------------------------------- ### RNVoipPushNotification Static Methods Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/README.md These are the static methods available on the RNVoipPushNotification module for managing listeners and initiating registration. ```APIDOC ## RNVoipPushNotification.addEventListener ### Description Attach a listener for 'register', 'notification', or 'didLoadWithEvents' events. ### Signature `(type, handler) => void` ### Parameters - **type** (string) - The type of event to listen for ('register', 'notification', 'didLoadWithEvents'). - **handler** (function) - The callback function to execute when the event is fired. ``` ```APIDOC ## RNVoipPushNotification.removeEventListener ### Description Remove a previously attached listener. ### Signature `(type) => void` ### Parameters - **type** (string) - The type of event listener to remove. ``` ```APIDOC ## RNVoipPushNotification.registerVoipToken ### Description Initiate the PushKit registration process for VoIP push notifications. This can be called directly from JavaScript. ### Signature `() => void` ``` ```APIDOC ## RNVoipPushNotification.onVoipNotificationCompleted ### Description Signal to the native side that the handling of an incoming VoIP push notification is complete. This is typically called after processing the notification payload. ### Signature `(uuid) => void` ### Parameters - **uuid** (string) - The unique identifier of the notification that has been completed. ``` -------------------------------- ### Import PushKit and RNVoipPushNotificationManager Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/configuration.md Import the necessary frameworks for PushKit and the React Native VoIP Push Notification manager into your AppDelegate.m file. ```objective-c #import #import "RNVoipPushNotificationManager.h" ``` -------------------------------- ### Native API Reference Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Documentation for the native iOS (Objective-C/Swift) API, including methods and configurations managed at the native level. ```APIDOC ## RNVoipPushNotificationManager-Native.md (Native API) This file provides documentation for the native API, primarily focusing on the iOS side (Objective-C/Swift). It covers native modules, methods, and configurations essential for integrating VoIP push notifications. ### Key Features: - Documentation for native methods and classes. - Configuration details specific to the native platform. - Integration points for native frameworks like CallKit and PushKit. Refer to `api-reference/RNVoipPushNotificationManager-Native.md` for detailed information. ``` -------------------------------- ### Minimum AppDelegate.m Integration for VOIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/INDEX.md Integrate the native module into your AppDelegate.m file to handle PushKit credentials and incoming push notifications. This includes registering for VOIP tokens and processing push payloads. ```objective-c #import #import "RNVoipPushNotificationManager.h" @interface AppDelegate : UIResponder - (void)application:didFinishLaunchingWithOptions: { [RNVoipPushNotificationManager voipRegistration]; // ... rest of setup } - (void)pushRegistry:didUpdatePushCredentials:forType: { [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:type]; } - (void)pushRegistry:didReceiveIncomingPushWithPayload:forType:withCompletionHandler: { [RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion]; [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:type]; [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:NO localizedCallerName:callerName fromPushKit:YES payload:nil]; } ``` -------------------------------- ### Modify AppDelegate.m for VoIP Push Notifications Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/README.md Add necessary imports and register for VoIP push notifications early in the application lifecycle. This is optional but recommended for performance. ```objective-c ... #import /* <------ add this line */ #import "RNVoipPushNotificationManager.h" /* <------ add this line */ ... @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; // ===== (THIS IS OPTIONAL BUT RECOMMENDED) ===== // --- register VoipPushNotification here ASAP rather than in JS. Doing this from the JS side may be too slow for some use cases // --- see: https://github.com/react-native-webrtc/react-native-voip-push-notification/issues/59#issuecomment-691685841 [RNVoipPushNotificationManager voipRegistration]; // ===== (THIS IS OPTIONAL BUT RECOMMENDED) ===== RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge moduleName:@"AppName" initialProperties:nil]; } ... ``` -------------------------------- ### Handle PushKit Delegate Methods in AppDelegate.m Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/README.md Implement delegate methods to handle updated push credentials, invalidation of push tokens, and incoming VoIP push payloads. This includes integrating with CallKit for incoming calls. ```objective-c /* Add PushKit delegate method */ // --- Handle updated push credentials - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type { // Register VoIP push token (a property of PKPushCredentials) with server [RNVoipPushNotificationManager didUpdatePushCredentials:credentials forType:(NSString *)type]; } - (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type { // --- The system calls this method when a previously provided push token is no longer valid for use. No action is necessary on your part to reregister the push type. Instead, use this method to notify your server not to send push notifications using the matching push token. } // --- Handle incoming pushes - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion { // --- NOTE: apple forced us to invoke callkit ASAP when we receive voip push // --- see: react-native-callkeep // --- Retrieve information from your voip push payload NSString *uuid = payload.dictionaryPayload[@"uuid"]; NSString *callerName = [NSString stringWithFormat:@"%@ (Connecting...)", payload.dictionaryPayload[@"callerName"]]; NSString *handle = payload.dictionaryPayload[@"handle"]; // --- this is optional, only required if you want to call `completion()` on the js side [RNVoipPushNotificationManager addCompletionHandler:uuid completionHandler:completion]; // --- Process the received push [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; // --- You should make sure to report to callkit BEFORE execute `completion()` [RNCallKeep reportNewIncomingCall:uuid handle:handle handleType:@"generic" hasVideo:false localizedCallerName:callerName fromPushKit: YES payload:nil]; // --- You don't need to call it if you stored `completion()` and will call it on the js side. completion(); } ... @end ``` -------------------------------- ### Implement PushKit Delegate in AppDelegate Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/errors.md Verify that your AppDelegate correctly implements the PushKit delegate method `didReceiveIncomingPushWithPayload:forType:` to handle incoming VoIP push notifications. This is crucial for the 'notification' event to fire. ```objectivec - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion { [RNVoipPushNotificationManager didReceiveIncomingPushWithPayload:payload forType:(NSString *)type]; } ``` -------------------------------- ### Design, Patterns, and Flows Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/DELIVERY_SUMMARY.txt Documentation explaining the library's architecture, design principles, and data flow patterns. ```APIDOC ## architecture.md This document delves into the architectural design of the React Native VoIP Push Notification library. It explains the underlying patterns, component interactions, and data flow sequences. ### Key Features: - ASCII architecture diagrams. - Event flow sequence diagrams. - Module dependency graph. - Advanced integration patterns. Refer to `architecture.md` for a deep dive into the library's design. ``` -------------------------------- ### Advanced VoIP Patterns Source: https://github.com/react-native-webrtc/react-native-voip-push-notification/blob/master/_autodocs/COMPLETION_REPORT.md Explores advanced patterns and configurations for VoIP push notifications. This section is for users needing more complex or specialized implementations. ```JavaScript // Advanced VoIP patterns // This snippet is a placeholder and would contain advanced JavaScript code examples for VoIP. ```