rns-nativecall 0.1.0 → 0.1.2

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.
@@ -50,4 +50,5 @@ dependencies {
50
50
 
51
51
  // Note: Telecom APIs (ConnectionService) are part of the standard Android SDK,
52
52
  // so no extra external dependencies are needed for them.
53
+ implementation "com.google.firebase:firebase-messaging:23.4.0"
53
54
  }
@@ -0,0 +1,14 @@
1
+ ///
2
+ // Users/bush/Desktop/Packages/rns-nativecall/android/src/main/java/com/rnsnativecall/CallMessagingService.kt
3
+ package com.rnsnativecall
4
+
5
+ import com.google.firebase.messaging.FirebaseMessagingService
6
+ import com.google.firebase.messaging.RemoteMessage
7
+
8
+ class CallMessagingService : FirebaseMessagingService() {
9
+
10
+ override fun onMessageReceived(remoteMessage: RemoteMessage) {
11
+ // Directly forward to your native call manager
12
+ NativeCallManager.handleIncomingPush(applicationContext, remoteMessage.data)
13
+ }
14
+ }
@@ -0,0 +1,56 @@
1
+ ///
2
+ // Users/bush/Desktop/Packages/rns-nativecall/android/src/main/java/com/rnsnativecall/NativeCallManager.kt
3
+ package com.rnsnativecall
4
+
5
+ import android.content.ComponentName
6
+ import android.content.Context
7
+ import android.net.Uri
8
+ import android.os.Bundle
9
+ import android.telecom.PhoneAccountHandle
10
+ import android.telecom.TelecomManager
11
+
12
+ object NativeCallManager {
13
+
14
+ fun handleIncomingPush(context: Context, data: Map<String, String>) {
15
+ val uuid = data["callId"] ?: return
16
+ val handle = data["from"] ?: "Unknown"
17
+ val name = data["name"] ?: handle
18
+ val hasVideo = data["hasVideo"]?.toBoolean() ?: false
19
+ val playRing = data["playRing"]?.toBoolean() ?: true
20
+
21
+ val telecomManager = context.getSystemService(Context.TELECOM_SERVICE) as TelecomManager
22
+ val phoneAccountHandle = getPhoneAccountHandle(context)
23
+
24
+ // In NativeCallManager.kt
25
+ val extras =
26
+ Bundle().apply {
27
+ putParcelable(
28
+ TelecomManager.EXTRA_INCOMING_CALL_ADDRESS,
29
+ Uri.fromParts("sip", handle, null)
30
+ )
31
+ putString("EXTRA_CALL_UUID", uuid)
32
+ putString(
33
+ TelecomManager.EXTRA_CALL_SUBJECT,
34
+ name
35
+ ) // Use system constant for name
36
+ putBoolean("EXTRA_PLAY_RING", playRing)
37
+
38
+ // IMPORTANT: Android uses specific integers for video state, not just a boolean
39
+ val videoState =
40
+ if (hasVideo) VideoProfile.STATE_BIDIRECTIONAL
41
+ else VideoProfile.STATE_AUDIO_ONLY
42
+ putInt(TelecomManager.EXTRA_START_CALL_WITH_VIDEO_STATE, videoState)
43
+ }
44
+
45
+ try {
46
+ telecomManager.addNewIncomingCall(phoneAccountHandle, extras)
47
+ } catch (e: Exception) {
48
+ e.printStackTrace()
49
+ }
50
+ }
51
+
52
+ private fun getPhoneAccountHandle(context: Context): PhoneAccountHandle {
53
+ val componentName = ComponentName(context, MyConnectionService::class.java)
54
+ return PhoneAccountHandle(componentName, "${context.packageName}.voip")
55
+ }
56
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rns-nativecall",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "RNS nativecall component with native Android/iOS for handling native call ui, when app is not open or open.",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,4 +1,3 @@
1
- ///Users/bush/Desktop/Apps/Raiidr/package/withNativeCallVoip.js
2
1
  const { withAndroidManifest, withInfoPlist, withPlugins } = require('@expo/config-plugins');
3
2
 
4
3
  /**
@@ -27,13 +26,14 @@ function withAndroidConfig(config) {
27
26
  const application = manifest.manifest.application[0];
28
27
  application.service = application.service || [];
29
28
 
30
- const serviceName = 'com.rnsnativecall.MyConnectionService';
31
- const existingService = application.service.find((s) => s.$['android:name'] === serviceName);
29
+ // MyConnectionService
30
+ const connectionServiceName = 'com.rnsnativecall.MyConnectionService';
31
+ const existingConnectionService = application.service.find((s) => s.$['android:name'] === connectionServiceName);
32
32
 
33
- if (!existingService) {
33
+ if (!existingConnectionService) {
34
34
  application.service.push({
35
35
  $: {
36
- 'android:name': serviceName,
36
+ 'android:name': connectionServiceName,
37
37
  'android:permission': 'android.permission.BIND_CONNECTION_SERVICE',
38
38
  'android:exported': 'true',
39
39
  },
@@ -45,6 +45,24 @@ function withAndroidConfig(config) {
45
45
  });
46
46
  }
47
47
 
48
+ // CallMessagingService (FCM)
49
+ const fcmServiceName = 'com.rnsnativecall.CallMessagingService';
50
+ const existingFCMService = application.service.find((s) => s.$['android:name'] === fcmServiceName);
51
+
52
+ if (!existingFCMService) {
53
+ application.service.push({
54
+ $: {
55
+ 'android:name': fcmServiceName,
56
+ 'android:exported': 'false',
57
+ },
58
+ 'intent-filter': [
59
+ {
60
+ action: [{ $: { 'android:name': 'com.google.firebase.MESSAGING_EVENT' } }]
61
+ }
62
+ ]
63
+ });
64
+ }
65
+
48
66
  return config;
49
67
  });
50
68
  }
@@ -68,7 +86,6 @@ function withIosConfig(config) {
68
86
  });
69
87
 
70
88
  // 2. Dynamic Microphone Description
71
- // config.name pulls the name from the user's app.json automatically
72
89
  const appName = config.name || 'this app';
73
90
  infoPlist.NSMicrophoneUsageDescription =
74
91
  infoPlist.NSMicrophoneUsageDescription || `Allow ${appName} to access your microphone for calls.`;
@@ -82,4 +99,4 @@ module.exports = (config) => {
82
99
  withAndroidConfig,
83
100
  withIosConfig,
84
101
  ]);
85
- };
102
+ };