Replaces WebView call media on Android with a native LiveKit connection (iOS parity), so call audio survives backgrounding and the output can be switched to Speaker/Bluetooth/Earpiece — the #3 (missing speaker control) and #4 (background audio) items. Gated behind a new, default-off server flag ANDROID_NATIVE_MEDIA (independent of ANDROID_CALLS, which only governs the native ring). Flag off = today's WebView media, video included; flag on = native audio (video is Increment 2b, so enable it for VOICE testing first). No behavior change until flipped. Native (mobile/plugins/native-call/android): - build.gradle: add kotlin-android + io.livekit:livekit-android 2.29.2 (+ twilio audioswitch, coroutines) + JitPack repo; minSdk 24 (LiveKit floor). - CallMedia.kt: LiveKit Room wrapper — connect/mic/disconnect + AudioSwitchHandler routing (auto + selectDevice) and route-change events. - CallForegroundService.java: microphone-type foreground service for background audio (no-ops without RECORD_AUDIO so it never crashes the call). - NativeCallPlugin.java: real bodies for reportOutgoingCall/reconnectRoom/setMuted /endCall + new setAudioRoute/getAudioRoute; fires callConnected/callError/audioRoute. - AndroidManifest: FG service + FOREGROUND_SERVICE(_MICROPHONE)/RECORD_AUDIO/ MODIFY_AUDIO_SETTINGS/BLUETOOTH_CONNECT. - android-patch.js: bump the generated app minSdk to 24. Server: - config.js/routes.js: ANDROID_NATIVE_MEDIA → /api/meetings/config.androidNativeMedia. Web (home.html): - Android flips to the native-media path when androidNativeMedia is set; the existing outgoing/answer/mic/end code then drives the plugin unchanged. - Speaker button wired for Android native: cycles speaker/earpiece/bluetooth via NC.setAudioRoute and reflects the real output from the audioRoute event. Video stays no-op on the native path (Increment 2b). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
92 lines
5.2 KiB
JavaScript
92 lines
5.2 KiB
JavaScript
// Inject the runtime permissions the web UI needs into the Capacitor-generated AndroidManifest.xml.
|
|
// Run on Codemagic from the Android workflow:
|
|
// node mobile/scripts/android-patch.js mobile/android/app/src/main/AndroidManifest.xml
|
|
//
|
|
// WHY: mobile/android/ is gitignored (regenerated in CI by `cap add android`, same as iOS ios/). The
|
|
// freshly generated manifest only declares INTERNET, so without this the WebRTC calls in the web UI can't
|
|
// get camera/mic and Android 13+ never prompts for notifications. This adds the same permissions listed in
|
|
// mobile/resources/android-permissions.xml. (When the native-call Android plugin lands, it will contribute
|
|
// its own manifest entries via Capacitor manifest-merging; this only covers the app-level WebView perms.)
|
|
//
|
|
// TOLERANT: exits 0 and no-ops if anything is off, so it can NEVER fail the build. Idempotent (keyed on
|
|
// the bzcAndroidPerms marker), so re-runs never duplicate the block.
|
|
const fs = require('fs');
|
|
const p = process.argv[2];
|
|
if (!p || !fs.existsSync(p)) { console.log(' (AndroidManifest.xml not found — permission patch skipped)'); process.exit(0); }
|
|
try {
|
|
let s = fs.readFileSync(p, 'utf8');
|
|
|
|
// (0) LiveKit Android (native call media, Increment 2) requires a higher minSdk than Capacitor's default.
|
|
// Bump it in the generated variables.gradle so the library manifest merge holds (a library minSdk above the
|
|
// app's fails the build). variables.gradle sits at android/variables.gradle (3 dirs up from app/src/main).
|
|
try {
|
|
const path = require('path');
|
|
const varsPath = path.resolve(path.dirname(p), '..', '..', '..', 'variables.gradle');
|
|
if (fs.existsSync(varsPath)) {
|
|
let v = fs.readFileSync(varsPath, 'utf8');
|
|
const m = v.match(/minSdkVersion\s*=\s*(\d+)/);
|
|
if (m && parseInt(m[1], 10) < 24) {
|
|
v = v.replace(/minSdkVersion\s*=\s*\d+/, 'minSdkVersion = 24');
|
|
fs.writeFileSync(varsPath, v);
|
|
console.log(' minSdkVersion bumped to 24 (LiveKit Android floor)');
|
|
} else {
|
|
console.log(' minSdkVersion already >= 24 or not found — no bump');
|
|
}
|
|
} else {
|
|
console.log(' variables.gradle not found — minSdk bump skipped');
|
|
}
|
|
} catch (e) { console.log(' minSdk bump skipped:', e.message); }
|
|
|
|
// (1) Native-call FirebaseMessagingService swap. The native-call plugin declares its own MESSAGING_EVENT
|
|
// service (BzCallMessagingService) that handles call-wake data messages AND forwards regular push to Capacitor
|
|
// via super. Remove @capacitor/push-notifications' own MessagingService here — the APP manifest is the highest
|
|
// merge priority, so this reliably guarantees exactly one receiver. Needs the `tools` namespace + an insert
|
|
// inside <application>. Keyed on bzcCallSvcRemove so re-runs never duplicate it.
|
|
if (!s.includes('bzcCallSvcRemove')) {
|
|
// Ensure xmlns:tools is declared on <manifest> (tools:node="remove" needs it).
|
|
if (!/<manifest[^>]*xmlns:tools=/.test(s)) {
|
|
s = s.replace(/<manifest(\s)/, '<manifest xmlns:tools="http://schemas.android.com/tools"$1');
|
|
}
|
|
const removal = [
|
|
'',
|
|
' <!-- bzcCallSvcRemove: the native-call plugin\'s BzCallMessagingService replaces this one (it forwards regular push via super) -->',
|
|
' <service android:name="com.capacitorjs.plugins.pushnotifications.MessagingService" tools:node="remove" />',
|
|
' ',
|
|
].join('\n');
|
|
const before = s;
|
|
s = s.replace(/<\/application>/, removal + '</application>');
|
|
if (s !== before) console.log(' Capacitor MessagingService removal injected (native-call takes over MESSAGING_EVENT)');
|
|
else console.log(' could not find </application> — MessagingService removal skipped');
|
|
fs.writeFileSync(p, s);
|
|
} else {
|
|
console.log(' Capacitor MessagingService removal already present');
|
|
}
|
|
|
|
// (2) WebView permissions.
|
|
if (s.includes('bzcAndroidPerms') || s.includes('android.permission.RECORD_AUDIO')) {
|
|
console.log(' Android permissions already present'); process.exit(0);
|
|
}
|
|
const block = [
|
|
'',
|
|
' <!-- bzcAndroidPerms: permissions the Biz Connect web UI needs (see mobile/resources/android-permissions.xml) -->',
|
|
' <!-- Push notifications: Android 13 (API 33)+ shows a runtime prompt -->',
|
|
' <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />',
|
|
' <!-- Voice / video calls + camera, used by the WebRTC features in the web UI -->',
|
|
' <uses-permission android:name="android.permission.CAMERA" />',
|
|
' <uses-permission android:name="android.permission.RECORD_AUDIO" />',
|
|
' <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />',
|
|
' <!-- Camera is optional hardware (tablets without one can still install) -->',
|
|
' <uses-feature android:name="android.hardware.camera" android:required="false" />',
|
|
'',
|
|
].join('\n');
|
|
const orig = s;
|
|
// Insert directly before the closing </manifest> tag.
|
|
s = s.replace(/<\/manifest>\s*$/, block + '</manifest>\n');
|
|
if (s === orig) { console.log(' could not find </manifest> — permission patch skipped'); process.exit(0); }
|
|
fs.writeFileSync(p, s);
|
|
console.log(' Android permissions injected into ' + p);
|
|
} catch (e) {
|
|
console.log(' Android permission patch skipped:', e.message);
|
|
}
|
|
process.exit(0);
|