@robono/calling-react-native 0.0.0-stage → 0.2.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/CHANGELOG.md +36 -0
- package/LICENSE +130 -0
- package/README.md +168 -2
- package/RobonoCallingRuntime.podspec +15 -0
- package/SBOM.spdx.json +983 -0
- package/android/build.gradle +8 -0
- package/android/src/main/AndroidManifest.xml +8 -0
- package/android/src/main/java/com/robono/calling/CallingPackage.java +15 -0
- package/android/src/main/java/com/robono/calling/CallingRuntime.java +75 -0
- package/android/src/main/java/com/robono/calling/CallingService.java +99 -0
- package/app.plugin.cjs +17 -0
- package/assets/bell.wav +0 -0
- package/assets/click.wav +0 -0
- package/assets/connecting.wav +0 -0
- package/assets/ended.wav +0 -0
- package/assets/marimba.wav +0 -0
- package/assets/pulse.wav +0 -0
- package/assets/ringing.wav +0 -0
- package/dist/appearance.d.ts +64 -0
- package/dist/appearance.js +126 -0
- package/dist/audio.d.mts +6 -0
- package/dist/audio.mjs +89 -0
- package/dist/controller.d.mts +7 -0
- package/dist/controller.mjs +211 -0
- package/dist/expo-notifications.d.ts +12 -0
- package/dist/expo-notifications.js +44 -0
- package/dist/history.d.ts +16 -0
- package/dist/history.js +12 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +23 -0
- package/dist/native.d.ts +18 -0
- package/dist/native.js +174 -0
- package/dist/notification-router.d.ts +18 -0
- package/dist/notification-router.js +59 -0
- package/dist/notifications.d.ts +37 -0
- package/dist/notifications.js +84 -0
- package/dist/runtime.d.ts +21 -0
- package/dist/runtime.js +227 -0
- package/dist/screens.d.ts +60 -0
- package/dist/screens.js +59 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.js +1 -0
- package/examples/CallingHost.tsx +209 -0
- package/examples/ExpoCallingHost.tsx +42 -0
- package/ios/RobonoCallingRuntime.m +84 -0
- package/package.json +99 -4
- package/react-native.config.js +4 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
apply plugin: 'com.android.library'
|
|
2
|
+
|
|
3
|
+
android {
|
|
4
|
+
namespace 'com.robono.calling'
|
|
5
|
+
compileSdkVersion rootProject.ext.has('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
6
|
+
defaultConfig { minSdkVersion 24 }
|
|
7
|
+
}
|
|
8
|
+
dependencies { implementation 'com.facebook.react:react-android' }
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
|
3
|
+
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE" />
|
|
4
|
+
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
5
|
+
<application>
|
|
6
|
+
<service android:name="com.robono.calling.CallingService" android:exported="false" android:foregroundServiceType="microphone" android:stopWithTask="true" />
|
|
7
|
+
</application>
|
|
8
|
+
</manifest>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.robono.calling;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.ReactPackage;
|
|
4
|
+
import com.facebook.react.bridge.NativeModule;
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
6
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
7
|
+
import java.util.Collections;
|
|
8
|
+
import java.util.List;
|
|
9
|
+
|
|
10
|
+
public final class CallingPackage implements ReactPackage {
|
|
11
|
+
public List<NativeModule> createNativeModules(ReactApplicationContext context) {
|
|
12
|
+
return Collections.singletonList(new CallingRuntime(context));
|
|
13
|
+
}
|
|
14
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext context) { return Collections.emptyList(); }
|
|
15
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
package com.robono.calling;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.os.Handler;
|
|
8
|
+
import android.os.Looper;
|
|
9
|
+
import android.os.ResultReceiver;
|
|
10
|
+
import com.facebook.react.bridge.*;
|
|
11
|
+
import com.facebook.react.common.LifecycleState;
|
|
12
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
13
|
+
import java.lang.ref.WeakReference;
|
|
14
|
+
|
|
15
|
+
public final class CallingRuntime extends ReactContextBaseJavaModule {
|
|
16
|
+
private static WeakReference<ReactApplicationContext> context = new WeakReference<>(null);
|
|
17
|
+
private final Handler main = new Handler(Looper.getMainLooper());
|
|
18
|
+
private String ownerToken;
|
|
19
|
+
public CallingRuntime(ReactApplicationContext value) { super(value); context = new WeakReference<>(value); }
|
|
20
|
+
public String getName() { return "RobonoCallingRuntime"; }
|
|
21
|
+
@ReactMethod public void addListener(String name) {}
|
|
22
|
+
@ReactMethod public void removeListeners(double count) {}
|
|
23
|
+
static ReactApplicationContext activeContext() {
|
|
24
|
+
ReactApplicationContext c = context.get();
|
|
25
|
+
if (c == null || !c.hasActiveReactInstance()) throw new IllegalStateException("calling_context_unavailable");
|
|
26
|
+
return c;
|
|
27
|
+
}
|
|
28
|
+
static void emit(String token, String type) {
|
|
29
|
+
ReactApplicationContext c = context.get();
|
|
30
|
+
if (c == null || !c.hasActiveReactInstance()) return;
|
|
31
|
+
WritableMap data = Arguments.createMap(); data.putString("token", token); data.putString("type", type);
|
|
32
|
+
c.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit("RobonoCallingRuntimeEvent", data);
|
|
33
|
+
}
|
|
34
|
+
@ReactMethod public void begin(String token, String title, String text, String channel, String endLabel, Promise promise) {
|
|
35
|
+
main.post(() -> {
|
|
36
|
+
ReactApplicationContext c = getReactApplicationContext();
|
|
37
|
+
if (c.getLifecycleState() != LifecycleState.RESUMED || c.getCurrentActivity() == null) {
|
|
38
|
+
promise.reject("open_app_to_start_call", "Open the app to start a call."); return;
|
|
39
|
+
}
|
|
40
|
+
if (c.checkSelfPermission(Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
|
|
41
|
+
promise.reject("microphone_permission_denied", "Microphone permission is required."); return;
|
|
42
|
+
}
|
|
43
|
+
final boolean[] settled = {false};
|
|
44
|
+
ownerToken = token;
|
|
45
|
+
Runnable timeout = () -> {
|
|
46
|
+
if (!settled[0]) { settled[0] = true; CallingService.finish(token); promise.reject("calling_service_timeout", "Call audio could not start."); }
|
|
47
|
+
};
|
|
48
|
+
ResultReceiver result = new ResultReceiver(main) {
|
|
49
|
+
@Override protected void onReceiveResult(int code, android.os.Bundle data) {
|
|
50
|
+
if (settled[0]) { if (code == 0) CallingService.finish(token); return; }
|
|
51
|
+
settled[0] = true; main.removeCallbacks(timeout);
|
|
52
|
+
if (code == 0) promise.resolve(null);
|
|
53
|
+
else promise.reject("calling_service_unavailable", "Call audio could not start.");
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
Intent intent = new Intent(c, CallingService.class).putExtra("token", token)
|
|
57
|
+
.putExtra("title", title).putExtra("text", text).putExtra("channel", channel)
|
|
58
|
+
.putExtra("endLabel", endLabel).putExtra("result", result);
|
|
59
|
+
try {
|
|
60
|
+
main.postDelayed(timeout, 4000);
|
|
61
|
+
if (Build.VERSION.SDK_INT >= 26) c.startForegroundService(intent); else c.startService(intent);
|
|
62
|
+
} catch (Exception error) {
|
|
63
|
+
settled[0] = true; main.removeCallbacks(timeout);
|
|
64
|
+
promise.reject("calling_service_unavailable", error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
@ReactMethod public void end(String token, Promise promise) {
|
|
69
|
+
main.post(() -> { CallingService.finish(token); if (token.equals(ownerToken)) ownerToken = null; promise.resolve(null); });
|
|
70
|
+
}
|
|
71
|
+
@Override public void invalidate() {
|
|
72
|
+
main.post(() -> { if (ownerToken != null) { CallingService.finish(ownerToken); ownerToken = null; } });
|
|
73
|
+
super.invalidate();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
package com.robono.calling;
|
|
2
|
+
|
|
3
|
+
import android.app.*;
|
|
4
|
+
import android.content.Intent;
|
|
5
|
+
import android.content.pm.ServiceInfo;
|
|
6
|
+
import android.os.*;
|
|
7
|
+
import java.lang.ref.WeakReference;
|
|
8
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.WritableMap;
|
|
10
|
+
import com.facebook.react.jstasks.HeadlessJsTaskConfig;
|
|
11
|
+
import com.facebook.react.jstasks.HeadlessJsTaskContext;
|
|
12
|
+
|
|
13
|
+
/** Owns only an explicitly started, answered/outgoing call. Never starts from a push. */
|
|
14
|
+
public final class CallingService extends Service {
|
|
15
|
+
private static WeakReference<CallingService> instance = new WeakReference<>(null);
|
|
16
|
+
private static final String CHANNEL = "robono_bridge_active_call";
|
|
17
|
+
private static final int NOTIFICATION = 0x524243;
|
|
18
|
+
private String token;
|
|
19
|
+
private PowerManager.WakeLock wakeLock;
|
|
20
|
+
private HeadlessJsTaskContext taskContext;
|
|
21
|
+
private Integer taskId;
|
|
22
|
+
private final Handler clock = new Handler(Looper.getMainLooper());
|
|
23
|
+
private final Runnable tick = new Runnable() {
|
|
24
|
+
@Override public void run() {
|
|
25
|
+
if (token == null) return;
|
|
26
|
+
CallingRuntime.emit(token, "tick"); clock.postDelayed(this, 250);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
public static void finish(String owner) {
|
|
30
|
+
CallingService service = instance.get();
|
|
31
|
+
if (service != null && owner.equals(service.token)) service.stopSelf();
|
|
32
|
+
}
|
|
33
|
+
@Override public void onCreate() { super.onCreate(); instance = new WeakReference<>(this); }
|
|
34
|
+
@Override public IBinder onBind(Intent intent) { return null; }
|
|
35
|
+
@Override public int onStartCommand(Intent intent, int flags, int startId) {
|
|
36
|
+
if (intent == null) { stopSelf(); return START_NOT_STICKY; }
|
|
37
|
+
String owner = intent.getStringExtra("token");
|
|
38
|
+
if ("end".equals(intent.getAction())) {
|
|
39
|
+
if (owner != null && owner.equals(token)) {
|
|
40
|
+
CallingRuntime.emit(token, "end");
|
|
41
|
+
// Keep the clock alive for the short hangup cue and audio cleanup.
|
|
42
|
+
// Normal cleanup calls finish(); this deadline handles an unresponsive JS host.
|
|
43
|
+
clock.postDelayed(() -> { if (owner.equals(token)) stopSelf(); }, 3000);
|
|
44
|
+
}
|
|
45
|
+
return START_NOT_STICKY;
|
|
46
|
+
}
|
|
47
|
+
ResultReceiver result = intent.getParcelableExtra("result");
|
|
48
|
+
if (owner == null || token != null && !token.equals(owner)) {
|
|
49
|
+
if (result != null) result.send(1, Bundle.EMPTY); return START_NOT_STICKY;
|
|
50
|
+
}
|
|
51
|
+
token = owner;
|
|
52
|
+
try {
|
|
53
|
+
NotificationManager manager = getSystemService(NotificationManager.class);
|
|
54
|
+
if (Build.VERSION.SDK_INT >= 26) {
|
|
55
|
+
NotificationChannel channel = new NotificationChannel(CHANNEL, intent.getStringExtra("channel"), NotificationManager.IMPORTANCE_LOW);
|
|
56
|
+
channel.setSound(null, null); channel.enableVibration(false); manager.createNotificationChannel(channel);
|
|
57
|
+
}
|
|
58
|
+
Intent launch = getPackageManager().getLaunchIntentForPackage(getPackageName());
|
|
59
|
+
if (launch == null) throw new IllegalStateException("calling_launch_activity_missing");
|
|
60
|
+
launch.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
61
|
+
PendingIntent open = PendingIntent.getActivity(this, NOTIFICATION, launch, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
62
|
+
Intent end = new Intent(this, CallingService.class).setAction("end").putExtra("token", token);
|
|
63
|
+
PendingIntent hangup = PendingIntent.getService(this, NOTIFICATION, end, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
|
64
|
+
Notification.Builder builder = Build.VERSION.SDK_INT >= 26 ? new Notification.Builder(this, CHANNEL) : new Notification.Builder(this);
|
|
65
|
+
builder.setSmallIcon(android.R.drawable.stat_sys_phone_call).setContentTitle(intent.getStringExtra("title"))
|
|
66
|
+
.setContentText(intent.getStringExtra("text")).setContentIntent(open).setOngoing(true).setOnlyAlertOnce(true)
|
|
67
|
+
.setCategory(Notification.CATEGORY_CALL).setVisibility(Notification.VISIBILITY_PRIVATE)
|
|
68
|
+
.addAction(new Notification.Action.Builder(android.R.drawable.ic_menu_close_clear_cancel, intent.getStringExtra("endLabel"), hangup).build());
|
|
69
|
+
if (Build.VERSION.SDK_INT >= 29) startForeground(NOTIFICATION, builder.build(), ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE);
|
|
70
|
+
else startForeground(NOTIFICATION, builder.build());
|
|
71
|
+
if (taskId == null) {
|
|
72
|
+
taskContext = HeadlessJsTaskContext.getInstance(CallingRuntime.activeContext());
|
|
73
|
+
WritableMap data = Arguments.createMap(); data.putString("token", token);
|
|
74
|
+
// Lifetime is bounded by this non-restarting call service, not a push.
|
|
75
|
+
taskId = taskContext.startTask(new HeadlessJsTaskConfig("RobonoBridgeCallLifetime", data, 0, true));
|
|
76
|
+
clock.post(tick);
|
|
77
|
+
}
|
|
78
|
+
if (wakeLock == null) {
|
|
79
|
+
wakeLock = getSystemService(PowerManager.class).newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, getPackageName()+":bridge-call");
|
|
80
|
+
wakeLock.acquire();
|
|
81
|
+
}
|
|
82
|
+
if (result != null) result.send(0, Bundle.EMPTY);
|
|
83
|
+
} catch (Exception error) {
|
|
84
|
+
if (result != null) result.send(1, Bundle.EMPTY); stopSelf();
|
|
85
|
+
}
|
|
86
|
+
return START_NOT_STICKY;
|
|
87
|
+
}
|
|
88
|
+
@Override public void onTaskRemoved(Intent rootIntent) { if (token != null) CallingRuntime.emit(token, "end"); stopSelf(); }
|
|
89
|
+
@Override public void onDestroy() {
|
|
90
|
+
clock.removeCallbacksAndMessages(null);
|
|
91
|
+
if (token != null) CallingRuntime.emit(token, "end");
|
|
92
|
+
if (taskContext != null && taskId != null) taskContext.finishTask(taskId);
|
|
93
|
+
taskId = null; taskContext = null;
|
|
94
|
+
if (wakeLock != null && wakeLock.isHeld()) wakeLock.release();
|
|
95
|
+
stopForeground(true);
|
|
96
|
+
if (instance.get() == this) instance.clear();
|
|
97
|
+
super.onDestroy();
|
|
98
|
+
}
|
|
99
|
+
}
|
package/app.plugin.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const {withInfoPlist, withAndroidManifest, createRunOncePlugin} = require('expo/config-plugins');
|
|
2
|
+
function withCallingRuntime(config) {
|
|
3
|
+
config = withInfoPlist(config, value => {
|
|
4
|
+
value.modResults.UIBackgroundModes = [...new Set([...(value.modResults.UIBackgroundModes || []), 'audio'])];
|
|
5
|
+
return value;
|
|
6
|
+
});
|
|
7
|
+
return withAndroidManifest(config, value => {
|
|
8
|
+
const manifest = value.modResults.manifest;
|
|
9
|
+
const permissions = manifest['uses-permission'] ||= [];
|
|
10
|
+
for (const name of ['RECORD_AUDIO', 'MODIFY_AUDIO_SETTINGS', 'INTERNET', 'WAKE_LOCK', 'POST_NOTIFICATIONS', 'BLUETOOTH_CONNECT']) {
|
|
11
|
+
const permission = `android.permission.${name}`;
|
|
12
|
+
if (!permissions.some(item => item.$['android:name'] === permission)) permissions.push({$: {'android:name': permission}});
|
|
13
|
+
}
|
|
14
|
+
return value;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
module.exports = createRunOncePlugin(withCallingRuntime, '@robono/calling-react-native', require('./package.json').version);
|
package/assets/bell.wav
ADDED
|
Binary file
|
package/assets/click.wav
ADDED
|
Binary file
|
|
Binary file
|
package/assets/ended.wav
ADDED
|
Binary file
|
|
Binary file
|
package/assets/pulse.wav
ADDED
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Shared website/SDK contract. Values contain presentation only, never credentials. */
|
|
2
|
+
export declare const callingColors: {
|
|
3
|
+
background: string;
|
|
4
|
+
foreground: string;
|
|
5
|
+
secondary: string;
|
|
6
|
+
control: string;
|
|
7
|
+
accent: string;
|
|
8
|
+
answer: string;
|
|
9
|
+
end: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const callingText: {
|
|
12
|
+
call: string;
|
|
13
|
+
contact: string;
|
|
14
|
+
incoming: string;
|
|
15
|
+
outgoing: string;
|
|
16
|
+
connecting: string;
|
|
17
|
+
held: string;
|
|
18
|
+
resume: string;
|
|
19
|
+
resuming: string;
|
|
20
|
+
resumeFailed: string;
|
|
21
|
+
audioBusy: string;
|
|
22
|
+
localHold: string;
|
|
23
|
+
loading: string;
|
|
24
|
+
answer: string;
|
|
25
|
+
decline: string;
|
|
26
|
+
mute: string;
|
|
27
|
+
unmute: string;
|
|
28
|
+
speaker: string;
|
|
29
|
+
end: string;
|
|
30
|
+
close: string;
|
|
31
|
+
unavailable: string;
|
|
32
|
+
failed: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const soundCatalog: {
|
|
35
|
+
none: string;
|
|
36
|
+
ringing: string;
|
|
37
|
+
connecting: string;
|
|
38
|
+
ended: string;
|
|
39
|
+
bell: string;
|
|
40
|
+
marimba: string;
|
|
41
|
+
pulse: string;
|
|
42
|
+
click: string;
|
|
43
|
+
};
|
|
44
|
+
export declare const callingSounds: Record<SoundEvent, SoundChoice>;
|
|
45
|
+
export type SoundChoice = keyof typeof soundCatalog;
|
|
46
|
+
export type SoundEvent = "incoming" | "outgoing" | "connecting" | "connected" | "ended" | "declined" | "unanswered" | "held" | "resumed";
|
|
47
|
+
export interface CallingAppearance {
|
|
48
|
+
schemaVersion: 1;
|
|
49
|
+
appName: string;
|
|
50
|
+
logoUrl: string | null;
|
|
51
|
+
theme: typeof callingColors;
|
|
52
|
+
labels: typeof callingText;
|
|
53
|
+
sounds: Record<SoundEvent, SoundChoice>;
|
|
54
|
+
}
|
|
55
|
+
export declare function defaultCallingAppearance(appName?: string): CallingAppearance;
|
|
56
|
+
export declare function validateCallingAppearance(input: unknown): CallingAppearance;
|
|
57
|
+
/** Choose readable icon/status-bar ink against a brand color. */
|
|
58
|
+
export declare function callingInk(color: string): "#ffffff" | "#000000";
|
|
59
|
+
export declare const callingIcons: {
|
|
60
|
+
answer: string;
|
|
61
|
+
end: string;
|
|
62
|
+
mute: string;
|
|
63
|
+
speaker: string;
|
|
64
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Shared website/SDK contract. Values contain presentation only, never credentials. */
|
|
2
|
+
export const callingColors = {
|
|
3
|
+
background: "#080808",
|
|
4
|
+
foreground: "#fafafa",
|
|
5
|
+
secondary: "#aaaaaa",
|
|
6
|
+
control: "#222222",
|
|
7
|
+
accent: "#ed8a36",
|
|
8
|
+
answer: "#247949",
|
|
9
|
+
end: "#bd2929",
|
|
10
|
+
};
|
|
11
|
+
export const callingText = {
|
|
12
|
+
call: "Voice call",
|
|
13
|
+
contact: "Contact",
|
|
14
|
+
incoming: "Incoming voice call",
|
|
15
|
+
outgoing: "Calling…",
|
|
16
|
+
connecting: "Connecting…",
|
|
17
|
+
held: "Call on hold",
|
|
18
|
+
resume: "Resume call",
|
|
19
|
+
resuming: "Resuming…",
|
|
20
|
+
resumeFailed: "Unable to resume. Check your connection and try again.",
|
|
21
|
+
audioBusy: "Finish the other call, then try again.",
|
|
22
|
+
localHold: "Finish the other call to resume.",
|
|
23
|
+
loading: "Opening call…",
|
|
24
|
+
answer: "Answer",
|
|
25
|
+
decline: "Decline",
|
|
26
|
+
mute: "Mute",
|
|
27
|
+
unmute: "Unmute",
|
|
28
|
+
speaker: "Speaker",
|
|
29
|
+
end: "End call",
|
|
30
|
+
close: "Close",
|
|
31
|
+
unavailable: "This call is no longer available.",
|
|
32
|
+
failed: "The call could not connect. Please try again.",
|
|
33
|
+
};
|
|
34
|
+
export const soundCatalog = {
|
|
35
|
+
none: "Silent",
|
|
36
|
+
ringing: "Robono chime",
|
|
37
|
+
connecting: "Soft pulse",
|
|
38
|
+
ended: "Soft finish",
|
|
39
|
+
bell: "Gentle bells",
|
|
40
|
+
marimba: "Warm marimba",
|
|
41
|
+
pulse: "Low pulse",
|
|
42
|
+
click: "Light tap",
|
|
43
|
+
};
|
|
44
|
+
export const callingSounds = {
|
|
45
|
+
incoming: "ringing",
|
|
46
|
+
outgoing: "connecting",
|
|
47
|
+
connecting: "connecting",
|
|
48
|
+
connected: "none",
|
|
49
|
+
ended: "ended",
|
|
50
|
+
declined: "none",
|
|
51
|
+
unanswered: "none",
|
|
52
|
+
held: "none",
|
|
53
|
+
resumed: "none",
|
|
54
|
+
};
|
|
55
|
+
export function defaultCallingAppearance(appName = "") {
|
|
56
|
+
return {
|
|
57
|
+
schemaVersion: 1,
|
|
58
|
+
appName: appName.trim().slice(0, 60),
|
|
59
|
+
logoUrl: null,
|
|
60
|
+
theme: { ...callingColors },
|
|
61
|
+
labels: { ...callingText },
|
|
62
|
+
sounds: { ...callingSounds },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export function validateCallingAppearance(input) {
|
|
66
|
+
const v = input;
|
|
67
|
+
if (!v || v.schemaVersion !== 1 || typeof v.appName !== "string" ||
|
|
68
|
+
v.appName.length > 60 || /[\u0000-\u001f]/.test(v.appName))
|
|
69
|
+
throw Error("Use an app name of up to 60 characters.");
|
|
70
|
+
if (v.logoUrl !== null &&
|
|
71
|
+
(typeof v.logoUrl !== "string" || v.logoUrl.length > 2048 ||
|
|
72
|
+
!/^https:\/\//.test(v.logoUrl) || new URL(v.logoUrl).username ||
|
|
73
|
+
new URL(v.logoUrl).password))
|
|
74
|
+
throw Error("Use an HTTPS logo address.");
|
|
75
|
+
const out = defaultCallingAppearance(v.appName.trim());
|
|
76
|
+
out.logoUrl = v.logoUrl;
|
|
77
|
+
for (const key of Object.keys(callingColors)) {
|
|
78
|
+
const x = v.theme?.[key];
|
|
79
|
+
if (typeof x !== "string" || !/^#[0-9a-f]{6}$/i.test(x)) {
|
|
80
|
+
throw Error("Choose a valid color for " + key + ".");
|
|
81
|
+
}
|
|
82
|
+
out.theme[key] = x;
|
|
83
|
+
}
|
|
84
|
+
for (const key of Object.keys(callingText)) {
|
|
85
|
+
const x = v.labels?.[key];
|
|
86
|
+
if (typeof x !== "string" || !x.trim() ||
|
|
87
|
+
x.length >
|
|
88
|
+
([
|
|
89
|
+
"answer",
|
|
90
|
+
"decline",
|
|
91
|
+
"mute",
|
|
92
|
+
"unmute",
|
|
93
|
+
"speaker",
|
|
94
|
+
"end",
|
|
95
|
+
"close",
|
|
96
|
+
"resume",
|
|
97
|
+
].includes(key)
|
|
98
|
+
? 32
|
|
99
|
+
: 160) ||
|
|
100
|
+
/[\u0000-\u001f]/.test(x))
|
|
101
|
+
throw Error("Enter a short, non-empty label for " + key + ".");
|
|
102
|
+
out.labels[key] = x.trim();
|
|
103
|
+
}
|
|
104
|
+
for (const key of Object.keys(callingSounds)) {
|
|
105
|
+
if (!Object.hasOwn(soundCatalog, v.sounds?.[key])) {
|
|
106
|
+
throw Error("Choose a supported sound for " + key + ".");
|
|
107
|
+
}
|
|
108
|
+
out.sounds[key] = v.sounds[key];
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
/** Choose readable icon/status-bar ink against a brand color. */
|
|
113
|
+
export function callingInk(color) {
|
|
114
|
+
const channels = [1, 3, 5].map((i) => parseInt(color.slice(i, i + 2), 16) / 255).map((v) => v <= .04045 ? v / 12.92 : ((v + .055) / 1.055) ** 2.4);
|
|
115
|
+
const luminance = .2126 * channels[0] + .7152 * channels[1] +
|
|
116
|
+
.0722 * channels[2];
|
|
117
|
+
return (luminance + .05) / .05 > 1.05 / (luminance + .05)
|
|
118
|
+
? "#000000"
|
|
119
|
+
: "#ffffff";
|
|
120
|
+
}
|
|
121
|
+
export const callingIcons = {
|
|
122
|
+
answer: "M6 3H3c-1 0-1 1-1 2 1 9 8 16 17 17 1 0 2 0 2-1v-4l-5-2-2 3C9 16 6 13 5 9l3-2-2-4Z",
|
|
123
|
+
end: "M2 11c6-5 14-5 20 0v5l-5-1v-4c-3-1-7-1-10 0v4l-5 1v-5Z",
|
|
124
|
+
mute: "M12 3a3 3 0 0 0-3 3v6a3 3 0 0 0 6 0V6a3 3 0 0 0-3-3ZM5 11v1a7 7 0 0 0 6 7v3h2v-3a7 7 0 0 0 6-7v-1h-2v1a5 5 0 0 1-10 0v-1H5Z",
|
|
125
|
+
speaker: "M3 9v6h4l5 4V5L7 9H3Zm12-3v2a5 5 0 0 1 0 8v2a7 7 0 0 0 0-12Zm3-3v2a9 9 0 0 1 0 14v2a11 11 0 0 0 0-18Z",
|
|
126
|
+
};
|
package/dist/audio.d.mts
ADDED
package/dist/audio.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Serializes native audio changes. Late setup/cleanup cannot overtake a new call.
|
|
2
|
+
export function createCallAudio(driver) {
|
|
3
|
+
let revision = 0, disposed = false, queue = Promise.resolve(), latest = queue, timer;
|
|
4
|
+
let phase = 'idle', speaker = false, active = false;
|
|
5
|
+
const serial = work => { const next = queue.then(work); latest = next; queue = next.catch(() => { }); return next; };
|
|
6
|
+
const schedule = driver.schedule || ((callback, delay) => { const id = setTimeout(callback, delay); return () => clearTimeout(id); });
|
|
7
|
+
const choice = (event, fallback = 'none') => driver.sound?.(event) ?? fallback;
|
|
8
|
+
const play = async (event, fallback, loop = false) => { const kind = choice(event, fallback); if (kind !== 'none')
|
|
9
|
+
await driver.play(kind, { loop, event }); };
|
|
10
|
+
const stop = () => { driver.pause(); timer?.(); timer = undefined; };
|
|
11
|
+
const release = async (generation) => {
|
|
12
|
+
if (generation !== revision)
|
|
13
|
+
return;
|
|
14
|
+
stop();
|
|
15
|
+
if (active) {
|
|
16
|
+
active = false;
|
|
17
|
+
await driver.release();
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
ready() { return latest; },
|
|
22
|
+
resume() { return serial(async () => { if (!disposed && active)
|
|
23
|
+
await driver.resume?.(); }); },
|
|
24
|
+
update(next) {
|
|
25
|
+
if (disposed)
|
|
26
|
+
return Promise.resolve();
|
|
27
|
+
const generation = ++revision;
|
|
28
|
+
const changed = next.phase !== phase;
|
|
29
|
+
phase = next.phase;
|
|
30
|
+
speaker = next.speaker;
|
|
31
|
+
// Stop a ringtone immediately on Answer, even while native setup is queued.
|
|
32
|
+
if (changed || !next.foreground && phase === 'incoming')
|
|
33
|
+
stop();
|
|
34
|
+
return serial(async () => {
|
|
35
|
+
if (generation !== revision || disposed)
|
|
36
|
+
return;
|
|
37
|
+
// The OS owns audio during a local interruption. Never activate the
|
|
38
|
+
// session, route output or play a cue while either participant is held.
|
|
39
|
+
if (phase === 'held') {
|
|
40
|
+
stop();
|
|
41
|
+
if (changed && next.localHeld === false)
|
|
42
|
+
await play('held', 'none');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (['idle', 'error', 'loading'].includes(phase)) {
|
|
46
|
+
if ((next.endTone || next.cue && choice(next.cue) !== 'none') && active) {
|
|
47
|
+
stop();
|
|
48
|
+
await play(next.endTone ? 'ended' : next.cue, next.endTone ? 'ended' : 'none');
|
|
49
|
+
if (generation !== revision)
|
|
50
|
+
return;
|
|
51
|
+
timer = schedule(() => { void serial(() => release(generation)).catch(driver.onError); }, driver.duration?.(next.endTone ? 'ended' : next.cue) ?? 700);
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
await release(generation);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (phase === 'incoming' && !next.foreground) {
|
|
58
|
+
await release(generation);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
active = true;
|
|
62
|
+
await driver.prepare(phase, speaker);
|
|
63
|
+
if (generation !== revision || disposed)
|
|
64
|
+
return;
|
|
65
|
+
if (phase === 'connected') {
|
|
66
|
+
if (changed) {
|
|
67
|
+
driver.pause();
|
|
68
|
+
await play(next.cue || 'connected', 'none');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (changed || !driver.playing())
|
|
72
|
+
await play(phase, phase === 'incoming' ? 'ringing' : 'connecting', true);
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async dispose() {
|
|
76
|
+
if (disposed)
|
|
77
|
+
return;
|
|
78
|
+
disposed = true;
|
|
79
|
+
const generation = ++revision;
|
|
80
|
+
stop();
|
|
81
|
+
try {
|
|
82
|
+
await serial(() => release(generation));
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
driver.dispose();
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {import('./types.js').CallingOptions & {createClient: (options: any) => import('@robono/calling').RobonoCallingClient}} options
|
|
3
|
+
* @returns {import('./types.js').CallingController}
|
|
4
|
+
*/
|
|
5
|
+
export function createController({ createClient, request, media, audio, resolveContact, onError, forceRelay }: import("./types.js").CallingOptions & {
|
|
6
|
+
createClient: (options: any) => import("@robono/calling").RobonoCallingClient;
|
|
7
|
+
}): import("./types.js").CallingController;
|