@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +130 -0
  3. package/README.md +168 -2
  4. package/RobonoCallingRuntime.podspec +15 -0
  5. package/SBOM.spdx.json +983 -0
  6. package/android/build.gradle +8 -0
  7. package/android/src/main/AndroidManifest.xml +8 -0
  8. package/android/src/main/java/com/robono/calling/CallingPackage.java +15 -0
  9. package/android/src/main/java/com/robono/calling/CallingRuntime.java +75 -0
  10. package/android/src/main/java/com/robono/calling/CallingService.java +99 -0
  11. package/app.plugin.cjs +17 -0
  12. package/assets/bell.wav +0 -0
  13. package/assets/click.wav +0 -0
  14. package/assets/connecting.wav +0 -0
  15. package/assets/ended.wav +0 -0
  16. package/assets/marimba.wav +0 -0
  17. package/assets/pulse.wav +0 -0
  18. package/assets/ringing.wav +0 -0
  19. package/dist/appearance.d.ts +64 -0
  20. package/dist/appearance.js +126 -0
  21. package/dist/audio.d.mts +6 -0
  22. package/dist/audio.mjs +89 -0
  23. package/dist/controller.d.mts +7 -0
  24. package/dist/controller.mjs +211 -0
  25. package/dist/expo-notifications.d.ts +12 -0
  26. package/dist/expo-notifications.js +44 -0
  27. package/dist/history.d.ts +16 -0
  28. package/dist/history.js +12 -0
  29. package/dist/index.d.ts +8 -0
  30. package/dist/index.js +23 -0
  31. package/dist/native.d.ts +18 -0
  32. package/dist/native.js +174 -0
  33. package/dist/notification-router.d.ts +18 -0
  34. package/dist/notification-router.js +59 -0
  35. package/dist/notifications.d.ts +37 -0
  36. package/dist/notifications.js +84 -0
  37. package/dist/runtime.d.ts +21 -0
  38. package/dist/runtime.js +227 -0
  39. package/dist/screens.d.ts +60 -0
  40. package/dist/screens.js +59 -0
  41. package/dist/types.d.ts +67 -0
  42. package/dist/types.js +1 -0
  43. package/examples/CallingHost.tsx +209 -0
  44. package/examples/ExpoCallingHost.tsx +42 -0
  45. package/ios/RobonoCallingRuntime.m +84 -0
  46. package/package.json +99 -4
  47. package/react-native.config.js +4 -0
@@ -0,0 +1,84 @@
1
+ /** Works with AsyncStorage or another durable, account-safe key/value store. */
2
+ export function createCallingNotificationStore(storage, prefix = '@robono/calling-notifications/') {
3
+ return {
4
+ async load(accountKey) {
5
+ const raw = await storage.getItem(prefix + encodeURIComponent(accountKey));
6
+ if (!raw)
7
+ return Object.create(null);
8
+ const data = JSON.parse(raw);
9
+ if (!data || typeof data !== 'object' || Array.isArray(data))
10
+ throw Error('calling_notification_store_invalid');
11
+ const ledger = Object.create(null);
12
+ for (const [key, entry] of Object.entries(data)) {
13
+ const value = entry;
14
+ if (!value || ![1, 2].includes(value.sequence) || !Number.isFinite(value.retainUntil))
15
+ throw Error('calling_notification_store_invalid');
16
+ if (value.retainUntil > Date.now())
17
+ ledger[key] = { sequence: value.sequence, retainUntil: value.retainUntil };
18
+ }
19
+ return ledger;
20
+ },
21
+ save: (accountKey, ledger) => storage.setItem(prefix + encodeURIComponent(accountKey), JSON.stringify(ledger)),
22
+ };
23
+ }
24
+ export function parseCallingNotification(data) {
25
+ if (!data || typeof data !== 'object')
26
+ return null;
27
+ const p = data;
28
+ if (!['calling.incoming', 'calling.dismissed'].includes(String(p.event)))
29
+ return null;
30
+ if (['call_id', 'event_id', 'connection_id'].some(key => typeof p[key] !== 'string' || !p[key] || p[key].length > 256))
31
+ return null;
32
+ if (typeof p.ring_expires_at !== 'string' || !Number.isFinite(Date.parse(p.ring_expires_at)))
33
+ return null;
34
+ if (p.sequence !== (p.event === 'calling.incoming' ? 1 : 2))
35
+ return null;
36
+ return { event: p.event, event_id: p.event_id, call_id: p.call_id, connection_id: p.connection_id, ring_expires_at: p.ring_expires_at, sequence: p.sequence };
37
+ }
38
+ /** Host retains its push provider, credentials and notification handler. */
39
+ export function createCallingNotificationHandler(options) {
40
+ let queue = Promise.resolve(), disposed = false;
41
+ const process = async (data, opened) => {
42
+ if (disposed)
43
+ return false;
44
+ const event = parseCallingNotification(data);
45
+ if (!event)
46
+ return false;
47
+ const ledger = await options.store.load(options.accountKey);
48
+ if (disposed)
49
+ return false;
50
+ const now = Date.now();
51
+ for (const [id, value] of Object.entries(ledger))
52
+ if (value.retainUntil < now)
53
+ delete ledger[id];
54
+ const previous = ledger[event.call_id]?.sequence || 0;
55
+ const expired = Date.parse(event.ring_expires_at) <= now;
56
+ if (event.sequence > previous) {
57
+ ledger[event.call_id] = { sequence: event.sequence, retainUntil: Math.max(now, Date.parse(event.ring_expires_at)) + 86400000 };
58
+ await options.store.save(options.accountKey, ledger);
59
+ }
60
+ if (disposed)
61
+ return false;
62
+ if (previous >= 2 || event.sequence === 2 || expired) {
63
+ await options.dismiss(event.call_id);
64
+ // State refresh clears stale invitations but does not hang up an answered call.
65
+ await options.controller.refresh();
66
+ return false;
67
+ }
68
+ if (opened)
69
+ return options.controller.openIncoming(event.call_id);
70
+ if (previous >= event.sequence)
71
+ return false;
72
+ // A push alone never authorizes microphone capture or an Answer button.
73
+ await options.controller.refresh();
74
+ return true;
75
+ };
76
+ return {
77
+ handle(data, options = {}) {
78
+ const next = queue.then(() => process(data, !!options.opened));
79
+ queue = next.then(() => { }, () => { });
80
+ return next;
81
+ },
82
+ dispose() { disposed = true; },
83
+ };
84
+ }
@@ -0,0 +1,21 @@
1
+ import type { CallingController } from './types.js';
2
+ export interface CallRuntime {
3
+ /** Start from the visible app, after microphone permission and before capture. */
4
+ begin(): Promise<void>;
5
+ end(): Promise<void>;
6
+ attach(controller: CallingController): () => void;
7
+ dispose(): Promise<void>;
8
+ /** Audio cleanup deadline also advances on native call ticks in background. */
9
+ schedule?(callback: () => void, delayMs: number): () => void;
10
+ activateAudio?(): Promise<void>;
11
+ }
12
+ export interface NativeRuntimeOptions {
13
+ /** Your app's translated, privacy-safe ongoing-call notification. */
14
+ notificationTitle: string;
15
+ notificationText: string;
16
+ channelName: string;
17
+ endLabel: string;
18
+ onError(error: Error): void;
19
+ }
20
+ /** Optional native lifetime support. Does not install CallKit or incoming-call UI. */
21
+ export declare function createNativeCallRuntime(options: NativeRuntimeOptions): CallRuntime;
@@ -0,0 +1,227 @@
1
+ import { AppRegistry, AppState, DeviceEventEmitter, NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
+ // Android pauses React timers without an active JS task even while a microphone
3
+ // service owns audio. Keep signaling alive only for an explicitly started call.
4
+ const callTasks = new Map();
5
+ let taskRegistered = false;
6
+ function holdCallTask(token) {
7
+ if (Platform.OS !== 'android')
8
+ return;
9
+ if (!taskRegistered) {
10
+ AppRegistry.registerHeadlessTask('RobonoBridgeCallLifetime', () => async (data) => {
11
+ await callTasks.get(data.token)?.promise;
12
+ });
13
+ taskRegistered = true;
14
+ }
15
+ let finish;
16
+ const promise = new Promise(resolve => { finish = resolve; });
17
+ callTasks.set(token, { promise, finish });
18
+ }
19
+ function finishCallTask(token) {
20
+ if (!token)
21
+ return;
22
+ callTasks.get(token)?.finish();
23
+ callTasks.delete(token);
24
+ }
25
+ /** Optional native lifetime support. Does not install CallKit or incoming-call UI. */
26
+ export function createNativeCallRuntime(options) {
27
+ const native = NativeModules.RobonoCallingRuntime;
28
+ if (!native)
29
+ throw Error('calling_runtime_native_build_required');
30
+ for (const key of ['notificationTitle', 'notificationText', 'channelName', 'endLabel'])
31
+ if (!options[key]?.trim())
32
+ throw Error(`calling_runtime_${key}_required`);
33
+ const owner = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
34
+ let token;
35
+ let starting;
36
+ let disposed = false, active = false, generation = 0;
37
+ let controller;
38
+ let ending = false;
39
+ let interruption = 0;
40
+ let holding = Promise.resolve();
41
+ let backgroundSince = 0, lastBackgroundSuccess = 0, nextRefresh = 0, refreshing = false;
42
+ const deadlines = new Set();
43
+ const subscriptions = [];
44
+ const endCall = (playEndTone = true) => {
45
+ if ((!active && !starting) || ending || !controller)
46
+ return;
47
+ ending = true;
48
+ void controller.hangUp({ playEndTone }).catch(options.onError).finally(() => { ending = false; });
49
+ };
50
+ const interrupt = () => {
51
+ if (!active || !controller)
52
+ return;
53
+ ++interruption;
54
+ const currentToken = token;
55
+ // interrupt() disables tracks synchronously before its first network wait.
56
+ holding = controller.interrupt().catch(options.onError).finally(() => {
57
+ if (token === currentToken)
58
+ void native.interruptionHandled?.(currentToken);
59
+ });
60
+ };
61
+ const resume = () => {
62
+ const currentToken = token, revision = interruption;
63
+ void holding.then(async () => {
64
+ if (active && token === currentToken && revision === interruption)
65
+ await controller?.resume();
66
+ }).catch(options.onError);
67
+ };
68
+ const emitter = new NativeEventEmitter(native);
69
+ subscriptions.push(emitter.addListener('RobonoCallingRuntimeEvent', event => {
70
+ if (event.token !== token)
71
+ return;
72
+ if (event.type === 'interrupted')
73
+ interrupt();
74
+ if (event.type === 'interruptionEnded' && event.shouldResume)
75
+ resume();
76
+ if (event.type === 'audioReset')
77
+ endCall(false);
78
+ if (event.type === 'end')
79
+ endCall();
80
+ if (event.type === 'tick') {
81
+ const now = Date.now();
82
+ for (const deadline of [...deadlines])
83
+ if (deadline.at <= now)
84
+ deadline.run();
85
+ if (!active || !controller || AppState.currentState === 'active') {
86
+ backgroundSince = 0;
87
+ return;
88
+ }
89
+ if (!backgroundSince)
90
+ backgroundSince = lastBackgroundSuccess = now;
91
+ // Native ticks don't depend on Android display-frame timers. Match the
92
+ // engine's connection-loss deadline, including while a request is stuck.
93
+ const state = controller.getSnapshot();
94
+ const heldLease = state.localHeld && (state.call?.holdExpiresAt || 0) > now;
95
+ if (now - lastBackgroundSuccess > 10000 && !heldLease) {
96
+ endCall(!state.localHeld);
97
+ return;
98
+ }
99
+ if (refreshing || now < nextRefresh)
100
+ return;
101
+ refreshing = true;
102
+ nextRefresh = now + 3000;
103
+ const currentToken = token;
104
+ void controller.refresh().then(ok => {
105
+ if (ok && token === currentToken)
106
+ lastBackgroundSuccess = Date.now();
107
+ }).catch(options.onError).finally(() => { refreshing = false; });
108
+ }
109
+ }));
110
+ if (Platform.OS === 'android')
111
+ subscriptions.push(DeviceEventEmitter.addListener('onAudioFocusChange', event => {
112
+ if (event.eventCode === -1 || event.eventCode === -2)
113
+ interrupt();
114
+ if (event.eventCode === 1)
115
+ resume();
116
+ }));
117
+ return {
118
+ async begin() {
119
+ if (disposed)
120
+ throw Error('calling_runtime_disposed');
121
+ if (active)
122
+ return;
123
+ if (starting)
124
+ return starting;
125
+ if (AppState.currentState !== 'active')
126
+ throw Error('open_app_to_start_call');
127
+ const revision = ++generation;
128
+ const callToken = token = `${owner}-${revision}`;
129
+ backgroundSince = nextRefresh = 0;
130
+ holdCallTask(callToken);
131
+ const work = (async () => {
132
+ try {
133
+ await native.begin(callToken, options.notificationTitle, options.notificationText, options.channelName, options.endLabel);
134
+ }
135
+ catch (error) {
136
+ finishCallTask(callToken);
137
+ throw error;
138
+ }
139
+ if (disposed || revision !== generation) {
140
+ try {
141
+ await native.end(callToken);
142
+ }
143
+ finally {
144
+ finishCallTask(callToken);
145
+ }
146
+ throw Error('call_cancelled');
147
+ }
148
+ active = true;
149
+ })();
150
+ starting = work;
151
+ try {
152
+ await work;
153
+ }
154
+ finally {
155
+ if (starting === work)
156
+ starting = undefined;
157
+ }
158
+ },
159
+ async end() {
160
+ ++generation;
161
+ ++interruption;
162
+ active = false;
163
+ const endingToken = token;
164
+ token = undefined;
165
+ if (endingToken)
166
+ try {
167
+ await native.end(endingToken);
168
+ }
169
+ finally {
170
+ finishCallTask(endingToken);
171
+ }
172
+ },
173
+ async activateAudio() {
174
+ if (!active || !token || disposed)
175
+ throw Error('call_cancelled');
176
+ if (typeof native.activateAudio !== 'function')
177
+ throw Error('calling_runtime_native_build_required');
178
+ await native.activateAudio(token);
179
+ },
180
+ schedule(callback, delayMs) {
181
+ let timer, pending = true;
182
+ const deadline = {
183
+ at: Date.now() + delayMs,
184
+ run() { if (!pending)
185
+ return; deadline.cancel(); callback(); },
186
+ cancel() { pending = false; clearTimeout(timer); deadlines.delete(deadline); },
187
+ };
188
+ deadlines.add(deadline);
189
+ timer = setTimeout(deadline.run, delayMs);
190
+ return deadline.cancel;
191
+ },
192
+ attach(value) {
193
+ if (disposed || controller && controller !== value)
194
+ throw Error('calling_runtime_already_attached');
195
+ controller = value;
196
+ value.setForeground(AppState.currentState === 'active');
197
+ const sub = AppState.addEventListener('change', state => {
198
+ value.setForeground(state === 'active');
199
+ if (state === 'active')
200
+ void value.refresh().catch(options.onError);
201
+ });
202
+ subscriptions.push(sub);
203
+ return () => { sub.remove(); if (controller === value)
204
+ controller = undefined; };
205
+ },
206
+ async dispose() {
207
+ if (disposed)
208
+ return;
209
+ disposed = true;
210
+ ++generation;
211
+ active = false;
212
+ controller = undefined;
213
+ subscriptions.forEach(sub => sub.remove());
214
+ for (const deadline of [...deadlines])
215
+ deadline.cancel();
216
+ const endingToken = token;
217
+ token = undefined;
218
+ if (endingToken)
219
+ try {
220
+ await native.end(endingToken);
221
+ }
222
+ finally {
223
+ finishCallTask(endingToken);
224
+ }
225
+ },
226
+ };
227
+ }
@@ -0,0 +1,60 @@
1
+ import React from 'react';
2
+ import { type CallingAppearance } from './appearance.js';
3
+ import type { CallingController, CallingState } from './types.js';
4
+ export interface CallingTheme {
5
+ background: string;
6
+ foreground: string;
7
+ secondary: string;
8
+ control: string;
9
+ accent: string;
10
+ answer: string;
11
+ end: string;
12
+ }
13
+ export interface CallingLabels {
14
+ call: string;
15
+ contact: string;
16
+ incoming: string;
17
+ outgoing: string;
18
+ connecting: string;
19
+ held: string;
20
+ resume: string;
21
+ resuming: string;
22
+ resumeFailed: string;
23
+ audioBusy: string;
24
+ localHold: string;
25
+ loading: string;
26
+ answer: string;
27
+ decline: string;
28
+ mute: string;
29
+ unmute: string;
30
+ speaker: string;
31
+ end: string;
32
+ close: string;
33
+ unavailable: string;
34
+ failed: string;
35
+ }
36
+ export interface CallingScreenProps {
37
+ state: CallingState;
38
+ appearance?: CallingAppearance;
39
+ onResume?(): void;
40
+ onAnswer(): void;
41
+ onHangUp(): void;
42
+ onMute(value: boolean): void;
43
+ onSpeaker(value: boolean): void;
44
+ onClose(): void;
45
+ theme?: Partial<CallingTheme>;
46
+ labels?: Partial<CallingLabels>;
47
+ formatError?: (code: string) => string;
48
+ /** Insets from the host's safe-area provider, in logical pixels. */
49
+ insets?: {
50
+ top: number;
51
+ bottom: number;
52
+ };
53
+ }
54
+ export declare function CallingScreen(props: CallingScreenProps): React.JSX.Element | null;
55
+ export declare function useCalling(controller: CallingController): CallingState;
56
+ export interface CallingOverlayProps extends Omit<CallingScreenProps, 'state' | 'onResume' | 'onAnswer' | 'onHangUp' | 'onMute' | 'onSpeaker' | 'onClose'> {
57
+ controller: CallingController;
58
+ }
59
+ /** Mount only when you choose Robono's interface. No global navigation changes. */
60
+ export declare function CallingOverlay({ controller, ...props }: CallingOverlayProps): React.JSX.Element;
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContext, useEffect, useState, useSyncExternalStore } from 'react';
3
+ import { AppState, Image, Modal, Pressable, ScrollView, StatusBar, StyleSheet, Text, View } from 'react-native';
4
+ import Svg, { Path } from 'react-native-svg';
5
+ import { SafeAreaInsetsContext, SafeAreaProvider } from 'react-native-safe-area-context';
6
+ import { callingColors, callingText, callingInk, callingIcons } from './appearance.js';
7
+ const theme = callingColors;
8
+ const labels = callingText;
9
+ // Familiar handset, microphone and speaker silhouettes; never status checkmarks.
10
+ function ControlIcon({ name, color, muted }) {
11
+ return _jsxs(Svg, { width: 30, height: 30, viewBox: "0 0 24 24", accessible: false, children: [_jsx(Path, { d: callingIcons[name], fill: color }), muted && _jsx(Path, { d: "M3 2 22 21", stroke: color, strokeWidth: 2.5 })] });
12
+ }
13
+ export function CallingScreen(props) {
14
+ const safeArea = useContext(SafeAreaInsetsContext);
15
+ const insets = props.insets || safeArea;
16
+ const s = props.state, c = { ...theme, ...props.appearance?.theme, ...props.theme }, t = { ...labels, ...props.appearance?.labels, ...props.labels };
17
+ const [clock, setClock] = useState(Date.now());
18
+ useEffect(() => {
19
+ if (s.phase !== 'connected')
20
+ return;
21
+ setClock(Date.now());
22
+ const timer = setInterval(() => setClock(Date.now()), 1000);
23
+ return () => clearInterval(timer);
24
+ }, [s.phase, s.connectedAt]);
25
+ if (s.phase === 'idle')
26
+ return null;
27
+ const seconds = s.connectedAt == null ? 0 : Math.max(0, Math.floor((clock - s.connectedAt) / 1000));
28
+ const duration = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
29
+ const title = s.contact?.name || t.contact;
30
+ const error = s.phase === 'held' ? (s.resumeError ? props.formatError?.(s.resumeError) || (s.resumeError === 'audio_still_interrupted' ? t.audioBusy : t.resumeFailed) : null) : s.error ? props.formatError?.(s.error) || (s.error === 'call_unavailable' ? t.unavailable : t.failed) : null;
31
+ const status = s.phase === 'connected' ? duration : s.phase === 'error' ? '' : t[s.phase];
32
+ const control = (name, title, onPress, options = {}) => _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: title, accessibilityState: { disabled: !!options.disabled, selected: !!options.selected }, disabled: options.disabled, onPress: onPress, hitSlop: 8, style: [styles.button, options.disabled && styles.disabled], children: [_jsx(View, { style: [styles.circle, { backgroundColor: options.color || (options.selected ? c.foreground : c.control) }], children: _jsx(ControlIcon, { name: name, muted: name === 'mute' && s.muted, color: options.color ? callingInk(options.color) : options.selected ? c.background : c.foreground }) }), _jsx(Text, { style: [styles.label, { color: c.foreground }], children: title })] }, name);
33
+ return _jsxs(ScrollView, { style: { flex: 1, backgroundColor: c.background }, contentContainerStyle: [styles.screen, { paddingTop: Math.max(36, insets?.top || 0) + 32, paddingBottom: Math.max(24, insets?.bottom ?? 48) + 16 }], children: [_jsxs(View, { style: styles.identity, children: [(props.appearance?.logoUrl || props.appearance?.appName) && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 8 }, children: [props.appearance.logoUrl && _jsx(Image, { source: { uri: props.appearance.logoUrl }, style: { width: 28, height: 28, borderRadius: 6 }, resizeMode: "contain" }), _jsx(Text, { style: { color: c.secondary, fontSize: 14 }, children: props.appearance.appName })] }), s.contact?.avatarUri ? _jsx(Image, { source: { uri: s.contact.avatarUri }, style: styles.avatar, accessibilityIgnoresInvertColors: true })
34
+ : _jsx(View, { style: [styles.avatar, { backgroundColor: c.control }], children: _jsx(Text, { style: [styles.initial, { color: c.accent }], children: title.trim().charAt(0).toUpperCase() }) }), _jsx(Text, { style: [styles.name, { color: c.foreground }], children: title }), _jsx(Text, { style: [styles.kind, { color: c.secondary }], children: t.call }), _jsx(Text, { style: [styles.status, { color: c.foreground }], accessibilityLiveRegion: s.phase === 'connected' ? 'none' : 'polite', children: status }), s.phase === 'held' && s.localHeld && _jsx(Text, { style: [styles.detail, { color: c.secondary }], children: t.localHold }), !!error && _jsx(Text, { accessibilityRole: "alert", style: [styles.detail, { color: c.foreground }], children: error })] }), _jsxs(View, { style: styles.controls, children: [s.phase === 'held' && s.localHeld && props.onResume && _jsx(Pressable, { accessibilityRole: "button", accessibilityState: { disabled: !!s.resumePending, busy: !!s.resumePending }, disabled: s.resumePending, onPress: props.onResume, style: [styles.close, { backgroundColor: c.control }, s.resumePending && styles.disabled], children: _jsx(Text, { style: [styles.label, { color: c.foreground }], children: s.resumePending ? t.resuming : t.resume }) }), ['outgoing', 'connecting', 'connected'].includes(s.phase) && _jsxs(View, { style: styles.row, children: [control('mute', s.muted ? t.unmute : t.mute, () => props.onMute(!s.muted), { disabled: !s.canMute, selected: s.muted }), control('speaker', t.speaker, () => props.onSpeaker(!s.speaker), { disabled: !s.canSpeaker, selected: s.speaker })] }), s.phase === 'error' || s.phase === 'loading' ? _jsx(Pressable, { accessibilityRole: "button", onPress: s.phase === 'loading' ? props.onHangUp : props.onClose, style: [styles.close, { backgroundColor: c.control }], children: _jsx(Text, { style: [styles.label, { color: c.foreground }], children: t.close }) }) : _jsxs(View, { style: styles.row, children: [control('end', s.phase === 'incoming' ? t.decline : t.end, props.onHangUp, { color: c.end }), s.phase === 'incoming' && control('answer', t.answer, props.onAnswer, { color: c.answer })] })] })] });
35
+ }
36
+ export function useCalling(controller) {
37
+ return useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
38
+ }
39
+ /** Mount only when you choose Robono's interface. No global navigation changes. */
40
+ export function CallingOverlay({ controller, ...props }) {
41
+ const state = useCalling(controller);
42
+ useEffect(() => { controller.reportComponents?.(['screens']); }, [controller]);
43
+ useEffect(() => {
44
+ controller.setForeground(AppState.currentState === 'active');
45
+ const sub = AppState.addEventListener('change', value => controller.setForeground(value === 'active'));
46
+ return () => sub.remove();
47
+ }, [controller]);
48
+ const active = state.phase !== 'idle';
49
+ return _jsx(Modal, { visible: active, presentationStyle: "fullScreen", animationType: "none", onRequestClose: () => { void controller.hangUp().catch(() => { }); }, children: active && _jsxs(SafeAreaProvider, { children: [_jsx(StatusBar, { barStyle: callingInk(props.theme?.background || props.appearance?.theme.background || theme.background) === '#000000' ? 'dark-content' : 'light-content' }), _jsx(CallingScreen, { ...props, state: state, onResume: () => { void controller.resume().catch(() => { }); }, onAnswer: () => { void controller.answer().catch(() => { }); }, onHangUp: () => { void controller.hangUp().catch(() => { }); }, onMute: value => controller.mute(value), onSpeaker: value => controller.setSpeaker(value), onClose: () => controller.dismissError() })] }) });
50
+ }
51
+ const styles = StyleSheet.create({
52
+ screen: { flexGrow: 1, paddingHorizontal: 24, justifyContent: 'space-between', gap: 40 },
53
+ identity: { alignItems: 'center', gap: 14 }, avatar: { height: 104, width: 104, borderRadius: 52, alignItems: 'center', justifyContent: 'center', marginBottom: 16 },
54
+ initial: { fontSize: 44, fontWeight: '600' }, name: { fontSize: 28, fontWeight: '600', textAlign: 'center' },
55
+ kind: { fontSize: 16 }, status: { fontSize: 21, marginTop: 8, textAlign: 'center' }, detail: { fontSize: 16, textAlign: 'center' },
56
+ controls: { gap: 30, alignItems: 'center' }, row: { flexDirection: 'row', justifyContent: 'center', gap: 48, flexWrap: 'wrap' },
57
+ button: { alignItems: 'center', gap: 10, minWidth: 80, maxWidth: 140 }, circle: { height: 72, width: 72, borderRadius: 36, alignItems: 'center', justifyContent: 'center' },
58
+ label: { fontSize: 17, textAlign: 'center' }, disabled: { opacity: 0.4 }, close: { paddingVertical: 16, paddingHorizontal: 32, borderRadius: 28 },
59
+ });
@@ -0,0 +1,67 @@
1
+ import type { Call, Request, RobonoCallingClient } from '@robono/calling';
2
+ export type Phase = 'idle' | 'loading' | 'incoming' | 'outgoing' | 'connecting' | 'connected' | 'held' | 'error';
3
+ export interface Contact {
4
+ name: string;
5
+ avatarUri?: string;
6
+ }
7
+ export interface CallingState {
8
+ resumePending?: boolean;
9
+ resumeError?: string | null;
10
+ phase: Phase;
11
+ call: Call | null;
12
+ contact: Contact | null;
13
+ speaker: boolean;
14
+ muted: boolean;
15
+ canMute: boolean;
16
+ canSpeaker: boolean;
17
+ connectedAt: number | null;
18
+ error: string | null;
19
+ localHeld?: boolean;
20
+ }
21
+ export interface CallAudio {
22
+ robonoAdapter?: boolean;
23
+ update(state: {
24
+ phase: Phase;
25
+ speaker: boolean;
26
+ foreground: boolean;
27
+ endTone: boolean;
28
+ cue?: string;
29
+ localHeld?: boolean;
30
+ }): Promise<void> | void;
31
+ dispose(): Promise<void> | void;
32
+ resume?(): Promise<void>;
33
+ }
34
+ export type MediaAdapter = Required<Pick<ConstructorParameters<typeof RobonoCallingClient>[0], 'getUserMedia' | 'createPeerConnection' | 'createRemoteStream' | 'createId'>> & {
35
+ robonoAdapter?: boolean;
36
+ };
37
+ export interface CallingOptions {
38
+ appearanceRevision?: number;
39
+ request: Request;
40
+ media: MediaAdapter;
41
+ audio: CallAudio;
42
+ forceRelay?: boolean;
43
+ resolveContact?: (connectionId: string) => Contact | null;
44
+ onError?: (error: Error) => void;
45
+ }
46
+ export interface CallingController {
47
+ reportComponents?(components: string[]): void;
48
+ readonly client: RobonoCallingClient;
49
+ getSnapshot(): CallingState;
50
+ subscribe(listener: () => void): () => void;
51
+ listen(): Promise<void>;
52
+ refresh(): Promise<boolean>;
53
+ call(connectionId: string, contact?: Contact): Promise<void>;
54
+ answer(): Promise<void>;
55
+ /** Suppress the end cue when the OS currently owns audio. */
56
+ hangUp(options?: {
57
+ playEndTone?: boolean;
58
+ }): Promise<void>;
59
+ interrupt(): Promise<void>;
60
+ resume(): Promise<void>;
61
+ mute(value: boolean): void;
62
+ setSpeaker(value: boolean): void;
63
+ setForeground(value: boolean): void;
64
+ openIncoming(callId: string): Promise<boolean>;
65
+ dismissError(): void;
66
+ dispose(): Promise<void>;
67
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};