rns-nativecall 0.4.1 → 0.4.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.
- package/app.plugin.js +2 -9
- package/package.json +1 -1
- package/withCallNativeConfig.js +1 -0
- package/withCallPermissions.js +2 -1
- package/withNativeCallVoip.js +62 -106
package/app.plugin.js
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
///app.plugin.js
|
|
2
|
-
const { withPlugins } = require('@expo/config-plugins');
|
|
3
2
|
const withNativeCallVoip = require('./withNativeCallVoip');
|
|
4
|
-
const withCallNativeConfig = require('./withCallNativeConfig');
|
|
5
|
-
const withCallPermissions = require('./withCallPermissions');
|
|
6
3
|
|
|
7
|
-
module.exports = function (config
|
|
8
|
-
return
|
|
9
|
-
[withNativeCallVoip, props],
|
|
10
|
-
[withCallNativeConfig, props],
|
|
11
|
-
[withCallPermissions, props],
|
|
12
|
-
]);
|
|
4
|
+
module.exports = function (config) {
|
|
5
|
+
return withNativeCallVoip(config);
|
|
13
6
|
};
|
package/package.json
CHANGED
package/withCallNativeConfig.js
CHANGED
package/withCallPermissions.js
CHANGED
package/withNativeCallVoip.js
CHANGED
|
@@ -1,59 +1,11 @@
|
|
|
1
1
|
const { withAndroidManifest, withInfoPlist, withPlugins, withMainActivity } = require('@expo/config-plugins');
|
|
2
2
|
|
|
3
|
-
/** 1. ANDROID MAIN ACTIVITY MOD **/
|
|
4
|
-
// function withMainActivityDataFix(config) {
|
|
5
|
-
// return withMainActivity(config, (config) => {
|
|
6
|
-
// let contents = config.modResults.contents;
|
|
7
|
-
|
|
8
|
-
// // 1. Ensure necessary Imports are present
|
|
9
|
-
// if (!contents.includes('import android.content.Intent')) {
|
|
10
|
-
// contents = contents.replace(/package .*/, (match) => `${match}\n\nimport android.content.Intent`);
|
|
11
|
-
// }
|
|
12
|
-
// if (!contents.includes('import android.os.Bundle')) {
|
|
13
|
-
// contents = contents.replace(/package .*/, (match) => `${match}\n\nimport android.os.Bundle`);
|
|
14
|
-
// }
|
|
15
|
-
|
|
16
|
-
// // 2. Define the code blocks
|
|
17
|
-
// const onNewIntentCode = `
|
|
18
|
-
// override fun onNewIntent(intent: Intent) {
|
|
19
|
-
// super.onNewIntent(intent)
|
|
20
|
-
// setIntent(intent)
|
|
21
|
-
// }
|
|
22
|
-
// `;
|
|
23
|
-
|
|
24
|
-
// const onCreateCode = `
|
|
25
|
-
// override fun onCreate(savedInstanceState: Bundle?) {
|
|
26
|
-
// super.onCreate(savedInstanceState)
|
|
27
|
-
// // If woken up silently, move to back to prevent UI flicker
|
|
28
|
-
// if (intent.getBooleanExtra("background_wake", false)) {
|
|
29
|
-
// moveTaskToBack(true)
|
|
30
|
-
// }
|
|
31
|
-
// }
|
|
32
|
-
// `;
|
|
33
|
-
|
|
34
|
-
// // 3. Insert the codes before the last closing brace of the class
|
|
35
|
-
// if (!contents.includes('override fun onNewIntent')) {
|
|
36
|
-
// const lastBraceIndex = contents.lastIndexOf('}');
|
|
37
|
-
// contents = contents.slice(0, lastBraceIndex) + onNewIntentCode + contents.slice(lastBraceIndex);
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// if (!contents.includes('override fun onCreate')) {
|
|
41
|
-
// // Re-calculate lastBraceIndex because contents string has changed
|
|
42
|
-
// const lastBraceIndex = contents.lastIndexOf('}');
|
|
43
|
-
// contents = contents.slice(0, lastBraceIndex) + onCreateCode + contents.slice(lastBraceIndex);
|
|
44
|
-
// }
|
|
45
|
-
|
|
46
|
-
// config.modResults.contents = contents;
|
|
47
|
-
// return config;
|
|
48
|
-
// });
|
|
49
|
-
// }
|
|
50
|
-
|
|
51
3
|
/** 1. ANDROID MAIN ACTIVITY MOD **/
|
|
52
4
|
function withMainActivityDataFix(config) {
|
|
53
5
|
return withMainActivity(config, (config) => {
|
|
54
6
|
let contents = config.modResults.contents;
|
|
55
7
|
|
|
56
|
-
// 1. Add
|
|
8
|
+
// 1. Add required imports
|
|
57
9
|
const imports = [
|
|
58
10
|
'import android.view.WindowManager',
|
|
59
11
|
'import android.os.Build',
|
|
@@ -66,11 +18,9 @@ function withMainActivityDataFix(config) {
|
|
|
66
18
|
}
|
|
67
19
|
});
|
|
68
20
|
|
|
69
|
-
// 2.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
super.onCreate(savedInstanceState)
|
|
73
|
-
if (intent?.action?.startsWith("ACTION_SHOW_UI") == true || intent?.getBooleanExtra("background_wake", false) == true) {
|
|
21
|
+
// 2. Add the Lockscreen / Wake logic inside onCreate
|
|
22
|
+
const wakeLogic = `super.onCreate(savedInstanceState)
|
|
23
|
+
if (intent?.getBooleanExtra("navigatingToCall", false) == true) {
|
|
74
24
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
|
75
25
|
setShowWhenLocked(true)
|
|
76
26
|
setTurnScreenOn(true)
|
|
@@ -80,20 +30,16 @@ function withMainActivityDataFix(config) {
|
|
|
80
30
|
}`;
|
|
81
31
|
|
|
82
32
|
if (!contents.includes('setShowWhenLocked')) {
|
|
83
|
-
contents = contents.replace(/super\.onCreate\(.*\)/,
|
|
33
|
+
contents = contents.replace(/super\.onCreate\(.*\)/, wakeLogic);
|
|
84
34
|
}
|
|
85
35
|
|
|
86
|
-
// 3.
|
|
87
|
-
// Modern Expo handles the Wrapper correctly; your regex was breaking the Kotlin syntax.
|
|
88
|
-
|
|
89
|
-
// 4. Ensure onNewIntent exists
|
|
36
|
+
// 3. Ensure onNewIntent is present
|
|
90
37
|
if (!contents.includes('override fun onNewIntent')) {
|
|
91
38
|
const onNewIntentCode = `
|
|
92
39
|
override fun onNewIntent(intent: Intent) {
|
|
93
40
|
super.onNewIntent(intent)
|
|
94
41
|
setIntent(intent)
|
|
95
42
|
}\n`;
|
|
96
|
-
// Insert it before the last closing brace of the class
|
|
97
43
|
const lastBraceIndex = contents.lastIndexOf('}');
|
|
98
44
|
contents = contents.slice(0, lastBraceIndex) + onNewIntentCode + contents.slice(lastBraceIndex);
|
|
99
45
|
}
|
|
@@ -106,73 +52,83 @@ function withMainActivityDataFix(config) {
|
|
|
106
52
|
/** 2. ANDROID MANIFEST CONFIG **/
|
|
107
53
|
function withAndroidConfig(config) {
|
|
108
54
|
return withAndroidManifest(config, (config) => {
|
|
109
|
-
const
|
|
110
|
-
const
|
|
55
|
+
const androidManifest = config.modResults.manifest;
|
|
56
|
+
const mainApplication = androidManifest.application[0];
|
|
57
|
+
|
|
58
|
+
// 1. Configure MainActivity flags in Manifest
|
|
59
|
+
const mainActivity = mainApplication.activity.find(a => a.$["android:name"] === ".MainActivity");
|
|
60
|
+
if (mainActivity) {
|
|
61
|
+
mainActivity.$["android:showWhenLocked"] = "true";
|
|
62
|
+
mainActivity.$["android:turnScreenOn"] = "true";
|
|
63
|
+
}
|
|
111
64
|
|
|
112
|
-
//
|
|
65
|
+
// 2. Unified Permissions
|
|
113
66
|
const permissions = [
|
|
114
67
|
'android.permission.USE_FULL_SCREEN_INTENT',
|
|
115
68
|
'android.permission.VIBRATE',
|
|
116
69
|
'android.permission.FOREGROUND_SERVICE',
|
|
117
|
-
'android.permission.FOREGROUND_SERVICE_PHONE_CALL',
|
|
70
|
+
'android.permission.FOREGROUND_SERVICE_PHONE_CALL',
|
|
118
71
|
'android.permission.POST_NOTIFICATIONS',
|
|
119
72
|
'android.permission.WAKE_LOCK',
|
|
120
73
|
'android.permission.DISABLE_KEYGUARD',
|
|
121
|
-
'android.permission.RECEIVE_BOOT_COMPLETED'
|
|
74
|
+
'android.permission.RECEIVE_BOOT_COMPLETED'
|
|
122
75
|
];
|
|
123
76
|
|
|
124
|
-
|
|
77
|
+
androidManifest['uses-permission'] = androidManifest['uses-permission'] || [];
|
|
125
78
|
permissions.forEach((perm) => {
|
|
126
|
-
if (!
|
|
127
|
-
|
|
79
|
+
if (!androidManifest['uses-permission'].some((p) => p.$['android:name'] === perm)) {
|
|
80
|
+
androidManifest['uses-permission'].push({ $: { 'android:name': perm } });
|
|
128
81
|
}
|
|
129
82
|
});
|
|
130
83
|
|
|
131
|
-
//
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
// 3. Service Setup (CRITICAL UPDATES FOR ANDROID 14)
|
|
136
|
-
application.service = application.service || [];
|
|
137
|
-
|
|
138
|
-
// Add Firebase Messaging Service
|
|
139
|
-
const firebaseServiceName = 'com.rnsnativecall.CallMessagingService';
|
|
140
|
-
if (!application.service.some(s => s.$['android:name'] === firebaseServiceName)) {
|
|
141
|
-
application.service.push({
|
|
84
|
+
// 3. AcceptCallActivity Registration
|
|
85
|
+
mainApplication.activity = mainApplication.activity || [];
|
|
86
|
+
if (!mainApplication.activity.some(a => a.$['android:name'] === 'com.rnsnativecall.AcceptCallActivity')) {
|
|
87
|
+
mainApplication.activity.push({
|
|
142
88
|
$: {
|
|
143
|
-
'android:name':
|
|
89
|
+
'android:name': 'com.rnsnativecall.AcceptCallActivity',
|
|
90
|
+
'android:theme': '@android:style/Theme.Translucent.NoTitleBar',
|
|
144
91
|
'android:exported': 'false',
|
|
145
|
-
|
|
146
|
-
'android:
|
|
147
|
-
}
|
|
148
|
-
'intent-filter': [{ action: [{ $: { 'android:name': 'com.google.firebase.MESSAGING_EVENT' } }] }]
|
|
92
|
+
'android:showWhenLocked': 'true',
|
|
93
|
+
'android:turnScreenOn': 'true'
|
|
94
|
+
}
|
|
149
95
|
});
|
|
150
96
|
}
|
|
151
97
|
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
98
|
+
// 4. Service Setup
|
|
99
|
+
mainApplication.service = mainApplication.service || [];
|
|
100
|
+
|
|
101
|
+
const services = [
|
|
102
|
+
{
|
|
103
|
+
name: 'com.rnsnativecall.CallMessagingService',
|
|
104
|
+
intentFilter: 'com.google.firebase.MESSAGING_EVENT'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'com.rnsnativecall.CallHeadlessTask'
|
|
108
|
+
}
|
|
109
|
+
];
|
|
110
|
+
|
|
111
|
+
services.forEach(svc => {
|
|
112
|
+
if (!mainApplication.service.some(s => s.$['android:name'] === svc.name)) {
|
|
113
|
+
const serviceEntry = {
|
|
114
|
+
$: {
|
|
115
|
+
'android:name': svc.name,
|
|
116
|
+
'android:exported': 'false',
|
|
117
|
+
'android:foregroundServiceType': 'phoneCall'
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
if (svc.intentFilter) {
|
|
121
|
+
serviceEntry['intent-filter'] = [{ action: [{ $: { 'android:name': svc.intentFilter } }] }];
|
|
161
122
|
}
|
|
162
|
-
|
|
163
|
-
|
|
123
|
+
mainApplication.service.push(serviceEntry);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
164
126
|
|
|
165
|
-
//
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
$: { 'android:name': receiverName, 'android:exported': 'false' },
|
|
171
|
-
'intent-filter': [{
|
|
172
|
-
action: [
|
|
173
|
-
{ $: { 'android:name': 'android.intent.action.BOOT_COMPLETED' } }
|
|
174
|
-
]
|
|
175
|
-
}]
|
|
127
|
+
// 5. Receiver Setup
|
|
128
|
+
mainApplication.receiver = mainApplication.receiver || [];
|
|
129
|
+
if (!mainApplication.receiver.some(r => r.$['android:name'] === 'com.rnsnativecall.CallActionReceiver')) {
|
|
130
|
+
mainApplication.receiver.push({
|
|
131
|
+
$: { 'android:name': 'com.rnsnativecall.CallActionReceiver', 'android:exported': 'false' }
|
|
176
132
|
});
|
|
177
133
|
}
|
|
178
134
|
|