@poolse/native 0.0.0-stage → 3.0.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.
- package/CHANGELOG.md +25 -0
- package/LICENSE +206 -0
- package/README.md +148 -2
- package/android/build.gradle +58 -0
- package/android/consumer-rules.pro +11 -0
- package/android/src/main/AndroidManifest.xml +46 -0
- package/android/src/main/java/dev/poolse/callcore/CallCoreRuntime.kt +540 -0
- package/android/src/main/java/dev/poolse/callcore/CallMachine.kt +492 -0
- package/android/src/main/java/dev/poolse/callcore/Ports.kt +132 -0
- package/android/src/main/java/dev/poolse/callcore/android/AndroidRingSurface.kt +383 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallActionReceiver.kt +45 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallCore.kt +578 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallForegroundService.kt +294 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallHttpClient.kt +207 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallMessagingService.kt +161 -0
- package/android/src/main/java/dev/poolse/callcore/android/CallVideo.kt +36 -0
- package/android/src/main/java/dev/poolse/callcore/android/HandlerTimerPort.kt +42 -0
- package/android/src/main/java/dev/poolse/callcore/android/IncomingCallActivity.kt +314 -0
- package/android/src/main/java/dev/poolse/callcore/android/MessageNotifications.kt +353 -0
- package/android/src/main/java/dev/poolse/callcore/android/MissedCallNotification.kt +103 -0
- package/android/src/main/java/dev/poolse/callcore/android/RingBundle.kt +42 -0
- package/android/src/main/java/dev/poolse/callcore/android/SnapshotJson.kt +99 -0
- package/android/src/main/java/expo/modules/poolsecalls/CallLockscreen.kt +42 -0
- package/android/src/main/java/expo/modules/poolsecalls/CallPictureInPicture.kt +92 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallVideoView.kt +64 -0
- package/android/src/main/java/expo/modules/poolsecalls/PoolseCallsModule.kt +205 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitMediaPort.kt +594 -0
- package/android/src/main/livekit/java/dev/poolse/callcore/livekit/LiveKitVideoSurface.kt +107 -0
- package/android/src/test/java/dev/poolse/callcore/android/CallHttpClientTest.kt +61 -0
- package/app.plugin.js +5 -0
- package/dist/index.cjs +197 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +313 -0
- package/dist/index.d.ts +313 -0
- package/dist/index.js +161 -0
- package/dist/index.js.map +1 -0
- package/expo-module.config.json +11 -0
- package/ios/Core/CallCoreRuntime.swift +543 -0
- package/ios/Core/CallHttpClient.swift +213 -0
- package/ios/Core/CallMachine.swift +394 -0
- package/ios/Core/PORTS_READY.md +93 -0
- package/ios/Core/Ports.swift +238 -0
- package/ios/Core/SnapshotEncoding.swift +122 -0
- package/ios/Module/PoolseCallVideoView.swift +70 -0
- package/ios/Module/PoolseCallsAppDelegateSubscriber.swift +16 -0
- package/ios/Module/PoolseCallsModule.swift +150 -0
- package/ios/Platform/CallCore.swift +623 -0
- package/ios/Platform/CallKitController.swift +326 -0
- package/ios/Platform/CallPictureInPicture.swift +145 -0
- package/ios/Platform/LiveKitMediaPort.swift +798 -0
- package/ios/Platform/LiveKitVideoSurface.swift +68 -0
- package/ios/Platform/MessageNotifications.swift +163 -0
- package/ios/Platform/Ringback.swift +61 -0
- package/ios/Platform/VoipPush.swift +174 -0
- package/ios/PoolseCalls.podspec +68 -0
- package/package.json +53 -4
- package/plugin/index.js +42 -0
- package/plugin/package.json +1 -0
- package/plugin/withCallDelegate.js +35 -0
- package/plugin/withLockscreenCalls.js +84 -0
- package/plugin/withNativeCallMedia.js +19 -0
- package/plugin/withPictureInPicture.js +28 -0
- package/plugin/withRingback.js +86 -0
- package/src/expo-modules-core.d.ts +16 -0
- package/src/index.ts +564 -0
- package/src/react-shims.d.ts +22 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Let MainActivity show itself over the keyguard when
|
|
3
|
+
* it is being launched for a call.
|
|
4
|
+
*
|
|
5
|
+
* Two signals ask for it, both from @poolse/native:
|
|
6
|
+
* * the `poolse_launch_call` extra the call core puts on the intent
|
|
7
|
+
* whenever it brings the app forward — answering from the lock
|
|
8
|
+
* screen or the notification;
|
|
9
|
+
* * `CallLockscreen.showOverKeyguard`, set by setShowOnLockscreen
|
|
10
|
+
* while a call is live, so an activity recreated mid-call keeps it.
|
|
11
|
+
*
|
|
12
|
+
* The expo-modules lifecycle listener is the polite way to do this, but
|
|
13
|
+
* its registration rides autolinking's generated package list, which
|
|
14
|
+
* proved cache-sensitive — a build where it is missing silently
|
|
15
|
+
* reintroduces "unlock to answer". So this patches the generated
|
|
16
|
+
* MainActivity directly, which no cache can skip.
|
|
17
|
+
*
|
|
18
|
+
* Both onCreate AND onNewIntent: MainActivity is singleTask, so a call
|
|
19
|
+
* answered while the app is already running arrives as a new intent on
|
|
20
|
+
* the existing activity, never through onCreate. Checking only onCreate
|
|
21
|
+
* left the app behind the lock screen with the audio already flowing.
|
|
22
|
+
*
|
|
23
|
+
* Only show-when-locked, never dismiss-keyguard: dismissing a secure
|
|
24
|
+
* lock would throw up the PIN bouncer, and a call must not demand an
|
|
25
|
+
* unlock. JS clears the flag when the call ends (setShowOnLockscreen).
|
|
26
|
+
*/
|
|
27
|
+
const { withMainActivity } = require('expo/config-plugins');
|
|
28
|
+
|
|
29
|
+
const MARKER = 'poolse_launch_call';
|
|
30
|
+
|
|
31
|
+
const ON_CREATE_SNIPPET = `
|
|
32
|
+
// Launched for a call: show over the lock screen — answering must
|
|
33
|
+
// never demand an unlock. (See @poolse/native/plugin.)
|
|
34
|
+
showOverKeyguardIfCall(intent)
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const MEMBERS_SNIPPET = `
|
|
38
|
+
override fun onNewIntent(intent: android.content.Intent) {
|
|
39
|
+
super.onNewIntent(intent)
|
|
40
|
+
setIntent(intent)
|
|
41
|
+
showOverKeyguardIfCall(intent)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private fun showOverKeyguardIfCall(intent: android.content.Intent?) {
|
|
45
|
+
val forCall = expo.modules.poolsecalls.CallLockscreen.showOverKeyguard ||
|
|
46
|
+
intent?.hasExtra("${MARKER}") == true
|
|
47
|
+
if (forCall && android.os.Build.VERSION.SDK_INT >= 27) {
|
|
48
|
+
setShowWhenLocked(true)
|
|
49
|
+
setTurnScreenOn(true)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
|
|
54
|
+
// The block the previous version of this plugin injected; replaced on
|
|
55
|
+
// rebuild of an already-patched MainActivity.
|
|
56
|
+
const LEGACY_BLOCK =
|
|
57
|
+
/\n\s*\/\/ Launched for a call: show over the lock screen[\s\S]*?setTurnScreenOn\(true\)\n\s*\}\n\s*\}\n/;
|
|
58
|
+
|
|
59
|
+
module.exports = function withLockscreenCalls(config) {
|
|
60
|
+
return withMainActivity(config, (cfg) => {
|
|
61
|
+
let src = cfg.modResults.contents;
|
|
62
|
+
if (src.includes(MARKER)) return cfg;
|
|
63
|
+
|
|
64
|
+
src = src.replace(LEGACY_BLOCK, '\n');
|
|
65
|
+
|
|
66
|
+
const onCreateAnchor = /super\.onCreate\(null\)\n/;
|
|
67
|
+
if (!onCreateAnchor.test(src)) {
|
|
68
|
+
throw new Error('withLockscreenCalls: could not find super.onCreate(null) in MainActivity');
|
|
69
|
+
}
|
|
70
|
+
src = src.replace(onCreateAnchor, (m) => m + ON_CREATE_SNIPPET);
|
|
71
|
+
|
|
72
|
+
// Before getMainComponentName's doc comment, so that comment stays
|
|
73
|
+
// attached to its function; the bare declaration is the fallback.
|
|
74
|
+
const memberAnchor =
|
|
75
|
+
/\n \/\*\*\n \* Returns the name of the main component|\n override fun getMainComponentName\(\)/;
|
|
76
|
+
if (!memberAnchor.test(src)) {
|
|
77
|
+
throw new Error('withLockscreenCalls: could not find getMainComponentName in MainActivity');
|
|
78
|
+
}
|
|
79
|
+
src = src.replace(memberAnchor, (m) => MEMBERS_SNIPPET + m);
|
|
80
|
+
|
|
81
|
+
cfg.modResults.contents = src;
|
|
82
|
+
return cfg;
|
|
83
|
+
});
|
|
84
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turn on the native call core's LiveKit media adapter.
|
|
3
|
+
*
|
|
4
|
+
* The core ships its LiveKit MediaPort (io.livekit:livekit-android) in an
|
|
5
|
+
* opt-in source set, gated on the `poolse.livekit` gradle property, so
|
|
6
|
+
* the library carries no SFU dependency unless an app asks for it. This
|
|
7
|
+
* sets that property; without it calls ring and connect with no audio.
|
|
8
|
+
*/
|
|
9
|
+
const { withGradleProperties } = require('expo/config-plugins');
|
|
10
|
+
|
|
11
|
+
module.exports = function withNativeCallMedia(config) {
|
|
12
|
+
return withGradleProperties(config, (cfg) => {
|
|
13
|
+
cfg.modResults = cfg.modResults.filter(
|
|
14
|
+
(p) => !(p.type === 'property' && p.key === 'poolse.livekit'),
|
|
15
|
+
);
|
|
16
|
+
cfg.modResults.push({ type: 'property', key: 'poolse.livekit', value: 'true' });
|
|
17
|
+
return cfg;
|
|
18
|
+
});
|
|
19
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Let the main activity float as a picture-in-picture
|
|
3
|
+
* window during a video call (`@poolse/native`'
|
|
4
|
+
* setPictureInPictureEnabled).
|
|
5
|
+
*
|
|
6
|
+
* Android only lets an activity that declares support enter PiP, and
|
|
7
|
+
* resizing into the window is a configuration change: without
|
|
8
|
+
* smallestScreenSize the activity would be destroyed and recreated as
|
|
9
|
+
* it shrinks — the call keeps going, but the app restarts its UI.
|
|
10
|
+
*/
|
|
11
|
+
const { withAndroidManifest } = require('expo/config-plugins');
|
|
12
|
+
|
|
13
|
+
const NEEDED = ['screenSize', 'smallestScreenSize', 'screenLayout', 'orientation'];
|
|
14
|
+
|
|
15
|
+
module.exports = function withPictureInPicture(config) {
|
|
16
|
+
return withAndroidManifest(config, (cfg) => {
|
|
17
|
+
const app = cfg.modResults.manifest.application?.[0];
|
|
18
|
+
const main = app?.activity?.find((a) => a.$?.['android:name'] === '.MainActivity');
|
|
19
|
+
if (!main) throw new Error('withPictureInPicture: no .MainActivity in AndroidManifest');
|
|
20
|
+
|
|
21
|
+
main.$['android:supportsPictureInPicture'] = 'true';
|
|
22
|
+
main.$['android:resizeableActivity'] = 'true';
|
|
23
|
+
const changes = new Set((main.$['android:configChanges'] ?? '').split('|').filter(Boolean));
|
|
24
|
+
for (const c of NEEDED) changes.add(c);
|
|
25
|
+
main.$['android:configChanges'] = [...changes].join('|');
|
|
26
|
+
return cfg;
|
|
27
|
+
});
|
|
28
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config plugin: ship the ringback tone — what the caller hears while the
|
|
3
|
+
* other phone rings — in both app bundles.
|
|
4
|
+
*
|
|
5
|
+
* The native core plays it by resource name: `configure({ ringback })`
|
|
6
|
+
* with the file's base name finds the iOS bundle's `<name>.<ext>` and
|
|
7
|
+
* Android's `res/raw/<name>`. Android resource names allow only
|
|
8
|
+
* lowercase letters, digits and underscores, so the file must be named
|
|
9
|
+
* that way.
|
|
10
|
+
*
|
|
11
|
+
* `expo prebuild` regenerates `ios/` and `android/` from scratch, so this
|
|
12
|
+
* re-applies the file every time instead of it being added by hand.
|
|
13
|
+
*/
|
|
14
|
+
const { IOSConfig, withDangerousMod, withXcodeProject } = require('expo/config-plugins');
|
|
15
|
+
const fs = require('node:fs');
|
|
16
|
+
const path = require('node:path');
|
|
17
|
+
|
|
18
|
+
function sourceOf(cfg, file) {
|
|
19
|
+
const source = path.resolve(cfg.modRequest.projectRoot, file);
|
|
20
|
+
if (!fs.existsSync(source)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
`@poolse/native: ringback ${source} is missing. Without it the ` +
|
|
23
|
+
'caller hears nothing (Android) or an iPhone ringtone (iOS) while it rings.',
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
return source;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function copyIntoProject(config, file) {
|
|
30
|
+
return withDangerousMod(config, [
|
|
31
|
+
'ios',
|
|
32
|
+
(cfg) => {
|
|
33
|
+
const target = path.join(cfg.modRequest.platformProjectRoot, cfg.modRequest.projectName, path.basename(file));
|
|
34
|
+
fs.copyFileSync(sourceOf(cfg, file), target);
|
|
35
|
+
return cfg;
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function addToBundle(config, file) {
|
|
41
|
+
return withXcodeProject(config, (cfg) => {
|
|
42
|
+
const groupName = cfg.modRequest.projectName;
|
|
43
|
+
const filepath = `${groupName}/${path.basename(file)}`;
|
|
44
|
+
|
|
45
|
+
// Copying the file in is not enough — it has to be a member of the
|
|
46
|
+
// Resources build phase or it never reaches the .app, and
|
|
47
|
+
// `_BUNDLE_` silently falls back to the ringtone again.
|
|
48
|
+
//
|
|
49
|
+
// Expo's helper rather than xcode's `addResourceFile` directly: the
|
|
50
|
+
// latter wants a resolved PBXGroup and throws an opaque
|
|
51
|
+
// "Cannot read properties of null (reading 'path')" when handed a
|
|
52
|
+
// group name.
|
|
53
|
+
if (!cfg.modResults.hasFile(filepath)) {
|
|
54
|
+
IOSConfig.XcodeUtils.addResourceFileToGroup({
|
|
55
|
+
filepath,
|
|
56
|
+
groupName,
|
|
57
|
+
project: cfg.modResults,
|
|
58
|
+
isBuildFile: true,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return cfg;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function copyIntoAndroidRes(config, file) {
|
|
66
|
+
return withDangerousMod(config, [
|
|
67
|
+
'android',
|
|
68
|
+
(cfg) => {
|
|
69
|
+
const rawDir = path.join(cfg.modRequest.platformProjectRoot, 'app', 'src', 'main', 'res', 'raw');
|
|
70
|
+
fs.mkdirSync(rawDir, { recursive: true });
|
|
71
|
+
fs.copyFileSync(sourceOf(cfg, file), path.join(rawDir, path.basename(file)));
|
|
72
|
+
return cfg;
|
|
73
|
+
},
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = function withRingback(config, file) {
|
|
78
|
+
const name = path.parse(file).name;
|
|
79
|
+
if (!/^[a-z][a-z0-9_]*$/.test(name)) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`@poolse/native: ringback "${path.basename(file)}" — the name must be ` +
|
|
82
|
+
'lowercase letters, digits and underscores (an Android resource name).',
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return copyIntoAndroidRes(addToBundle(copyIntoProject(config, file), file), file);
|
|
86
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Minimal ambient declaration for the one `expo-modules-core` function
|
|
2
|
+
// this package calls at runtime. It lets the package type-check and emit
|
|
3
|
+
// its own `.d.ts` without `expo-modules-core`'s full types installed in
|
|
4
|
+
// the monorepo — the host app always supplies the real module at runtime.
|
|
5
|
+
//
|
|
6
|
+
// This shim lives only in the package source; consumers read the emitted
|
|
7
|
+
// `dist/index.d.ts`, which never references `expo-modules-core`, so it
|
|
8
|
+
// cannot collide with the app's own copy of the types.
|
|
9
|
+
declare module 'expo-modules-core' {
|
|
10
|
+
export function requireOptionalNativeModule<T>(name: string): T | null;
|
|
11
|
+
/** A native view registered by an Expo module (`View(...)` + `Name(...)`). */
|
|
12
|
+
export function requireNativeViewManager<P>(
|
|
13
|
+
moduleName: string,
|
|
14
|
+
viewName?: string,
|
|
15
|
+
): import('react').ComponentType<P>;
|
|
16
|
+
}
|