@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,209 @@
|
|
|
1
|
+
import React, { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
2
|
+
import { AppState, Modal, Pressable, StatusBar, Text, View } from 'react-native';
|
|
3
|
+
import { setAudioModeAsync } from 'expo-audio';
|
|
4
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
5
|
+
import { createHttpTransport } from '@robono/calling';
|
|
6
|
+
import { CallingScreen, callingInk, createCallingController, validateCallingAppearance, type CallingAppearance, type CallingController, type CallingState, type Contact } from '@robono/calling-react-native';
|
|
7
|
+
import { createNativeCallAdapters } from '@robono/calling-react-native/native';
|
|
8
|
+
import { createNativeCallRuntime, type CallRuntime } from '@robono/calling-react-native/runtime';
|
|
9
|
+
|
|
10
|
+
export interface CallingHostProps {
|
|
11
|
+
accountId: string;
|
|
12
|
+
/** Your authenticated backend returns a session for THIS signed-in account. */
|
|
13
|
+
getSession(): Promise<{serviceUrl: string; token: string; expiresAt: number; appearance?:unknown; appearanceRevision?:number}>;
|
|
14
|
+
/** Supply the HTTPS service origin configured for your integration. */
|
|
15
|
+
serviceOrigin: string;
|
|
16
|
+
connectionId: string;
|
|
17
|
+
contact: Contact;
|
|
18
|
+
resolveContact(connectionId: string): Contact | null;
|
|
19
|
+
notificationCallId?: string;
|
|
20
|
+
/** Clear the consumed notification from your router and push provider. */
|
|
21
|
+
onNotificationConsumed?(callId: string): void;
|
|
22
|
+
onController?(controller: CallingController | null): void;
|
|
23
|
+
/** Supply your own native lifetime adapter if your app already owns calling. */
|
|
24
|
+
createRuntime?(): CallRuntime;
|
|
25
|
+
}
|
|
26
|
+
const idle: CallingState = {phase:'idle',call:null,contact:null,speaker:false,muted:false,canMute:false,canSpeaker:false,connectedAt:null,error:null};
|
|
27
|
+
const emptySubscribe = () => () => {};
|
|
28
|
+
const idleSnapshot = () => idle;
|
|
29
|
+
|
|
30
|
+
/** Mount once under your account provider; keep backend callbacks stable. */
|
|
31
|
+
export function CallingHost(props: CallingHostProps) {
|
|
32
|
+
const cleanup = useRef(Promise.resolve());
|
|
33
|
+
// Account changes discard old contacts, notifications and rendered call state.
|
|
34
|
+
return <AccountCallingHost key={props.accountId} {...props} cleanup={cleanup}/>;
|
|
35
|
+
}
|
|
36
|
+
function AccountCallingHost(props: CallingHostProps & {cleanup: React.MutableRefObject<Promise<void>>}) {
|
|
37
|
+
const [controller, setController] = useState<CallingController | null>(null);
|
|
38
|
+
const [appearance,setAppearance] = useState<CallingAppearance|undefined>();
|
|
39
|
+
const [available, setAvailable] = useState(false);
|
|
40
|
+
const [error, setError] = useState<string | null>(null);
|
|
41
|
+
const [attempt, setAttempt] = useState(0);
|
|
42
|
+
const [booting, setBooting] = useState(true);
|
|
43
|
+
const [consumed, setConsumed] = useState<string | undefined>();
|
|
44
|
+
const handled = useRef(new Set<string>());
|
|
45
|
+
const availabilityNotBefore = useRef(0);
|
|
46
|
+
const idleRenewals = useRef(0);
|
|
47
|
+
const state = useSyncExternalStore(controller?.subscribe || emptySubscribe, controller?.getSnapshot || idleSnapshot, idleSnapshot);
|
|
48
|
+
const pendingNotification = props.notificationCallId && consumed !== props.notificationCallId;
|
|
49
|
+
useEffect(() => { props.onController?.(controller); return () => props.onController?.(null); }, [controller, props.onController]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
let cancelled = false, instance: CallingController | undefined;
|
|
52
|
+
let runtime: CallRuntime | undefined;
|
|
53
|
+
let expiryTimer: ReturnType<typeof setTimeout> | undefined;
|
|
54
|
+
let renewalTimer: ReturnType<typeof setTimeout> | undefined;
|
|
55
|
+
let unsubscribe: (() => void) | undefined;
|
|
56
|
+
let disposal: Promise<void> | undefined;
|
|
57
|
+
const dispose = () => disposal ||= (async () => {
|
|
58
|
+
try { await instance?.dispose(); } finally { await runtime?.dispose(); }
|
|
59
|
+
})().catch(() => {});
|
|
60
|
+
let renewDue = false, renewing = false;
|
|
61
|
+
setBooting(true); setError(null); setAvailable(false);
|
|
62
|
+
const renewWhenIdle = () => {
|
|
63
|
+
if (!cancelled && !renewing && instance?.client.closed) {
|
|
64
|
+
renewing = true; clearTimeout(expiryTimer); clearTimeout(renewalTimer); unsubscribe?.();
|
|
65
|
+
setController(null); setAvailable(false);
|
|
66
|
+
props.cleanup.current = dispose();
|
|
67
|
+
if(instance.client.state.listeningStatus==='session_expired' && instance.getSnapshot().phase==='idle' && idleRenewals.current<6){
|
|
68
|
+
const delay=Math.min(30000,1000*2**idleRenewals.current++);
|
|
69
|
+
renewalTimer=setTimeout(()=>{if(!cancelled)setAttempt(value=>value+1);},delay);
|
|
70
|
+
} else setError('Calling access ended. Reconnect to check your access.');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (!cancelled && renewDue && !renewing && instance?.getSnapshot().phase === 'idle') {
|
|
74
|
+
renewing = true; setAttempt(value => value + 1);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const start = async () => {
|
|
78
|
+
try {
|
|
79
|
+
await props.cleanup.current;
|
|
80
|
+
if (cancelled) return;
|
|
81
|
+
const session = await props.getSession();
|
|
82
|
+
if (cancelled) return;
|
|
83
|
+
const service = new URL(session.serviceUrl);
|
|
84
|
+
if (service.protocol !== 'https:' || service.origin !== props.serviceOrigin || service.username || service.password || service.search || service.hash) throw Error('Unexpected calling service');
|
|
85
|
+
if (!session.token || !Number.isFinite(session.expiresAt) || session.expiresAt - Date.now() < 60000) throw Error('Calling session expired');
|
|
86
|
+
const design=session.appearance===undefined?undefined:validateCallingAppearance(session.appearance);
|
|
87
|
+
setAppearance(design);
|
|
88
|
+
runtime = props.createRuntime?.() || createNativeCallRuntime({
|
|
89
|
+
notificationTitle:'Voice call', notificationText:'Call in progress', channelName:'Ongoing calls', endLabel:'End call',
|
|
90
|
+
onError:() => { if (!cancelled) setError('The call was interrupted.'); },
|
|
91
|
+
});
|
|
92
|
+
const adapters = createNativeCallAdapters({
|
|
93
|
+
runtime, appearance:design,
|
|
94
|
+
ringtone:'robono', onError:() => { if (!cancelled) setError('Call audio is unavailable.'); },
|
|
95
|
+
restoreAudio:() => setAudioModeAsync({allowsRecording:false,playsInSilentMode:true,
|
|
96
|
+
interruptionMode:'duckOthers',shouldPlayInBackground:false,shouldRouteThroughEarpiece:false}),
|
|
97
|
+
});
|
|
98
|
+
instance = createCallingController({request:createHttpTransport({baseUrl:session.serviceUrl,token:session.token}),
|
|
99
|
+
...adapters, appearanceRevision:session.appearanceRevision, resolveContact:props.resolveContact,
|
|
100
|
+
onError:() => { if (!cancelled) setError('The call could not connect. Please try again.'); }});
|
|
101
|
+
instance.setForeground(AppState.currentState === 'active');
|
|
102
|
+
runtime.attach(instance);
|
|
103
|
+
unsubscribe = instance.subscribe(renewWhenIdle);
|
|
104
|
+
setController(instance);
|
|
105
|
+
await instance.listen();
|
|
106
|
+
instance.reportComponents?.(['screens']);
|
|
107
|
+
if (cancelled || renewing) return;
|
|
108
|
+
setBooting(false);
|
|
109
|
+
// Renew only while idle. A new session cannot take over an active call.
|
|
110
|
+
renewalTimer = setTimeout(() => { renewDue = true; renewWhenIdle(); }, session.expiresAt - Date.now() - 30000);
|
|
111
|
+
expiryTimer = setTimeout(() => {
|
|
112
|
+
if (cancelled) return;
|
|
113
|
+
renewing = true; unsubscribe?.();
|
|
114
|
+
setController(null); setAvailable(false);
|
|
115
|
+
setError('Your calling session expired. Reconnect to make or receive calls.');
|
|
116
|
+
props.cleanup.current = dispose();
|
|
117
|
+
}, session.expiresAt - Date.now());
|
|
118
|
+
} catch {
|
|
119
|
+
if (!cancelled) {
|
|
120
|
+
if (instance || runtime) props.cleanup.current = dispose();
|
|
121
|
+
setController(null); setBooting(false); setError('Calling is unavailable. Please try again.');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
void start();
|
|
126
|
+
return () => {
|
|
127
|
+
cancelled = true; clearTimeout(expiryTimer); clearTimeout(renewalTimer); unsubscribe?.();
|
|
128
|
+
setController(null); setAvailable(false);
|
|
129
|
+
if (instance || runtime) props.cleanup.current = dispose();
|
|
130
|
+
};
|
|
131
|
+
}, [attempt, props.getSession, props.resolveContact, props.serviceOrigin, props.cleanup, props.createRuntime]);
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
let cancelled = false, timer: ReturnType<typeof setTimeout> | undefined, checking = false, failures = 0;
|
|
134
|
+
setAvailable(false);
|
|
135
|
+
const check = async () => {
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
if (!controller || cancelled || checking) return;
|
|
138
|
+
if (AppState.currentState !== 'active' || controller.getSnapshot().phase !== 'idle') return;
|
|
139
|
+
if (Date.now() < availabilityNotBefore.current) {
|
|
140
|
+
timer = setTimeout(check, availabilityNotBefore.current - Date.now()); return;
|
|
141
|
+
}
|
|
142
|
+
checking = true;
|
|
143
|
+
let nextCheck = 0;
|
|
144
|
+
try {
|
|
145
|
+
const result = await controller.client.availability(props.connectionId);
|
|
146
|
+
availabilityNotBefore.current = 0; failures = 0;
|
|
147
|
+
if (!cancelled) setAvailable(result.voiceAvailable);
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!cancelled) setAvailable(false);
|
|
150
|
+
nextCheck = Math.min(30000, 1000 * 2 ** failures++);
|
|
151
|
+
const retryAfter = (error as {retryAfterMs?: number}).retryAfterMs;
|
|
152
|
+
if (Number.isFinite(retryAfter)) nextCheck = Math.min(2147483647, Math.max(nextCheck, retryAfter!));
|
|
153
|
+
availabilityNotBefore.current = Date.now() + nextCheck;
|
|
154
|
+
}
|
|
155
|
+
finally { checking = false; if (!cancelled && nextCheck > 0 && failures < 6) timer = setTimeout(check, nextCheck); }
|
|
156
|
+
};
|
|
157
|
+
const sub = AppState.addEventListener('change', value => {
|
|
158
|
+
controller?.setForeground(value === 'active');
|
|
159
|
+
if (value === 'active') { failures = 0; void check(); }
|
|
160
|
+
else clearTimeout(timer);
|
|
161
|
+
});
|
|
162
|
+
void check();
|
|
163
|
+
return () => { cancelled = true; clearTimeout(timer); sub.remove(); };
|
|
164
|
+
}, [controller, props.connectionId, state.phase]);
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
const id = props.notificationCallId;
|
|
167
|
+
if (!controller || !id || handled.current.has(id)) return;
|
|
168
|
+
handled.current.add(id);
|
|
169
|
+
// openIncoming publishes loading synchronously, before removing startup cover.
|
|
170
|
+
void controller.openIncoming(id).catch(() => setError('This call could not be opened.'));
|
|
171
|
+
setConsumed(id); props.onNotificationConsumed?.(id);
|
|
172
|
+
}, [controller, props.notificationCallId, props.onNotificationConsumed]);
|
|
173
|
+
const close = () => {
|
|
174
|
+
if (pendingNotification && props.notificationCallId) {
|
|
175
|
+
handled.current.add(props.notificationCallId); setConsumed(props.notificationCallId);
|
|
176
|
+
props.onNotificationConsumed?.(props.notificationCallId);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (state.phase === 'error') controller?.dismissError();
|
|
180
|
+
else void controller?.hangUp().catch(() => setError('The call could not be ended.'));
|
|
181
|
+
};
|
|
182
|
+
const call = async () => {
|
|
183
|
+
if (!controller) return;
|
|
184
|
+
setError(null);
|
|
185
|
+
try {
|
|
186
|
+
if (!(await controller.client.availability(props.connectionId)).voiceAvailable) {
|
|
187
|
+
setAvailable(false); setError('This contact cannot receive a call right now.'); return;
|
|
188
|
+
}
|
|
189
|
+
await controller.call(props.connectionId, props.contact);
|
|
190
|
+
} catch { setError('The call could not connect. Please try again.'); }
|
|
191
|
+
};
|
|
192
|
+
const visible = state.phase !== 'idle' || !!pendingNotification;
|
|
193
|
+
const screen = pendingNotification && state.phase === 'idle'
|
|
194
|
+
? {...idle, phase:(!booting && !controller ? 'error' : 'loading') as CallingState['phase'], error:!booting && !controller ? 'call_unavailable' : null}
|
|
195
|
+
: state;
|
|
196
|
+
return <View>
|
|
197
|
+
{error && <Text accessibilityRole="alert">{error}</Text>}
|
|
198
|
+
{!controller && !booting && <Pressable accessibilityRole="button" onPress={() => setAttempt(value => value + 1)}><Text>Reconnect calling</Text></Pressable>}
|
|
199
|
+
<Pressable accessibilityRole="button" accessibilityState={{disabled:!available}} disabled={!available} onPress={() => { void call(); }}>
|
|
200
|
+
<Text>Call {props.contact.name}</Text>
|
|
201
|
+
</Pressable>
|
|
202
|
+
<Modal visible={visible} presentationStyle="fullScreen" animationType="none" onRequestClose={close}>
|
|
203
|
+
{visible && <SafeAreaProvider><StatusBar barStyle={callingInk(appearance?.theme.background||'#080808')==='#000000'?'dark-content':'light-content'}/><CallingScreen state={screen} appearance={appearance}
|
|
204
|
+
onResume={() => { void controller?.resume().catch(() => {}); }}
|
|
205
|
+
onAnswer={() => { void controller?.answer().catch(() => {}); }} onHangUp={close} onClose={close}
|
|
206
|
+
onMute={value => controller?.mute(value)} onSpeaker={value => controller?.setSpeaker(value)}/></SafeAreaProvider>}
|
|
207
|
+
</Modal>
|
|
208
|
+
</View>;
|
|
209
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React, {useCallback, useEffect, useRef, useState} from 'react';
|
|
2
|
+
import type {CallingController} from '@robono/calling-react-native';
|
|
3
|
+
import type {NotificationStore} from '@robono/calling-react-native/notifications';
|
|
4
|
+
import {connectExpoCallingNotifications} from '@robono/calling-react-native/expo-notifications';
|
|
5
|
+
import {CallingHost, type CallingHostProps} from './CallingHost';
|
|
6
|
+
|
|
7
|
+
export interface ExpoCallingHostProps extends Omit<CallingHostProps, 'notificationCallId' | 'onNotificationConsumed' | 'onController'> {
|
|
8
|
+
notificationStore: NotificationStore;
|
|
9
|
+
/** Return the account identifier your backend attached to this push. */
|
|
10
|
+
recipientAccount(data: unknown): string | null;
|
|
11
|
+
onNotificationError(error: Error): void;
|
|
12
|
+
/** Use this readiness in withCallingNotificationPresentation's callback. */
|
|
13
|
+
onReadyChange?(ready: boolean): void;
|
|
14
|
+
}
|
|
15
|
+
/** Place above chat navigation after restoring the signed-in account. */
|
|
16
|
+
export function ExpoCallingHost(props: ExpoCallingHostProps) {
|
|
17
|
+
return <AccountNotifications key={props.accountId} {...props}/>;
|
|
18
|
+
}
|
|
19
|
+
function AccountNotifications(props: ExpoCallingHostProps) {
|
|
20
|
+
const current = useRef<CallingController | null>(null);
|
|
21
|
+
const pendingRefresh = useRef(false);
|
|
22
|
+
const [callId, setCallId] = useState<string>();
|
|
23
|
+
const onController = useCallback((controller: CallingController | null) => {
|
|
24
|
+
current.current = controller;
|
|
25
|
+
props.onReadyChange?.(!!controller);
|
|
26
|
+
if (controller && pendingRefresh.current) {
|
|
27
|
+
pendingRefresh.current = false;
|
|
28
|
+
void controller.refresh().catch(props.onNotificationError);
|
|
29
|
+
}
|
|
30
|
+
}, [props.onNotificationError, props.onReadyChange]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const notifications = connectExpoCallingNotifications({
|
|
33
|
+
accountKey:props.accountId, store:props.notificationStore,
|
|
34
|
+
recipientAccount:props.recipientAccount, open:setCallId,
|
|
35
|
+
refresh:async () => { if (current.current) await current.current.refresh(); else pendingRefresh.current = true; },
|
|
36
|
+
onError:props.onNotificationError,
|
|
37
|
+
});
|
|
38
|
+
return () => notifications.dispose();
|
|
39
|
+
}, [props.accountId, props.notificationStore, props.recipientAccount, props.onNotificationError]);
|
|
40
|
+
const consumed = useCallback((id: string) => setCallId(value => value === id ? undefined : value), []);
|
|
41
|
+
return <CallingHost {...props} notificationCallId={callId} onController={onController} onNotificationConsumed={consumed}/>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#import <React/RCTBridgeModule.h>
|
|
2
|
+
#import <React/RCTEventEmitter.h>
|
|
3
|
+
#import <AVFAudio/AVFAudio.h>
|
|
4
|
+
#import <UIKit/UIKit.h>
|
|
5
|
+
|
|
6
|
+
@interface RobonoCallingRuntime : RCTEventEmitter <RCTBridgeModule>
|
|
7
|
+
@property(nonatomic, copy) NSString *owner;
|
|
8
|
+
@property(nonatomic) BOOL observing;
|
|
9
|
+
@property(nonatomic, strong) NSTimer *clock;
|
|
10
|
+
@property(nonatomic) UIBackgroundTaskIdentifier interruptionTask;
|
|
11
|
+
@end
|
|
12
|
+
|
|
13
|
+
@implementation RobonoCallingRuntime
|
|
14
|
+
RCT_EXPORT_MODULE();
|
|
15
|
+
+ (BOOL)requiresMainQueueSetup { return YES; }
|
|
16
|
+
- (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); }
|
|
17
|
+
- (NSArray<NSString *> *)supportedEvents { return @[@"RobonoCallingRuntimeEvent"]; }
|
|
18
|
+
- (void)startObserving {
|
|
19
|
+
self.interruptionTask = UIBackgroundTaskInvalid;
|
|
20
|
+
self.observing = YES;
|
|
21
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(interrupted:) name:AVAudioSessionInterruptionNotification object:nil];
|
|
22
|
+
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reset:) name:AVAudioSessionMediaServicesWereResetNotification object:nil];
|
|
23
|
+
}
|
|
24
|
+
- (void)stopObserving { self.observing = NO; [[NSNotificationCenter defaultCenter] removeObserver:self]; }
|
|
25
|
+
- (void)reset:(NSNotification *)note {
|
|
26
|
+
NSString *token = [self.owner copy];
|
|
27
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
28
|
+
if (token && [self.owner isEqualToString:token] && self.observing) [self sendEventWithName:@"RobonoCallingRuntimeEvent" body:@{@"token":token,@"type":@"audioReset"}];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
- (void)interrupted:(NSNotification *)note {
|
|
32
|
+
NSString *token = [self.owner copy];
|
|
33
|
+
BOOL began = [note.userInfo[AVAudioSessionInterruptionTypeKey] unsignedIntegerValue] == AVAudioSessionInterruptionTypeBegan;
|
|
34
|
+
BOOL shouldResume = ([note.userInfo[AVAudioSessionInterruptionOptionKey] unsignedIntegerValue] & AVAudioSessionInterruptionOptionShouldResume) != 0;
|
|
35
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
36
|
+
if (!token || ![self.owner isEqualToString:token] || !self.observing) return;
|
|
37
|
+
if (began && self.interruptionTask == UIBackgroundTaskInvalid) {
|
|
38
|
+
// Just enough time to acknowledge hold before audio suspension. No silent
|
|
39
|
+
// playback, indefinite background task or takeover of the cellular call.
|
|
40
|
+
self.interruptionTask = [UIApplication.sharedApplication beginBackgroundTaskWithName:@"Robono call hold" expirationHandler:^{ [self finishInterruptionTask]; }];
|
|
41
|
+
}
|
|
42
|
+
[self sendEventWithName:@"RobonoCallingRuntimeEvent" body:@{@"token":token,@"type":began ? @"interrupted" : @"interruptionEnded",@"shouldResume":@(shouldResume)}];
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
- (void)finishInterruptionTask {
|
|
46
|
+
if (self.interruptionTask != UIBackgroundTaskInvalid) {
|
|
47
|
+
UIBackgroundTaskIdentifier task = self.interruptionTask; self.interruptionTask = UIBackgroundTaskInvalid;
|
|
48
|
+
[UIApplication.sharedApplication endBackgroundTask:task];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
RCT_EXPORT_METHOD(interruptionHandled:(NSString *)token) {
|
|
52
|
+
if ([self.owner isEqualToString:token]) [self finishInterruptionTask];
|
|
53
|
+
}
|
|
54
|
+
RCT_REMAP_METHOD(activateAudio, activateAudio:(NSString *)token resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
55
|
+
if (![self.owner isEqualToString:token]) { reject(@"call_cancelled", @"The call has ended.", nil); return; }
|
|
56
|
+
NSError *error = nil;
|
|
57
|
+
if (![[AVAudioSession sharedInstance] setActive:YES error:&error]) {
|
|
58
|
+
reject(@"audio_still_interrupted", @"Audio is in use by another call.", error); return;
|
|
59
|
+
}
|
|
60
|
+
resolve(nil);
|
|
61
|
+
}
|
|
62
|
+
- (void)tick:(NSTimer *)timer {
|
|
63
|
+
if (self.owner && self.observing) [self sendEventWithName:@"RobonoCallingRuntimeEvent" body:@{@"token":self.owner,@"type":@"tick"}];
|
|
64
|
+
}
|
|
65
|
+
RCT_REMAP_METHOD(begin, begin:(NSString *)token title:(NSString *)title text:(NSString *)text channel:(NSString *)channel endLabel:(NSString *)endLabel resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
66
|
+
if (self.owner && ![self.owner isEqualToString:token]) { reject(@"audio_busy", @"Another call owns audio.", nil); return; }
|
|
67
|
+
if (UIApplication.sharedApplication.applicationState != UIApplicationStateActive) { reject(@"open_app_to_start_call", @"Open the app to start a call.", nil); return; }
|
|
68
|
+
NSArray *modes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIBackgroundModes"];
|
|
69
|
+
if (![modes containsObject:@"audio"]) { reject(@"background_audio_not_configured", @"Enable the audio background mode for ongoing calls.", nil); return; }
|
|
70
|
+
self.owner = token;
|
|
71
|
+
if (!self.clock) {
|
|
72
|
+
self.clock = [NSTimer timerWithTimeInterval:0.25 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
|
|
73
|
+
[[NSRunLoop mainRunLoop] addTimer:self.clock forMode:NSRunLoopCommonModes];
|
|
74
|
+
}
|
|
75
|
+
// The chosen media/audio adapter owns AVAudioSession. This module observes it;
|
|
76
|
+
// it never replaces the host's category or installs a system calling screen.
|
|
77
|
+
resolve(nil);
|
|
78
|
+
}
|
|
79
|
+
RCT_REMAP_METHOD(end, end:(NSString *)token resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
|
|
80
|
+
if ([self.owner isEqualToString:token]) { self.owner = nil; [self.clock invalidate]; self.clock = nil; [self finishInterruptionTask]; }
|
|
81
|
+
resolve(nil);
|
|
82
|
+
}
|
|
83
|
+
- (void)invalidate { self.owner = nil; [self.clock invalidate]; self.clock = nil; [self finishInterruptionTask]; [self stopObserving]; [super invalidate]; }
|
|
84
|
+
@end
|
package/package.json
CHANGED
|
@@ -1,6 +1,101 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@robono/calling-react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "Optional branded calling screens, sounds and native audio adapters for Robono calling.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./native": {
|
|
15
|
+
"types": "./dist/native.d.ts",
|
|
16
|
+
"default": "./dist/native.js"
|
|
17
|
+
},
|
|
18
|
+
"./notifications": {
|
|
19
|
+
"types": "./dist/notifications.d.ts",
|
|
20
|
+
"default": "./dist/notifications.js"
|
|
21
|
+
},
|
|
22
|
+
"./notification-router": {
|
|
23
|
+
"types": "./dist/notification-router.d.ts",
|
|
24
|
+
"default": "./dist/notification-router.js"
|
|
25
|
+
},
|
|
26
|
+
"./expo-notifications": {
|
|
27
|
+
"types": "./dist/expo-notifications.d.ts",
|
|
28
|
+
"default": "./dist/expo-notifications.js"
|
|
29
|
+
},
|
|
30
|
+
"./runtime": {
|
|
31
|
+
"types": "./dist/runtime.d.ts",
|
|
32
|
+
"default": "./dist/runtime.js"
|
|
33
|
+
},
|
|
34
|
+
"./app.plugin": "./app.plugin.cjs",
|
|
35
|
+
"./assets/*": "./assets/*",
|
|
36
|
+
"./appearance": {
|
|
37
|
+
"types": "./dist/appearance.d.ts",
|
|
38
|
+
"default": "./dist/appearance.js"
|
|
39
|
+
},
|
|
40
|
+
"./app.plugin.js": "./app.plugin.cjs",
|
|
41
|
+
"./app.plugin.cjs": "./app.plugin.cjs"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"dist",
|
|
45
|
+
"assets",
|
|
46
|
+
"examples",
|
|
47
|
+
"ios",
|
|
48
|
+
"RobonoCallingRuntime.podspec",
|
|
49
|
+
"react-native.config.js",
|
|
50
|
+
"app.plugin.cjs",
|
|
51
|
+
"README.md",
|
|
52
|
+
"CHANGELOG.md",
|
|
53
|
+
"LICENSE",
|
|
54
|
+
"SBOM.spdx.json",
|
|
55
|
+
"android/build.gradle",
|
|
56
|
+
"android/src/main"
|
|
57
|
+
],
|
|
58
|
+
"devDependencies": {
|
|
59
|
+
"typescript": "~6.0.3",
|
|
60
|
+
"@types/react": "~19.2.2"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@robono/calling": "^0.1.3",
|
|
64
|
+
"react": ">=18.2 <20",
|
|
65
|
+
"react-native": ">=0.76 <1",
|
|
66
|
+
"react-native-svg": ">=15 <16",
|
|
67
|
+
"react-native-safe-area-context": ">=5 <6",
|
|
68
|
+
"react-native-webrtc": ">=124 <125",
|
|
69
|
+
"react-native-incall-manager": ">=4.2 <5",
|
|
70
|
+
"expo-audio": ">=1.1.1 <2 || >=55 <57",
|
|
71
|
+
"expo-crypto": ">=15.0.9 <16 || >=55 <57",
|
|
72
|
+
"expo-notifications": ">=0.32.17 <0.33 || >=55 <57"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"react-native-webrtc": {
|
|
76
|
+
"optional": true
|
|
77
|
+
},
|
|
78
|
+
"react-native-incall-manager": {
|
|
79
|
+
"optional": true
|
|
80
|
+
},
|
|
81
|
+
"expo-audio": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"expo-crypto": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"expo-notifications": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
92
|
+
"homepage": "https://robono.com/docs#calling",
|
|
93
|
+
"repository": {
|
|
94
|
+
"type": "git",
|
|
95
|
+
"url": "git+https://github.com/IMLX16/robono-sdks.git",
|
|
96
|
+
"directory": "packages/calling-react-native"
|
|
97
|
+
},
|
|
98
|
+
"bugs": {
|
|
99
|
+
"url": "https://robono.com/contact?topic=sdk"
|
|
100
|
+
}
|
|
101
|
+
}
|