@robono/calling-react-native 0.2.2 → 0.3.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 +15 -2
- package/README.md +94 -3
- package/RobonoCallingRuntime.podspec +1 -1
- package/SBOM.spdx.json +972 -156
- package/android/build.gradle +1 -1
- package/android/consumer-rules.pro +5 -0
- package/android/src/main/java/com/robono/calling/CallingRuntime.java +21 -0
- package/app.plugin.cjs +4 -2
- package/broadcast/SampleHandler.swift +92 -0
- package/dist/CallRecord.d.ts +19 -0
- package/dist/CallRecord.js +22 -0
- package/dist/appearance.d.ts +69 -4
- package/dist/appearance.js +70 -5
- package/dist/components.d.ts +135 -0
- package/dist/components.js +185 -0
- package/dist/controller.d.mts +1 -1
- package/dist/controller.mjs +59 -7
- package/dist/expo-notifications.d.ts +1 -1
- package/dist/expo-notifications.js +3 -3
- package/dist/group-phase.d.mts +4 -0
- package/dist/group-phase.mjs +26 -0
- package/dist/groups.d.ts +41 -0
- package/dist/groups.js +90 -0
- package/dist/history.d.ts +6 -15
- package/dist/history.js +3 -11
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/dist/native-video.d.ts +8 -0
- package/dist/native-video.js +10 -0
- package/dist/native.d.ts +2 -0
- package/dist/native.js +51 -2
- package/dist/notification-router.d.ts +2 -1
- package/dist/notification-router.js +4 -4
- package/dist/notifications.d.ts +5 -3
- package/dist/notifications.js +7 -5
- package/dist/runtime.d.ts +2 -1
- package/dist/runtime.js +1 -1
- package/dist/screens.d.ts +6 -54
- package/dist/screens.js +17 -42
- package/dist/types.d.ts +38 -1
- package/dist/versions.d.ts +2 -0
- package/dist/versions.js +3 -0
- package/dist/visual/RobonoIcon.d.ts +232 -0
- package/dist/visual/RobonoIcon.js +20 -0
- package/dist/visual/icon-nodes.d.ts +3 -0
- package/dist/visual/icon-nodes.js +2 -0
- package/dist/visual/icon-paths.d.ts +221 -0
- package/dist/visual/icon-paths.js +221 -0
- package/examples/CallingHost.tsx +16 -8
- package/examples/CustomCallingScreen.tsx +64 -0
- package/examples/ExpoGroupCallingHost.tsx +42 -0
- package/examples/GroupCallingHost.tsx +70 -0
- package/ios/RobonoCallingRuntime.m +24 -0
- package/licenses/robono-icons-lucide-license.txt +43 -0
- package/licenses/robono-icons-weather-attribution.txt +1 -0
- package/licenses/robono-icons-weather-license.txt +21 -0
- package/package.json +21 -4
- package/plugin/screensharing.cjs +39 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useEffect, useState } from 'react';
|
|
3
|
+
import { Image, Platform, Pressable, ScrollView, StyleSheet, Text, View, useColorScheme } from 'react-native';
|
|
4
|
+
import { RobonoIcon } from './visual/RobonoIcon.js';
|
|
5
|
+
import { SafeAreaInsetsContext } from 'react-native-safe-area-context';
|
|
6
|
+
import { callingText, callingInk, resolveCallingDesign } from './appearance.js';
|
|
7
|
+
const CallingUIContext = createContext(null);
|
|
8
|
+
/** Read the same state, labels and guarded actions used by the supplied components. */
|
|
9
|
+
export function useCallingUI() {
|
|
10
|
+
const value = useContext(CallingUIContext);
|
|
11
|
+
if (!value)
|
|
12
|
+
throw Error('Calling components must be inside CallingUIProvider, CallingScreen or CallingOverlay.');
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
/** Presentation only: does not create a client, request microphone access or own audio. */
|
|
16
|
+
export function CallingUIProvider({ children, ...props }) {
|
|
17
|
+
const safeArea = useContext(SafeAreaInsetsContext);
|
|
18
|
+
const design = resolveCallingDesign(props.appearance, useColorScheme());
|
|
19
|
+
const c = { ...design.colors, ...props.theme };
|
|
20
|
+
const t = { ...callingText, ...props.appearance?.labels, ...props.labels };
|
|
21
|
+
const s = props.state;
|
|
22
|
+
const [clock, setClock] = useState(Date.now());
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (s.phase !== 'connected')
|
|
25
|
+
return;
|
|
26
|
+
setClock(Date.now());
|
|
27
|
+
const timer = setInterval(() => setClock(Date.now()), 1000);
|
|
28
|
+
return () => clearInterval(timer);
|
|
29
|
+
}, [s.phase, s.connectedAt]);
|
|
30
|
+
const seconds = s.connectedAt == null ? 0 : Math.max(0, Math.floor((clock - s.connectedAt) / 1000));
|
|
31
|
+
const duration = `${Math.floor(seconds / 60)}:${String(seconds % 60).padStart(2, '0')}`;
|
|
32
|
+
const error = s.phase === 'held'
|
|
33
|
+
? (s.resumeError ? props.formatError?.(s.resumeError) || (s.resumeError === 'audio_still_interrupted' ? t.audioBusy : t.resumeFailed) : null)
|
|
34
|
+
: s.error ? props.formatError?.(s.error) || (s.error === 'call_unavailable' ? t.unavailable : t.failed) : null;
|
|
35
|
+
const audio = ['outgoing', 'connecting', 'connected'].includes(s.phase);
|
|
36
|
+
const action = (label, visible, onPress, options = {}) => {
|
|
37
|
+
const disabled = !visible || !!options.disabled;
|
|
38
|
+
return { label, visible, selected: false, busy: false, ...options, disabled, onPress: () => { if (!disabled)
|
|
39
|
+
onPress(); } };
|
|
40
|
+
};
|
|
41
|
+
const actions = {
|
|
42
|
+
share: action(s.screenSharing ? t.stopSharing : t.shareScreen, s.kind === 'video' && audio && !!props.onScreenShare && !!s.canScreenShare, () => props.onScreenShare?.(), { icon: 'share', disabled: s.screenSharePending, selected: s.screenSharing }),
|
|
43
|
+
camera: action(s.cameraEnabled === false ? t.cameraOn : t.cameraOff, s.kind === 'video' && audio && !!props.onCamera, () => props.onCamera?.(s.cameraEnabled === false), { icon: 'camera', disabled: !s.canCamera || s.screenSharing, selected: s.cameraEnabled !== false }),
|
|
44
|
+
flip: action(t.switchCamera, s.kind === 'video' && audio && !!props.onSwitchCamera, () => props.onSwitchCamera?.(), { icon: 'flip', disabled: !s.canCamera || s.screenSharing }),
|
|
45
|
+
answer: action(t.answer, s.phase === 'incoming', props.onAnswer, { icon: 'answer', color: c.answer }),
|
|
46
|
+
decline: action(t.decline, s.phase === 'incoming', props.onHangUp, { icon: 'end', color: c.end }),
|
|
47
|
+
mute: action(s.muted ? t.unmute : t.mute, audio, () => props.onMute(!s.muted), { icon: 'mute', disabled: !s.canMute, selected: s.muted }),
|
|
48
|
+
speaker: action(t.speaker, audio, () => props.onSpeaker(!s.speaker), { icon: 'speaker', disabled: !s.canSpeaker, selected: s.speaker }),
|
|
49
|
+
resume: action(s.resumePending ? t.resuming : t.resume, s.phase === 'held' && !!s.localHeld && !!props.onResume, () => props.onResume?.(), { disabled: !!s.resumePending, busy: !!s.resumePending }),
|
|
50
|
+
end: action(t.end, audio || s.phase === 'held', props.onHangUp, { icon: 'end', color: c.end }),
|
|
51
|
+
close: action(t.close, s.phase === 'error' || s.phase === 'loading', s.phase === 'loading' ? props.onHangUp : props.onClose),
|
|
52
|
+
};
|
|
53
|
+
const fontFamily = Platform.OS === 'ios' ? design.fontFamily.ios : Platform.OS === 'android' ? design.fontFamily.android : design.fontFamily.web;
|
|
54
|
+
const value = {
|
|
55
|
+
state: s, renderVideo: props.renderVideo, appearance: props.appearance, theme: c, labels: t, design,
|
|
56
|
+
insets: props.insets || safeArea, components: props.components || {},
|
|
57
|
+
title: s.contact?.name || t.contact,
|
|
58
|
+
status: s.phase === 'connected' ? duration : s.phase === 'error' || s.phase === 'idle' ? '' : s.phase === 'incoming' && s.kind === 'video' ? t.incomingVideo : t[s.phase],
|
|
59
|
+
error, actions, typography: size => ({ fontFamily, fontSize: size * design.presentation.textScale }),
|
|
60
|
+
};
|
|
61
|
+
return s.phase === 'idle' ? null : _jsx(CallingUIContext.Provider, { value: value, children: children });
|
|
62
|
+
}
|
|
63
|
+
/** Scrollable, safe-area-aware frame. Use it when composing your own layout. */
|
|
64
|
+
export function CallingLayout({ children, style, contentContainerStyle }) {
|
|
65
|
+
const { theme, insets, state } = useCallingUI();
|
|
66
|
+
if ((state.kind === 'video' || state.group) && !['incoming', 'error', 'loading'].includes(state.phase))
|
|
67
|
+
return _jsx(View, { style: [{ flex: 1, backgroundColor: theme.background, paddingTop: insets?.top ?? 16, paddingBottom: insets?.bottom ?? 16, paddingHorizontal: 12, gap: 8 }, style], children: children });
|
|
68
|
+
return _jsx(ScrollView, { style: [{ flex: 1, backgroundColor: theme.background }, style], contentContainerStyle: [styles.screen, {
|
|
69
|
+
paddingTop: Math.max(36, insets?.top || 0) + 32,
|
|
70
|
+
paddingBottom: Math.max(24, insets?.bottom ?? 48) + 16,
|
|
71
|
+
}, contentContainerStyle], children: children });
|
|
72
|
+
}
|
|
73
|
+
export function CallingBrand({ style } = {}) {
|
|
74
|
+
const { appearance, theme, typography } = useCallingUI();
|
|
75
|
+
if (!appearance?.logoUrl && !appearance?.appName)
|
|
76
|
+
return null;
|
|
77
|
+
return _jsxs(View, { style: [styles.brand, style], children: [!!appearance?.logoUrl && _jsx(Image, { source: { uri: appearance.logoUrl }, style: styles.logo, resizeMode: "contain" }), _jsx(Text, { style: [typography(14), { color: theme.secondary, flexShrink: 1, textAlign: 'center' }], children: appearance?.appName })] });
|
|
78
|
+
}
|
|
79
|
+
export function CallingAvatar({ size } = {}) {
|
|
80
|
+
const { state, title, design, theme, typography } = useCallingUI();
|
|
81
|
+
if (!design.presentation.showAvatar)
|
|
82
|
+
return null;
|
|
83
|
+
const width = size ?? design.avatarSize;
|
|
84
|
+
const style = { height: width, width, borderRadius: width / 2 };
|
|
85
|
+
return state.contact?.avatarUri
|
|
86
|
+
? _jsx(Image, { source: { uri: state.contact.avatarUri }, style: [styles.avatar, style], accessibilityIgnoresInvertColors: true })
|
|
87
|
+
: _jsx(View, { style: [styles.avatar, style, { backgroundColor: theme.control }], children: _jsx(Text, { style: [styles.initial, typography(size !== undefined ? size * 44 / 104 : design.presentation.layout === 'compact' ? 30 : 44), { color: theme.accent }], children: title.trim().charAt(0).toUpperCase() }) });
|
|
88
|
+
}
|
|
89
|
+
export function CallingContact({ nameStyle, descriptionStyle } = {}) {
|
|
90
|
+
const { title, labels, theme, design, typography, state } = useCallingUI();
|
|
91
|
+
return _jsxs(_Fragment, { children: [_jsx(Text, { style: [styles.name, typography(28), { color: theme.foreground }, nameStyle], children: title }), design.presentation.showCallDescription && _jsx(Text, { style: [styles.kind, typography(16), { color: theme.secondary }, descriptionStyle], children: state.kind === 'video' ? labels.videoCall : labels.call })] });
|
|
92
|
+
}
|
|
93
|
+
export function CallingStatus({ style, detailStyle } = {}) {
|
|
94
|
+
const { state, status, error, labels, theme, typography } = useCallingUI();
|
|
95
|
+
return _jsxs(_Fragment, { children: [_jsx(Text, { style: [styles.status, typography(21), { color: theme.foreground }, style], accessibilityLiveRegion: state.phase === 'connected' ? 'none' : 'polite', children: status }), state.phase === 'held' && state.localHeld && _jsx(Text, { style: [styles.detail, typography(16), { color: theme.secondary }, detailStyle], children: labels.localHold }), !!error && _jsx(Text, { accessibilityRole: "alert", style: [styles.detail, typography(16), { color: theme.foreground }, detailStyle], children: error })] });
|
|
96
|
+
}
|
|
97
|
+
export function CallingIdentity({ style } = {}) {
|
|
98
|
+
const { components, design, state } = useCallingUI();
|
|
99
|
+
const Brand = components.Brand || CallingBrand, Avatar = components.Avatar || CallingAvatar;
|
|
100
|
+
const Contact = components.Contact || CallingContact, Status = components.Status || CallingStatus;
|
|
101
|
+
if ((state.kind === 'video' || state.group) && !['incoming', 'error', 'loading'].includes(state.phase))
|
|
102
|
+
return _jsxs(View, { style: [styles.identity, { gap: 2 }, style], children: [_jsx(Contact, { nameStyle: { fontSize: 18 }, descriptionStyle: { fontSize: 13 } }), _jsx(Status, { style: { fontSize: 14, marginTop: 0 } })] });
|
|
103
|
+
return _jsxs(View, { style: [styles.identity, { gap: design.identityGap }, style], children: [_jsx(Brand, {}), _jsx(Avatar, {}), _jsx(Contact, {}), _jsx(Status, {})] });
|
|
104
|
+
}
|
|
105
|
+
function ControlIcon({ name, color, muted }) {
|
|
106
|
+
const names = { share: 'screen-share', camera: muted ? 'video-off' : 'video', flip: 'flip', answer: 'phone', end: 'phone-end', mute: muted ? 'mic-off' : 'mic', speaker: 'speaker' };
|
|
107
|
+
return _jsx(RobonoIcon, { name: names[name], size: 30, color: color });
|
|
108
|
+
}
|
|
109
|
+
/** A state-aware button. Hidden actions render nothing; unavailable actions are disabled. */
|
|
110
|
+
export function CallingActionButton({ action, style, iconStyle, labelStyle }) {
|
|
111
|
+
const { actions, theme: c, design, typography, state } = useCallingUI();
|
|
112
|
+
const a = actions[action];
|
|
113
|
+
if (!a.visible)
|
|
114
|
+
return null;
|
|
115
|
+
return _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: a.label, accessibilityState: { disabled: a.disabled, selected: a.selected, busy: a.busy }, disabled: a.disabled, onPress: a.onPress, hitSlop: 8, style: [a.icon ? styles.button : [styles.close, { backgroundColor: c.control }], a.disabled && styles.disabled, style], children: [a.icon && _jsx(View, { style: [styles.circle, { borderRadius: design.controlRadius, backgroundColor: a.color || (a.selected ? c.foreground : c.control) }, iconStyle], children: _jsx(ControlIcon, { name: a.icon, muted: action === 'mute' && state.muted || action === 'camera' && state.cameraEnabled === false, color: a.color ? callingInk(a.color) : a.selected ? c.background : c.foreground }) }), _jsx(Text, { style: [styles.label, typography(17), { color: c.foreground }, labelStyle], children: a.label })] });
|
|
116
|
+
}
|
|
117
|
+
export function CallingAudioControls({ style } = {}) {
|
|
118
|
+
const { actions, components } = useCallingUI();
|
|
119
|
+
const Button = components.ActionButton || CallingActionButton;
|
|
120
|
+
if (!actions.mute.visible && !actions.speaker.visible)
|
|
121
|
+
return null;
|
|
122
|
+
return _jsxs(View, { style: [styles.row, style], children: [_jsx(Button, { action: "mute" }), _jsx(Button, { action: "speaker" })] });
|
|
123
|
+
}
|
|
124
|
+
export function CallingIncomingControls({ style } = {}) {
|
|
125
|
+
const { state, components } = useCallingUI();
|
|
126
|
+
const Button = components.ActionButton || CallingActionButton;
|
|
127
|
+
if (state.phase !== 'incoming')
|
|
128
|
+
return null;
|
|
129
|
+
return _jsxs(View, { style: [styles.row, style], children: [_jsx(Button, { action: "decline" }), _jsx(Button, { action: "answer" })] });
|
|
130
|
+
}
|
|
131
|
+
/** Essential controls stay visible; secondary tools open above the dock. */
|
|
132
|
+
function CallingConferenceControls({ style }) {
|
|
133
|
+
const { actions, components, state, theme, labels, typography, design } = useCallingUI();
|
|
134
|
+
const Button = components.ActionButton || CallingActionButton;
|
|
135
|
+
const [expanded, setExpanded] = useState(false);
|
|
136
|
+
const secondary = (state.kind === 'video' ? ['speaker', 'flip', 'share'] : []).filter(action => actions[action].visible);
|
|
137
|
+
const compact = { minWidth: 48, maxWidth: 100, flex: 1, gap: 5 };
|
|
138
|
+
const icon = { width: 48, height: 48 };
|
|
139
|
+
const label = typography(12);
|
|
140
|
+
useEffect(() => { setExpanded(false); }, [state.phase]);
|
|
141
|
+
return _jsxs(View, { style: [{ position: 'relative', zIndex: 2, paddingVertical: 8 }, style], children: [expanded && _jsx(View, { testID: "calling-more-tools", style: { marginBottom: 12, width: '100%', maxWidth: 420, alignSelf: 'center', borderRadius: 18, padding: 16, backgroundColor: theme.control }, children: _jsx(View, { style: { flexDirection: 'row', justifyContent: 'space-evenly', gap: 12 }, children: secondary.map(action => _jsx(Button, { action: action, style: compact, iconStyle: icon, labelStyle: label }, action)) }) }), _jsxs(View, { testID: "calling-main-controls", style: { flexDirection: 'row', alignItems: 'flex-start', justifyContent: 'center', gap: 12, maxWidth: 420, width: '100%', alignSelf: 'center' }, children: [_jsx(Button, { action: "mute", style: compact, iconStyle: icon, labelStyle: label }), actions.camera.visible && _jsx(Button, { action: "camera", style: compact, iconStyle: icon, labelStyle: label }), state.kind !== 'video' && _jsx(Button, { action: "speaker", style: compact, iconStyle: icon, labelStyle: label }), secondary.length > 0 && _jsxs(Pressable, { accessibilityRole: "button", accessibilityLabel: labels.more, accessibilityState: { expanded }, onPress: () => setExpanded(value => !value), style: [styles.button, compact], children: [_jsx(View, { style: [styles.circle, icon, { borderRadius: design.controlRadius, backgroundColor: expanded ? theme.foreground : theme.control }], children: _jsx(RobonoIcon, { name: "more", size: 24, color: expanded ? theme.background : theme.foreground }) }), _jsx(Text, { style: [label, { color: theme.foreground, textAlign: 'center' }], children: labels.more })] }), _jsx(Button, { action: "end", style: [compact, { marginLeft: 8 }], iconStyle: icon, labelStyle: label })] })] });
|
|
142
|
+
}
|
|
143
|
+
export function CallingControls({ style } = {}) {
|
|
144
|
+
const { actions, components, state } = useCallingUI();
|
|
145
|
+
const Button = components.ActionButton || CallingActionButton;
|
|
146
|
+
const Audio = components.AudioControls || CallingAudioControls;
|
|
147
|
+
const Incoming = components.IncomingControls || CallingIncomingControls;
|
|
148
|
+
if ((state.kind === 'video' || state.group) && state.phase === 'held')
|
|
149
|
+
return _jsxs(View, { style: [{ flexDirection: 'row', justifyContent: 'center', alignItems: 'center', gap: 24, paddingVertical: 8 }, style], children: [actions.resume.visible && _jsx(Button, { action: "resume" }), _jsx(Button, { action: "end", iconStyle: { width: 48, height: 48 }, labelStyle: { fontSize: 12 } })] });
|
|
150
|
+
if ((state.kind === 'video' || state.group) && ['outgoing', 'connecting', 'connected'].includes(state.phase))
|
|
151
|
+
return _jsx(CallingConferenceControls, { style: style });
|
|
152
|
+
return _jsxs(View, { style: [styles.controls, style], children: [actions.resume.visible && _jsx(Button, { action: "resume" }), actions.mute.visible && _jsx(Audio, {}), actions.close.visible ? _jsx(Button, { action: "close" }) : state.phase === 'incoming' ? _jsx(Incoming, {}) : _jsx(View, { style: styles.row, children: _jsx(Button, { action: "end" }) })] });
|
|
153
|
+
}
|
|
154
|
+
const styles = StyleSheet.create({
|
|
155
|
+
screen: { flexGrow: 1, paddingHorizontal: 24, justifyContent: 'space-between', gap: 40 },
|
|
156
|
+
identity: { alignItems: 'center', gap: 14 },
|
|
157
|
+
brand: { flexDirection: 'row', alignItems: 'center', gap: 8, marginBottom: 8 }, logo: { width: 28, height: 28, borderRadius: 6 },
|
|
158
|
+
avatar: { alignItems: 'center', justifyContent: 'center', marginBottom: 16 },
|
|
159
|
+
initial: { fontSize: 44, fontWeight: '600' }, name: { fontSize: 28, fontWeight: '600', textAlign: 'center' },
|
|
160
|
+
kind: { fontSize: 16, textAlign: 'center' }, status: { fontSize: 21, marginTop: 8, textAlign: 'center' }, detail: { fontSize: 16, textAlign: 'center' },
|
|
161
|
+
controls: { gap: 30, alignItems: 'center' }, row: { flexDirection: 'row', justifyContent: 'center', gap: 48, flexWrap: 'wrap' },
|
|
162
|
+
button: { alignItems: 'center', gap: 10, minWidth: 80, maxWidth: 140 }, circle: { height: 72, width: 72, borderRadius: 36, alignItems: 'center', justifyContent: 'center' },
|
|
163
|
+
label: { fontSize: 17, textAlign: 'center' }, disabled: { opacity: 0.4 }, close: { paddingVertical: 16, paddingHorizontal: 32, borderRadius: 28 },
|
|
164
|
+
});
|
|
165
|
+
/** Video uses the same SDK layout, labels and controls on native and web. */
|
|
166
|
+
export function CallingVideo({ style } = {}) {
|
|
167
|
+
const { state, renderVideo, theme, typography, labels, design } = useCallingUI();
|
|
168
|
+
const [area, setArea] = useState({ width: 0, height: 0 });
|
|
169
|
+
if (state.group && ['outgoing', 'connecting', 'connected', 'held'].includes(state.phase)) {
|
|
170
|
+
const members = state.groupMembers?.filter(m => !['left', 'declined'].includes(m.state)) ?? [], sharing = members.find(m => m.sharing);
|
|
171
|
+
const tile = (member, tileStyle, compact = false) => _jsxs(View, { style: [{ flex: 1, minHeight: 60, overflow: 'hidden', borderRadius: 12, backgroundColor: theme.control, alignItems: 'center', justifyContent: 'center' }, tileStyle], children: [state.kind === 'video' && member.stream && renderVideo && !member.held && state.phase !== 'held' && (member.sharing || !member.local || state.cameraEnabled !== false)
|
|
172
|
+
? renderVideo({ stream: member.stream, local: !!member.local, screen: member.sharing, style: { position: 'absolute', width: '100%', height: '100%' } })
|
|
173
|
+
: design.presentation.showAvatar && _jsx(View, { style: { width: compact ? 36 : avatarSize, height: compact ? 36 : avatarSize, borderRadius: 40, backgroundColor: theme.background, alignItems: 'center', justifyContent: 'center' }, children: member.avatarUri ? _jsx(Image, { source: { uri: member.avatarUri }, style: { width: compact ? 36 : avatarSize, height: compact ? 36 : avatarSize, borderRadius: 40 } }) : _jsx(Text, { style: [typography(28), { color: theme.accent }], children: member.name.slice(0, 1) }) }), _jsx(View, { style: { position: 'absolute', bottom: 8, left: 8, maxWidth: '90%', borderRadius: 6, paddingHorizontal: 8, paddingVertical: 4, backgroundColor: '#000000b0' }, children: _jsxs(Text, { numberOfLines: 1, style: [typography(12), { color: '#ffffff', textAlign: 'left' }], children: [member.name, member.sharing ? ' · ' + labels.sharingScreen : '', member.held ? ' · ' + labels.held : member.state === 'invited' ? ' · ' + labels.outgoing : ''] }) })] }, member.id);
|
|
174
|
+
const landscape = area.width > area.height;
|
|
175
|
+
const columns = Math.max(1, Math.min(members.length, landscape && area.width > 700 && members.length > 4 ? 4 : landscape || members.length > 2 ? 2 : 1));
|
|
176
|
+
const avatarSize = Math.min(72, Math.max(28, (area.height || 400) / Math.ceil(Math.max(1, members.length) / columns) - 48));
|
|
177
|
+
const rows = Array.from({ length: Math.ceil(members.length / Math.max(1, columns)) }, (_, i) => members.slice(i * columns, (i + 1) * columns));
|
|
178
|
+
return _jsx(View, { onLayout: e => { const { width, height } = e.nativeEvent.layout; setArea(old => old.width === width && old.height === height ? old : { width, height }); }, style: [{ flex: 1, gap: 8, minHeight: 100 }, style], children: sharing ? _jsxs(_Fragment, { children: [tile(sharing), _jsx(ScrollView, { horizontal: true, style: { flexGrow: 0, flexShrink: 0, height: Math.max(72, Math.min(136, area.height * 0.24)) }, contentContainerStyle: { gap: 8, height: Math.max(72, Math.min(136, area.height * 0.24)), alignItems: 'stretch' }, children: members.filter(m => m !== sharing).map(m => tile(m, { width: 120, flexGrow: 0, flexShrink: 0, flexBasis: 'auto' }, true)) })] }) : rows.map((row, index) => _jsx(View, { style: { flex: 1, flexDirection: 'row', justifyContent: 'center', gap: 8 }, children: row.map(m => tile(m, { maxWidth: columns > 1 && area.width > 0 ? Math.max(0, (area.width - 8 * (columns - 1)) / columns) : undefined })) }, index)) });
|
|
179
|
+
}
|
|
180
|
+
if (state.kind !== 'video' || !['outgoing', 'connecting', 'connected', 'held'].includes(state.phase) || !renderVideo)
|
|
181
|
+
return null;
|
|
182
|
+
const visible = !['held', 'idle', 'error'].includes(state.phase);
|
|
183
|
+
return _jsxs(View, { style: [{ flex: 1, minHeight: 100, borderRadius: 16, overflow: 'hidden', backgroundColor: theme.control }, style], children: [visible && state.remoteStream ? renderVideo({ stream: state.remoteStream, local: false, screen: state.remoteScreenSharing, style: { width: '100%', height: '100%' } }) :
|
|
184
|
+
_jsxs(View, { style: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 16 }, children: [_jsx(CallingAvatar, { size: 80 }), _jsx(Text, { style: [typography(16), { color: theme.secondary }], children: state.phase === 'held' ? labels.held : labels.connecting })] }), visible && (state.screenSharing || state.remoteScreenSharing) && _jsx(Text, { style: [typography(13), { position: 'absolute', top: 8, left: 8, padding: 6, borderRadius: 5, color: '#ffffff', backgroundColor: '#000000b0' }], children: labels.sharingScreen }), visible && state.localStream && (state.screenSharing || state.cameraEnabled !== false) && _jsx(View, { style: { position: 'absolute', right: 10, bottom: 10, width: 86, height: 114, borderRadius: 10, overflow: 'hidden' }, children: renderVideo({ stream: state.displayStream || state.localStream, local: true, screen: state.screenSharing, style: { width: '100%', height: '100%' } }) })] });
|
|
185
|
+
}
|
package/dist/controller.d.mts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* @param {import('./types.js').CallingOptions & {createClient: (options: any) => import('@robono/calling').RobonoCallingClient}} options
|
|
3
3
|
* @returns {import('./types.js').CallingController}
|
|
4
4
|
*/
|
|
5
|
-
export function createController({ createClient, request, media, audio, resolveContact, onError, forceRelay }: import("./types.js").CallingOptions & {
|
|
5
|
+
export function createController({ createClient, request, media, audio, resolveContact, onError, onUnansweredCall, forceRelay }: import("./types.js").CallingOptions & {
|
|
6
6
|
createClient: (options: any) => import("@robono/calling").RobonoCallingClient;
|
|
7
7
|
}): import("./types.js").CallingController;
|
package/dist/controller.mjs
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* @param {import('./types.js').CallingOptions & {createClient: (options: any) => import('@robono/calling').RobonoCallingClient}} options
|
|
4
4
|
* @returns {import('./types.js').CallingController}
|
|
5
5
|
*/
|
|
6
|
-
export function createController({ createClient, request, media, audio, resolveContact = () => null, onError = () => { }, forceRelay = false }) {
|
|
6
|
+
export function createController({ createClient, request, media, audio, resolveContact = () => null, onError = () => { }, onUnansweredCall = () => { }, forceRelay = false }) {
|
|
7
7
|
const listeners = new Set();
|
|
8
8
|
let disposed = false, foreground = true, action = null, startingContact = null;
|
|
9
9
|
let opening = null, openingTimer, connectedId = null, audioKey = '', epoch = 0;
|
|
10
10
|
let resuming = null;
|
|
11
|
+
const offeredMessages = new Set();
|
|
12
|
+
const outgoingCalls = new Set();
|
|
11
13
|
let snapshot = { call: null, voiceAvailable: false, muted: false, error: null };
|
|
12
14
|
let state = { phase: 'idle', call: null, contact: null, speaker: false, muted: false, error: null, canMute: false, canSpeaker: false, connectedAt: null };
|
|
13
15
|
const publish = patch => { state = { ...state, ...patch }; for (const listener of listeners)
|
|
@@ -29,6 +31,11 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
29
31
|
snapshot = next;
|
|
30
32
|
const call = next.call;
|
|
31
33
|
const active = call && call.state !== 'ended' && call.controlled;
|
|
34
|
+
if (active && call.role === 'caller') {
|
|
35
|
+
outgoingCalls.add(call.id);
|
|
36
|
+
if (outgoingCalls.size > 100)
|
|
37
|
+
outgoingCalls.delete(outgoingCalls.values().next().value);
|
|
38
|
+
}
|
|
32
39
|
if (opening && (!active || call.id !== opening))
|
|
33
40
|
return;
|
|
34
41
|
if (opening) {
|
|
@@ -49,7 +56,7 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
49
56
|
const newIncoming = active && call.role === 'callee' && state.call?.id !== call.id;
|
|
50
57
|
const previousPhase = state.phase;
|
|
51
58
|
const cue = phase === 'connected' && previousPhase === 'held' ? 'resumed' : phase === 'idle' && call?.state === 'ended' && state.call?.id === call.id ? (call.reason === 'declined' ? 'declined' : ['no_answer', 'cancelled'].includes(call.reason) ? 'unanswered' : undefined) : undefined;
|
|
52
|
-
publish({ phase, call: active && !terminalError ? call : null, contact, muted: next.muted,
|
|
59
|
+
publish({ screenSharing: !!next.screenSharing, screenSharePending: !!next.screenSharePending, displayStream: next.displayStream, canScreenShare: !!call?.screenSharingAvailable && phase === 'connected', remoteScreenSharing: !!call?.sharing?.some((value, i) => i !== call.self && value), phase, kind: active ? call.kind || 'voice' : state.kind || 'voice', cameraEnabled: next.cameraEnabled !== false, canCamera: !!state.localStream?.getVideoTracks().length && ['outgoing', 'connecting', 'connected'].includes(phase), call: active && !terminalError ? call : null, contact, muted: next.muted,
|
|
53
60
|
...(newIncoming ? { speaker: false } : {}),
|
|
54
61
|
error: next.error, localHeld: !!next.localHeld,
|
|
55
62
|
...(phase !== 'held' ? { resumeError: null, resumePending: false } : {}),
|
|
@@ -57,10 +64,26 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
57
64
|
canMute: phase === 'connected' && !next.preparing,
|
|
58
65
|
canSpeaker: ['outgoing', 'connecting', 'connected'].includes(phase) });
|
|
59
66
|
sound(phase, endTone, cue);
|
|
67
|
+
if (call?.state === 'ended' && outgoingCalls.has(call.id) && call.role === 'caller' && call.reason === 'no_answer' && call.answeredAt == null && call.connectedAt == null && !offeredMessages.has(call.id)) {
|
|
68
|
+
offeredMessages.add(call.id);
|
|
69
|
+
if (offeredMessages.size > 100)
|
|
70
|
+
offeredMessages.delete(offeredMessages.values().next().value);
|
|
71
|
+
queueMicrotask(() => { if (!disposed) {
|
|
72
|
+
try {
|
|
73
|
+
onUnansweredCall({ id: call.id, connectionId: call.connectionId });
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
onError(error);
|
|
77
|
+
}
|
|
78
|
+
} });
|
|
79
|
+
}
|
|
60
80
|
if (phase === 'idle' && !action)
|
|
61
81
|
startingContact = null;
|
|
62
82
|
};
|
|
63
|
-
const client = createClient({ request, ...media, forceRelay, onChange: update
|
|
83
|
+
const client = createClient({ request, ...media, forceRelay, onChange: update,
|
|
84
|
+
onLocalStream: localStream => publish({ localStream, canCamera: !!localStream?.getVideoTracks().length }),
|
|
85
|
+
onRemoteStream: remoteStream => publish({ remoteStream }),
|
|
86
|
+
});
|
|
64
87
|
const run = async (kind, work) => {
|
|
65
88
|
if (disposed || action || ['loading', 'error'].includes(state.phase))
|
|
66
89
|
throw Error('client_not_ready');
|
|
@@ -87,14 +110,14 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
87
110
|
subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
|
|
88
111
|
async listen() { if (disposed)
|
|
89
112
|
throw Error('client_not_ready'); await client.listen(); },
|
|
90
|
-
async call(connectionId, contact) {
|
|
113
|
+
async call(connectionId, contact, { kind = 'voice' } = {}) {
|
|
91
114
|
if (state.phase !== 'idle')
|
|
92
115
|
throw Error('busy');
|
|
93
116
|
startingContact = contact || resolveContact(connectionId);
|
|
94
117
|
return run('call', async () => {
|
|
95
|
-
publish({ phase: 'outgoing', contact: startingContact, speaker: false, canSpeaker: true, error: null });
|
|
118
|
+
publish({ phase: 'outgoing', kind, cameraEnabled: true, contact: startingContact, speaker: false, canSpeaker: true, error: null });
|
|
96
119
|
sound('outgoing');
|
|
97
|
-
await client.call(connectionId);
|
|
120
|
+
await client.call(connectionId, { kind });
|
|
98
121
|
});
|
|
99
122
|
},
|
|
100
123
|
async answer() {
|
|
@@ -154,6 +177,32 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
154
177
|
resuming = work;
|
|
155
178
|
return work;
|
|
156
179
|
},
|
|
180
|
+
async startScreenSharing() { try {
|
|
181
|
+
await client.startScreenSharing();
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
report(e);
|
|
185
|
+
throw e;
|
|
186
|
+
} },
|
|
187
|
+
async stopScreenSharing() { try {
|
|
188
|
+
await client.stopScreenSharing();
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
report(e);
|
|
192
|
+
throw e;
|
|
193
|
+
} },
|
|
194
|
+
setCamera(enabled) { if (state.canCamera)
|
|
195
|
+
client.setCamera(enabled); },
|
|
196
|
+
async switchCamera() {
|
|
197
|
+
if (!state.canCamera || !state.localStream || !media.switchCamera)
|
|
198
|
+
return;
|
|
199
|
+
try {
|
|
200
|
+
await media.switchCamera(state.localStream);
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
report(error);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
157
206
|
mute(value) { if (state.canMute)
|
|
158
207
|
client.mute(value); },
|
|
159
208
|
setSpeaker(value) {
|
|
@@ -162,7 +211,10 @@ export function createController({ createClient, request, media, audio, resolveC
|
|
|
162
211
|
publish({ speaker: value });
|
|
163
212
|
sound(state.phase);
|
|
164
213
|
},
|
|
165
|
-
setForeground(value) { foreground = value; client.setForeground
|
|
214
|
+
setForeground(value) { foreground = value; if (client.setForeground)
|
|
215
|
+
client.setForeground(value);
|
|
216
|
+
else
|
|
217
|
+
client.setVideoForeground?.(value); sound(state.phase); },
|
|
166
218
|
async refresh() { return client.refresh(); },
|
|
167
219
|
async openIncoming(callId) {
|
|
168
220
|
if (disposed || typeof callId !== 'string' || !callId || callId.length > 128)
|
|
@@ -2,7 +2,7 @@ import * as Notifications from 'expo-notifications';
|
|
|
2
2
|
import { type CallingNotificationRouterOptions } from './notification-router.js';
|
|
3
3
|
export { callingNotificationPresentation } from './notification-router.js';
|
|
4
4
|
/** Compose explicitly with your existing handler; preserve ordinary message alerts. */
|
|
5
|
-
export declare function withCallingNotificationPresentation(handler: Notifications.NotificationHandler, canPresentCall: () => boolean): Notifications.NotificationHandler;
|
|
5
|
+
export declare function withCallingNotificationPresentation(handler: Notifications.NotificationHandler, canPresentCall: () => boolean, group?: boolean): Notifications.NotificationHandler;
|
|
6
6
|
/** Registers listeners, never replaces the app's global presentation handler. */
|
|
7
7
|
export declare function connectExpoCallingNotifications(options: Omit<CallingNotificationRouterOptions, 'dismiss'> & {
|
|
8
8
|
onError(error: Error): void;
|
|
@@ -3,9 +3,9 @@ import { AppState } from 'react-native';
|
|
|
3
3
|
import { createCallingNotificationRouter, callingNotificationPresentation } from './notification-router.js';
|
|
4
4
|
export { callingNotificationPresentation } from './notification-router.js';
|
|
5
5
|
/** Compose explicitly with your existing handler; preserve ordinary message alerts. */
|
|
6
|
-
export function withCallingNotificationPresentation(handler, canPresentCall) {
|
|
6
|
+
export function withCallingNotificationPresentation(handler, canPresentCall, group = false) {
|
|
7
7
|
return { ...handler, handleNotification: async (notification) => {
|
|
8
|
-
const decision = callingNotificationPresentation(notification.request.content.data, AppState.currentState === 'active');
|
|
8
|
+
const decision = callingNotificationPresentation(notification.request.content.data, AppState.currentState === 'active', group);
|
|
9
9
|
if (decision === 'dismiss' || decision === 'screen' && canPresentCall())
|
|
10
10
|
return { shouldPlaySound: false, shouldSetBadge: false, shouldShowBanner: false, shouldShowList: false };
|
|
11
11
|
return handler.handleNotification(notification);
|
|
@@ -27,7 +27,7 @@ export function connectExpoCallingNotifications(options) {
|
|
|
27
27
|
if (disposed || !value || value.actionIdentifier !== Notifications.DEFAULT_ACTION_IDENTIFIER)
|
|
28
28
|
return;
|
|
29
29
|
const data = value.notification.request.content.data;
|
|
30
|
-
if (!callingNotificationPresentation(data, false))
|
|
30
|
+
if (!callingNotificationPresentation(data, false, options.group))
|
|
31
31
|
return;
|
|
32
32
|
if (await router.handle(data, true)) {
|
|
33
33
|
// Don't clear a different notification that arrived while storage was read.
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Presentation follows this device's participation, not another member's call. */
|
|
2
|
+
export function groupPhase(snapshot: any, pending?: boolean): "incoming" | "outgoing" | "connecting" | "connected" | "held" | "idle" | "error";
|
|
3
|
+
/** Media may connect before the service acknowledges the group connection. */
|
|
4
|
+
export function groupCanShare(snapshot: any): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** Presentation follows this device's participation, not another member's call. */
|
|
2
|
+
export function groupPhase(snapshot, pending = false) {
|
|
3
|
+
const call = snapshot.call;
|
|
4
|
+
if (call && (call.controlled === false || call.state === 'ended' || ['left', 'declined'].includes(call.memberState)))
|
|
5
|
+
return 'idle';
|
|
6
|
+
if (snapshot.localHeld)
|
|
7
|
+
return 'held';
|
|
8
|
+
if (snapshot.connectedAt != null)
|
|
9
|
+
return 'connected';
|
|
10
|
+
if (snapshot.preparing)
|
|
11
|
+
return call?.memberState === 'invited' || call?.state === 'connecting' ? 'connecting' : 'outgoing';
|
|
12
|
+
if (call?.memberState === 'invited')
|
|
13
|
+
return 'incoming';
|
|
14
|
+
if (call?.memberState === 'joined')
|
|
15
|
+
return call.state === 'ringing' ? 'outgoing' : 'connecting';
|
|
16
|
+
if (pending)
|
|
17
|
+
return 'outgoing';
|
|
18
|
+
return snapshot.error ? 'error' : 'idle';
|
|
19
|
+
}
|
|
20
|
+
/** Media may connect before the service acknowledges the group connection. */
|
|
21
|
+
export function groupCanShare(snapshot) {
|
|
22
|
+
const call = snapshot.call;
|
|
23
|
+
return !!(call?.controlled && call.state === 'connected' && call.memberState === 'joined'
|
|
24
|
+
&& call.kind === 'video' && call.screenSharingAvailable
|
|
25
|
+
&& !snapshot.localHeld && !call.localHeld && !call.remoteHeld);
|
|
26
|
+
}
|
package/dist/groups.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { RobonoGroupCallingClient } from '@robono/calling/groups';
|
|
3
|
+
import { type CallingScreenProps } from './screens.js';
|
|
4
|
+
import type { CallingOptions, CallingState, Contact } from './types.js';
|
|
5
|
+
export interface GroupCallingOptions extends Omit<CallingOptions, 'resolveContact' | 'onUnansweredCall'> {
|
|
6
|
+
resolveGroup?: (connectionId: string) => Contact | null;
|
|
7
|
+
resolveMember?: (appId: string, userId: string) => Contact | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function createGroupCallingController(options: GroupCallingOptions): {
|
|
10
|
+
client: RobonoGroupCallingClient;
|
|
11
|
+
getSnapshot: () => CallingState;
|
|
12
|
+
subscribe: (fn: () => void) => () => void;
|
|
13
|
+
listen(): Promise<void>;
|
|
14
|
+
reportComponents(values: string[]): void;
|
|
15
|
+
call(connectionId: string, input?: {
|
|
16
|
+
kind?: "voice" | "video";
|
|
17
|
+
}): Promise<void>;
|
|
18
|
+
answer(): Promise<void>;
|
|
19
|
+
refresh: () => Promise<boolean>;
|
|
20
|
+
openIncoming(callId: string): Promise<boolean>;
|
|
21
|
+
hangUp(input?: {
|
|
22
|
+
playEndTone?: boolean;
|
|
23
|
+
}): Promise<void>;
|
|
24
|
+
mute: (value: boolean) => void;
|
|
25
|
+
setCamera: (value: boolean) => void;
|
|
26
|
+
startScreenSharing: () => Promise<void>;
|
|
27
|
+
stopScreenSharing: () => Promise<void>;
|
|
28
|
+
switchCamera(): Promise<void>;
|
|
29
|
+
setSpeaker(value: boolean): void;
|
|
30
|
+
setForeground(value: boolean): void;
|
|
31
|
+
interrupt(): Promise<void>;
|
|
32
|
+
resume(): Promise<void>;
|
|
33
|
+
dismissError(): void;
|
|
34
|
+
dispose(): Promise<void>;
|
|
35
|
+
};
|
|
36
|
+
export type GroupCallingController = ReturnType<typeof createGroupCallingController>;
|
|
37
|
+
export interface GroupCallingOverlayProps extends Omit<CallingScreenProps, 'state' | 'onAnswer' | 'onHangUp' | 'onMute' | 'onSpeaker' | 'onClose'> {
|
|
38
|
+
controller: GroupCallingController;
|
|
39
|
+
}
|
|
40
|
+
/** Optional group screen. Use the engine alone when keeping your own interface. */
|
|
41
|
+
export declare function GroupCallingOverlay({ controller, ...props }: GroupCallingOverlayProps): React.JSX.Element;
|
package/dist/groups.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { engineVersion, mobileVersion } from './versions.js';
|
|
3
|
+
import { useEffect, useSyncExternalStore } from 'react';
|
|
4
|
+
import { AppState, Modal, Platform } from 'react-native';
|
|
5
|
+
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
|
6
|
+
import { RobonoGroupCallingClient } from '@robono/calling/groups';
|
|
7
|
+
import { CallingScreen } from './screens.js';
|
|
8
|
+
import { groupPhase, groupCanShare } from './group-phase.mjs';
|
|
9
|
+
export function createGroupCallingController(options) {
|
|
10
|
+
let state = { group: true, phase: 'idle', call: null, contact: null, speaker: false, muted: false, canMute: false, canSpeaker: true, connectedAt: null, error: null };
|
|
11
|
+
const listeners = new Set();
|
|
12
|
+
let foreground = true, pendingKind = 'voice', pending = false, suppressEnd = false;
|
|
13
|
+
const emit = () => listeners.forEach(fn => fn());
|
|
14
|
+
const report = (e) => options.onError?.(e instanceof Error ? e : Error(String(e)));
|
|
15
|
+
const sound = (endTone = false) => void Promise.resolve(options.audio.update({ phase: state.phase, speaker: state.speaker, foreground, endTone, localHeld: state.localHeld })).catch(report);
|
|
16
|
+
const apply = (snapshot) => {
|
|
17
|
+
const c = snapshot.call, old = state.phase;
|
|
18
|
+
const phase = groupPhase(snapshot, pending);
|
|
19
|
+
state = { ...state, screenSharing: snapshot.screenSharing, screenSharePending: snapshot.screenSharePending, displayStream: snapshot.displayStream, canScreenShare: groupCanShare(snapshot), phase, kind: c?.kind ?? pendingKind, error: snapshot.error, muted: snapshot.muted, localHeld: snapshot.localHeld,
|
|
20
|
+
holdExpiresAt: c?.holdExpiresAt, canMute: !!snapshot.localStream, canSpeaker: true, canCamera: !!snapshot.localStream, cameraEnabled: snapshot.cameraEnabled, localStream: snapshot.localStream,
|
|
21
|
+
contact: c ? options.resolveGroup?.(c.connectionId) ?? { name: 'Group call' } : state.contact, connectedAt: snapshot.connectedAt,
|
|
22
|
+
groupMembers: c?.members.map(m => ({ ...options.resolveMember?.(m.appId, m.userId), id: m.id, name: m.id === c.self ? 'You' : options.resolveMember?.(m.appId, m.userId)?.name ?? 'Participant', state: m.state, held: m.held, local: m.id === c.self, sharing: !!c.sharing?.[m.id], stream: m.id === c.self ? snapshot.displayStream || snapshot.localStream : snapshot.remoteStreams[m.id] })) };
|
|
23
|
+
sound(!suppressEnd && old === 'connected' && phase === 'idle');
|
|
24
|
+
emit();
|
|
25
|
+
};
|
|
26
|
+
const components = new Set(['controller', ...(options.media.robonoAdapter ? ['native-media'] : []), ...(options.audio.robonoAdapter ? ['native-audio'] : [])]);
|
|
27
|
+
const inventory = () => void options.request('client-info', { platform: Platform.OS, engineVersion, mobileVersion, components: [...components], appearanceRevision: options.appearanceRevision }).catch(report);
|
|
28
|
+
const client = new RobonoGroupCallingClient({ ...options.media, request: options.request, forceRelay: options.forceRelay, onChange: apply });
|
|
29
|
+
return { client, getSnapshot: () => state, subscribe: (fn) => { listeners.add(fn); return () => { listeners.delete(fn); }; },
|
|
30
|
+
async listen() { await client.listen(); inventory(); },
|
|
31
|
+
reportComponents(values) { values.forEach(v => components.add(v)); inventory(); },
|
|
32
|
+
async call(connectionId, input = {}) { pendingKind = input.kind ?? 'voice'; pending = true; state = { ...state, contact: options.resolveGroup?.(connectionId) ?? { name: 'Group call' }, kind: pendingKind, phase: 'outgoing' }; sound(); emit(); try {
|
|
33
|
+
await client.call(connectionId, input);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
pending = false;
|
|
37
|
+
apply(client.state);
|
|
38
|
+
} },
|
|
39
|
+
async answer() { state = { ...state, phase: 'connecting' }; sound(); emit(); await client.answer(); },
|
|
40
|
+
refresh: () => client.refresh(),
|
|
41
|
+
async openIncoming(callId) {
|
|
42
|
+
if (state.phase === 'idle') {
|
|
43
|
+
state = { ...state, phase: 'loading', error: null };
|
|
44
|
+
emit();
|
|
45
|
+
}
|
|
46
|
+
const ok = await client.refresh(), matches = ok && client.state.call?.id === callId && client.state.call.controlled && client.state.call.state !== 'ended' && client.state.call.memberState === 'invited';
|
|
47
|
+
if (!matches && state.phase === 'loading') {
|
|
48
|
+
state = { ...state, phase: 'error', error: 'call_unavailable' };
|
|
49
|
+
emit();
|
|
50
|
+
}
|
|
51
|
+
return !!matches;
|
|
52
|
+
},
|
|
53
|
+
async hangUp(input) { suppressEnd = input?.playEndTone === false; try {
|
|
54
|
+
await client.leave();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
suppressEnd = false;
|
|
58
|
+
} }, mute: (value) => client.mute(value), setCamera: (value) => client.setCamera(value),
|
|
59
|
+
startScreenSharing: () => client.startScreenSharing(), stopScreenSharing: () => client.stopScreenSharing(),
|
|
60
|
+
async switchCamera() { if (client.state.localStream)
|
|
61
|
+
await options.media.switchCamera?.(client.state.localStream); },
|
|
62
|
+
setSpeaker(value) { state = { ...state, speaker: value }; sound(); emit(); },
|
|
63
|
+
setForeground(value) { foreground = value; client.setForeground(value); sound(); },
|
|
64
|
+
async interrupt() { await client.hold(); }, async resume() { if (state.resumePending)
|
|
65
|
+
return; state = { ...state, resumePending: true, resumeError: null }; emit(); try {
|
|
66
|
+
await client.resume(() => Promise.resolve(options.audio.resume?.()));
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
state = { ...state, resumeError: e instanceof Error ? e.message : String(e) };
|
|
70
|
+
throw e;
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
state = { ...state, resumePending: false };
|
|
74
|
+
emit();
|
|
75
|
+
} },
|
|
76
|
+
dismissError() { state = { ...state, error: null, phase: 'idle' }; emit(); },
|
|
77
|
+
async dispose() { try {
|
|
78
|
+
await client.dispose();
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
await options.audio.dispose();
|
|
82
|
+
listeners.clear();
|
|
83
|
+
} } };
|
|
84
|
+
}
|
|
85
|
+
/** Optional group screen. Use the engine alone when keeping your own interface. */
|
|
86
|
+
export function GroupCallingOverlay({ controller, ...props }) {
|
|
87
|
+
const state = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
|
|
88
|
+
useEffect(() => { controller.reportComponents(['screens']); controller.setForeground(AppState.currentState === 'active'); const s = AppState.addEventListener('change', v => controller.setForeground(v === 'active')); return () => s.remove(); }, [controller]);
|
|
89
|
+
return _jsx(Modal, { visible: state.phase !== 'idle', animationType: "none", presentationStyle: "fullScreen", onRequestClose: () => { void controller.hangUp().catch(() => { }); }, children: _jsx(SafeAreaProvider, { children: _jsx(CallingScreen, { ...props, state: state, onAnswer: () => { void controller.answer().catch(() => { }); }, onHangUp: () => { void controller.hangUp().catch(() => { }); }, onMute: controller.mute, onSpeaker: controller.setSpeaker, onScreenShare: () => { void (state.screenSharing ? controller.stopScreenSharing() : controller.startScreenSharing()).catch(() => { }); }, onCamera: controller.setCamera, onSwitchCamera: () => { void controller.switchCamera().catch(() => { }); }, onResume: () => { void controller.resume().catch(() => { }); }, onClose: controller.dismissError }) }) });
|
|
90
|
+
}
|
package/dist/history.d.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
textColor?: string;
|
|
9
|
-
/** Caller must recheck live availability before placing the callback. */
|
|
10
|
-
onCallBack?: () => void;
|
|
11
|
-
label?: (entry: CallHistoryEntry) => {
|
|
12
|
-
label: string;
|
|
13
|
-
detail: string;
|
|
14
|
-
missed: boolean;
|
|
15
|
-
};
|
|
16
|
-
}): React.JSX.Element;
|
|
2
|
+
import { CallRecord } from './CallRecord.js';
|
|
3
|
+
type Props = Omit<React.ComponentProps<typeof CallRecord>, 'label'> & {
|
|
4
|
+
label?: React.ComponentProps<typeof CallRecord>['label'];
|
|
5
|
+
};
|
|
6
|
+
export declare function CallHistoryItem({ label, ...props }: Props): React.JSX.Element;
|
|
7
|
+
export {};
|
package/dist/history.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import { Pressable, StyleSheet, Text, View } from 'react-native';
|
|
3
|
-
import Svg, { Path } from 'react-native-svg';
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
2
|
import { describeCall } from '@robono/calling/history';
|
|
5
|
-
|
|
6
|
-
export function CallHistoryItem({
|
|
7
|
-
const description = label ? label(entry) : describeCall(entry);
|
|
8
|
-
const incoming = entry.role === 'callee';
|
|
9
|
-
const body = _jsxs(View, { style: [styles.bubble, { backgroundColor: incoming ? incomingColor : outgoingColor }], children: [_jsx(Svg, { width: 24, height: 24, viewBox: "0 0 24 24", accessible: false, children: _jsx(Path, { d: description.missed ? 'M4 5v6h6M4 11l6-6 7 7 4-4' : incoming ? 'M18 5 6 17M6 10v7h7' : 'M6 18 18 6M11 6h7v7', stroke: textColor, strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", fill: "none" }) }), _jsxs(View, { style: styles.text, children: [_jsx(Text, { style: [styles.title, { color: textColor }], children: description.label }), !!description.detail && _jsx(Text, { style: { color: textColor }, children: description.detail })] })] });
|
|
10
|
-
return _jsx(View, { style: { alignItems: incoming ? 'flex-start' : 'flex-end', marginVertical: 4 }, children: onCallBack ? _jsx(Pressable, { onPress: onCallBack, accessibilityRole: "button", accessibilityLabel: `${description.label}. ${description.detail}`, accessibilityHint: "Call this contact", style: styles.width, children: body }) : body });
|
|
11
|
-
}
|
|
12
|
-
const styles = StyleSheet.create({ bubble: { borderRadius: 16, padding: 14, flexDirection: 'row', alignItems: 'center', gap: 12, maxWidth: '85%' }, width: { maxWidth: '100%' }, text: { flexShrink: 1, gap: 4 }, title: { fontSize: 16, fontWeight: '500' } });
|
|
3
|
+
import { CallRecord } from './CallRecord.js';
|
|
4
|
+
export function CallHistoryItem({ label = describeCall, ...props }) { return _jsx(CallRecord, { ...props, label: label }); }
|
package/dist/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export { CallingScreen, CallingOverlay, useCalling } from './screens.js';
|
|
|
4
4
|
export { CallHistoryItem } from './history.js';
|
|
5
5
|
export type { CallingScreenProps, CallingOverlayProps, CallingLabels, CallingTheme } from './screens.js';
|
|
6
6
|
export type { CallAudio, CallingState, CallingController, CallingOptions, Contact, MediaAdapter, Phase } from './types.js';
|
|
7
|
-
export { callingInk, defaultCallingAppearance, validateCallingAppearance, soundCatalog } from './appearance.js';
|
|
8
|
-
export type { CallingAppearance, SoundChoice, SoundEvent } from './appearance.js';
|
|
7
|
+
export { callingInk, resolveCallingDesign, defaultCallingAppearance, validateCallingAppearance, soundCatalog } from './appearance.js';
|
|
8
|
+
export type { CallingAppearance, CallingPresentation, SoundChoice, SoundEvent } from './appearance.js';
|
|
9
|
+
export { CallingUIProvider, useCallingUI, CallingLayout, CallingBrand, CallingAvatar, CallingContact, CallingStatus, CallingIdentity, CallingVideo, CallingActionButton, CallingAudioControls, CallingIncomingControls, CallingControls, } from './components.js';
|
|
10
|
+
export type { CallingUIProviderProps, CallingUIValue, CallingScreenComponents, CallingAction, CallingActionModel, CallingSectionProps, CallingLayoutProps, CallingAvatarProps, CallingContactProps, CallingStatusProps, CallingActionButtonProps, } from './components.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { engineVersion, mobileVersion } from './versions.js';
|
|
1
2
|
import { RobonoCallingClient } from '@robono/calling';
|
|
2
3
|
import { createController } from './controller.mjs';
|
|
3
4
|
import { Platform } from 'react-native';
|
|
@@ -12,7 +13,7 @@ export function createCallingController(options) {
|
|
|
12
13
|
return;
|
|
13
14
|
sent = key;
|
|
14
15
|
// Inventory is explicitly client-declared; it cannot set charges or access.
|
|
15
|
-
void Promise.resolve().then(() => options.request('client-info', { platform: Platform.OS, engineVersion
|
|
16
|
+
void Promise.resolve().then(() => options.request('client-info', { platform: Platform.OS, engineVersion, mobileVersion, components: [...components].sort(), appearanceRevision: options.appearanceRevision })).catch(() => { sent = ''; });
|
|
16
17
|
};
|
|
17
18
|
const listen = controller.listen;
|
|
18
19
|
controller.listen = async () => { await listen(); controller.reportComponents?.([]); };
|
|
@@ -20,4 +21,5 @@ export function createCallingController(options) {
|
|
|
20
21
|
}
|
|
21
22
|
export { CallingScreen, CallingOverlay, useCalling } from './screens.js';
|
|
22
23
|
export { CallHistoryItem } from './history.js';
|
|
23
|
-
export { callingInk, defaultCallingAppearance, validateCallingAppearance, soundCatalog } from './appearance.js';
|
|
24
|
+
export { callingInk, resolveCallingDesign, defaultCallingAppearance, validateCallingAppearance, soundCatalog } from './appearance.js';
|
|
25
|
+
export { CallingUIProvider, useCallingUI, CallingLayout, CallingBrand, CallingAvatar, CallingContact, CallingStatus, CallingIdentity, CallingVideo, CallingActionButton, CallingAudioControls, CallingIncomingControls, CallingControls, } from './components.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type CallingOverlayProps } from './screens.js';
|
|
3
|
+
import type { CallingScreenProps } from './components.js';
|
|
4
|
+
export declare const renderNativeCallVideo: NonNullable<CallingScreenProps['renderVideo']>;
|
|
5
|
+
/** Optional complete native screen; the calling engine can also use your UI. */
|
|
6
|
+
export declare function NativeCallingOverlay(props: CallingOverlayProps): React.JSX.Element;
|
|
7
|
+
import { type GroupCallingOverlayProps } from './groups.js';
|
|
8
|
+
export declare function NativeGroupCallingOverlay(props: GroupCallingOverlayProps): React.JSX.Element;
|