@robono/messaging-react-native 0.26.3 → 0.27.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.
Files changed (74) hide show
  1. package/README.md +18 -1
  2. package/SBOM.spdx.json +1696 -616
  3. package/app.plugin.cjs +4 -0
  4. package/dist/bubble-design.d.ts +1 -0
  5. package/dist/bubble-design.js +1 -0
  6. package/dist/call-message-decoration.d.ts +15 -0
  7. package/dist/call-message-decoration.js +23 -0
  8. package/dist/calling-timeline.d.ts +40 -0
  9. package/dist/calling-timeline.js +79 -0
  10. package/dist/calling.d.ts +4 -1
  11. package/dist/calling.js +8 -5
  12. package/dist/expo-connected-calling.d.ts +4 -0
  13. package/dist/expo-connected-calling.js +3 -1
  14. package/dist/expo-messenger.d.ts +10 -0
  15. package/dist/expo-messenger.js +7 -1
  16. package/dist/expo-reviews.js +1 -1
  17. package/dist/expo-screen.d.ts +32 -0
  18. package/dist/expo-screen.js +93 -49
  19. package/dist/expo-thumbnails.js +2 -2
  20. package/dist/expo-video-orientation.d.ts +7 -0
  21. package/dist/expo-video-orientation.js +14 -0
  22. package/dist/expo-video-thumbnail.d.ts +6 -0
  23. package/dist/expo-video-thumbnail.js +30 -0
  24. package/dist/expo-voicemail-recorder.d.ts +18 -0
  25. package/dist/expo-voicemail-recorder.js +214 -0
  26. package/dist/expo-voicemail-storage.d.ts +10 -0
  27. package/dist/expo-voicemail-storage.js +81 -0
  28. package/dist/expo-voicemail-video.d.ts +15 -0
  29. package/dist/expo-voicemail-video.js +44 -0
  30. package/dist/expo-voicemail.d.ts +34 -0
  31. package/dist/expo-voicemail.js +110 -0
  32. package/dist/expo.d.ts +3 -0
  33. package/dist/expo.js +3 -0
  34. package/dist/header-action-group.d.ts +11 -0
  35. package/dist/header-action-group.js +7 -0
  36. package/dist/header-calls.js +2 -1
  37. package/dist/history-anchor.d.ts +29 -0
  38. package/dist/history-anchor.js +74 -0
  39. package/dist/history-follow.d.ts +18 -0
  40. package/dist/history-follow.js +35 -0
  41. package/dist/index.d.ts +14 -1
  42. package/dist/index.js +94 -74
  43. package/dist/message-time.d.ts +7 -0
  44. package/dist/message-time.js +17 -0
  45. package/dist/messenger-video-view.d.ts +4 -1
  46. package/dist/messenger-video-view.js +15 -4
  47. package/dist/recording-notice.d.ts +5 -0
  48. package/dist/recording-notice.js +13 -0
  49. package/dist/use-quote-gesture.d.ts +1 -0
  50. package/dist/use-quote-gesture.js +1 -0
  51. package/dist/video-message-badge.d.ts +7 -0
  52. package/dist/video-message-badge.js +8 -0
  53. package/dist/video-orientation.d.ts +13 -0
  54. package/dist/video-orientation.js +58 -0
  55. package/dist/voice-composer.d.ts +3 -1
  56. package/dist/voice-composer.js +7 -6
  57. package/dist/voicemail-flow.d.ts +60 -0
  58. package/dist/voicemail-flow.js +156 -0
  59. package/dist/voicemail-media.d.ts +19 -0
  60. package/dist/voicemail-media.js +45 -0
  61. package/dist/voicemail-message.d.ts +41 -0
  62. package/dist/voicemail-message.js +48 -0
  63. package/dist/voicemail-prompts.d.ts +4 -0
  64. package/dist/voicemail-prompts.js +3 -0
  65. package/dist/voicemail-recording.d.ts +15 -0
  66. package/dist/voicemail-recording.js +46 -0
  67. package/dist/voicemail-session.d.ts +19 -0
  68. package/dist/voicemail-session.js +48 -0
  69. package/dist/voicemail.d.ts +179 -0
  70. package/dist/voicemail.js +234 -0
  71. package/package.json +9 -5
  72. package/plugin/prepare-native.cjs +1 -0
  73. package/plugin/video-display-mirror.cjs +66 -0
  74. package/setup.plugin.cjs +1 -0
@@ -1,4 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { RecordingNotice } from './recording-notice.js';
2
3
  import { messengerRecordingWaveform } from './voice-waveform.js';
3
4
  import { Text } from './typography.js';
4
5
  import { useRobonoLocale } from './localization.js';
@@ -9,18 +10,18 @@ function Waveform({ samples = [], color }) {
9
10
  return _jsx(View, { accessibilityLabel: uiText("Recording waveform"), style: { flex: 1, minWidth: 0, height: 28, flexDirection: 'row', alignItems: 'center', gap: 2, overflow: 'hidden' }, children: messengerRecordingWaveform(samples).map((value, i) => _jsx(View, { testID: "recording-waveform-bar", style: { flex: 1, minWidth: 2, borderRadius: 2, height: 2 + value * 24, backgroundColor: color, opacity: samples.length ? 1 : .25 } }, i)) });
10
11
  }
11
12
  /** Messenger's inline recorder; adapters supply media state and the optional text composer. */
12
- export function VoiceMessageComposer({ appearance, maxSeconds, busy, onRecord, actions, phase = 'idle', elapsedMs = 0, waveform, error, review, onStop, onSend, onRemove, renderTextComposer, renderAttachments }) {
13
+ export function VoiceMessageComposer({ appearance, maxSeconds, busy, onRecord, actions, phase = 'idle', elapsedMs = 0, waveform, error, review, onStop, onSend, onRemove, onRecordAgain, sendWhileRecording = false, renderTextComposer, renderAttachments }) {
13
14
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
14
15
  const c = appearance.colors, recording = phase === 'recording', waiting = phase === 'preparing' || phase === 'uploading' || (busy && phase === 'idle');
15
- const canSend = !!review && (phase === 'review' || phase === 'failed') && !!onSend;
16
+ const canSend = (!!review && (phase === 'review' || phase === 'failed') || recording && sendWhileRecording) && !!onSend;
16
17
  if (renderTextComposer && !recording && phase !== 'preparing' && phase !== 'uploading')
17
- return _jsxs(View, { style: { gap: 4 }, children: [renderAttachments ? renderAttachments(review, waiting) : review && _jsx(View, { style: { paddingHorizontal: 8, paddingTop: 4 }, children: review }), renderTextComposer({ sendVoice: canSend ? onSend : undefined, hasVoice: !!review, blocked: waiting }), !!error && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 8 }, children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 12, flex: 1 }, children: error }), onRemove && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel recording"), onPress: onRemove, style: { padding: 8 }, children: _jsx(MessageIcon, { name: "close", color: c.foreground, size: 18 }) })] })] });
18
- return _jsxs(View, { testID: "voice-only-composer", style: { gap: 5 }, children: [renderAttachments?.(review, waiting || recording), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'flex-end', gap: 4 }, children: [_jsxs(View, { style: { flex: 1, minWidth: 0, minHeight: 44, borderRadius: 22, backgroundColor: composerSurface(c.background), flexDirection: 'row', alignItems: 'center', overflow: 'hidden' }, children: [!recording && !review && !waiting && actions, review && !renderAttachments ? _jsx(View, { style: { flex: 1, minWidth: 0, paddingLeft: 10 }, children: review }) : recording ? _jsxs(View, { style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 6, paddingLeft: 10 }, children: [_jsx(Text, { style: { fontSize: 11, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(Math.floor(elapsedMs / 1000) * 1000) }), appearance.showWaveform !== false ? _jsx(Waveform, { samples: waveform, color: c.accent }) : _jsx(View, { style: { flex: 1 } }), _jsx(Text, { style: { fontSize: 11, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(maxSeconds * 1000) })] }) : _jsx(View, { style: { flex: 1, minWidth: 0, paddingHorizontal: 12 }, children: _jsx(Text, { style: { color: c.secondary, fontSize: 14, fontWeight: '800' }, children: waiting ? (phase === 'uploading' ? 'Sending…' : 'Preparing…') : uiText("Voice up to {value1}s", { value1: maxSeconds }) }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: recording ? uiText("Stop recording") : uiText("Voice message"), disabled: waiting || !!review || phase === 'failed', onPress: recording ? onStop : onRecord, style: { width: 42, height: 44, alignItems: 'center', justifyContent: 'center', opacity: (waiting || !!review || phase === 'failed') ? .45 : 1 }, children: waiting ? _jsx(ActivityIndicator, { size: "small", color: c.accent }) : _jsx(MessageIcon, { name: "mic", color: recording ? '#c94040' : c.accent, size: 23 }) })] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: canSend ? uiText("Send voice message") : uiText("Send unavailable"), accessibilityState: { disabled: !canSend }, disabled: !canSend, onPress: onSend, style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center', opacity: canSend ? 1 : .4 }, children: _jsx(MessageIcon, { name: "send", color: c.accent, size: 24 }) })] }), !!error && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 8 }, children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 12, flex: 1 }, children: error }), onRemove && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel recording"), onPress: onRemove, style: { padding: 8 }, children: _jsx(MessageIcon, { name: "close", color: c.foreground, size: 18 }) })] })] });
18
+ return _jsxs(View, { style: { gap: 4 }, children: [renderAttachments ? renderAttachments(review, waiting) : review && _jsx(View, { style: { paddingHorizontal: 8, paddingTop: 4 }, children: review }), renderTextComposer({ sendVoice: canSend ? onSend : undefined, hasVoice: !!review, blocked: waiting }), _jsx(RecordingNotice, { message: error })] });
19
+ return _jsxs(View, { testID: "voice-only-composer", style: { gap: 5 }, children: [renderAttachments?.(review, waiting || recording), _jsxs(View, { style: { flexDirection: 'row', alignItems: 'flex-end', gap: 4 }, children: [_jsxs(View, { style: { flex: 1, minWidth: 0, minHeight: 44, borderRadius: 22, backgroundColor: composerSurface(c.background), flexDirection: 'row', alignItems: 'center', overflow: 'hidden' }, children: [!recording && !review && !waiting && actions, review && !renderAttachments ? _jsx(View, { style: { flex: 1, minWidth: 0, paddingLeft: 10 }, children: review }) : recording ? _jsxs(View, { style: { flex: 1, minWidth: 0, flexDirection: 'row', alignItems: 'center', gap: 6, paddingLeft: 10 }, children: [_jsx(Text, { style: { fontSize: 11, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(Math.floor(elapsedMs / 1000) * 1000) }), appearance.showWaveform !== false ? _jsx(Waveform, { samples: waveform, color: c.accent }) : _jsx(View, { style: { flex: 1 } }), _jsx(Text, { style: { fontSize: 11, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(maxSeconds * 1000) })] }) : _jsx(View, { style: { flex: 1, minWidth: 0, paddingHorizontal: 12 }, children: _jsx(Text, { style: { color: c.secondary, fontSize: 14, fontWeight: '800' }, children: waiting ? (phase === 'uploading' ? 'Sending…' : 'Preparing…') : uiText("Voice up to {value1}s", { value1: maxSeconds }) }) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: recording ? uiText("Stop recording") : review && onRecordAgain && phase !== 'failed' ? uiText("Record again") : uiText("Voice message"), disabled: waiting || !!review && (!onRecordAgain || phase === 'failed'), onPress: recording ? onStop : review && onRecordAgain && phase !== 'failed' ? onRecordAgain : onRecord, style: { width: 42, height: 44, alignItems: 'center', justifyContent: 'center', opacity: (waiting || !!review && (!onRecordAgain || phase === 'failed')) ? .45 : 1 }, children: waiting ? _jsx(ActivityIndicator, { size: "small", color: c.accent }) : _jsx(MessageIcon, { name: "mic", color: recording ? '#c94040' : c.accent, size: 23 }) })] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: canSend ? uiText("Send voice message") : uiText("Send unavailable"), accessibilityState: { disabled: !canSend }, disabled: !canSend, onPress: onSend, style: { width: 44, height: 44, alignItems: 'center', justifyContent: 'center', opacity: canSend ? 1 : .4 }, children: _jsx(MessageIcon, { name: "send", color: c.accent, size: 24 }) })] }), _jsx(RecordingNotice, { message: error })] });
19
20
  }
20
21
  export function VoiceDraftPlayback({ appearance, playing, positionMs = 0, durationMs = 0, waveform, onToggle, onRemove, disabled = false, error, compact = false }) {
21
22
  const { text: uiText, locale: uiLocale, number: uiNumber, count: uiCount } = useRobonoLocale();
22
23
  const c = appearance.colors;
23
24
  if (compact)
24
- return _jsxs(View, { style: { width: 88, height: 84, paddingTop: 8, paddingRight: 10 }, children: [_jsxs(View, { style: { width: 76, height: 76, borderRadius: 9, borderWidth: 1, borderColor: c.secondary + '40', backgroundColor: c.background, alignItems: 'center', justifyContent: 'center', gap: 2 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause recorded voice message") : uiText("Play recorded voice message"), disabled: disabled, onPress: onToggle, style: { width: 44, height: 38, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: c.accent, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: playing ? 'pause' : 'play', color: "#fff", size: 18 }) }) }), _jsx(Text, { style: { fontSize: 10, fontWeight: '800', color: c.foreground }, children: duration(positionMs >= durationMs ? durationMs : durationMs - positionMs) })] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Remove voice message"), disabled: disabled, onPress: onRemove, style: { position: 'absolute', right: 0, top: 0, width: 30, height: 30, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 22, height: 22, borderRadius: 11, backgroundColor: c.foreground, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", color: c.background, size: 14 }) }) }), !!error && _jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 11 }, children: error })] });
25
- return _jsxs(View, { style: { flex: 1, minWidth: 0, gap: 3 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 7, minHeight: 44 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause recorded voice message") : uiText("Play recorded voice message"), disabled: disabled, onPress: onToggle, style: { width: 32, height: 32, borderRadius: 16, backgroundColor: c.accent, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: playing ? 'pause' : 'play', color: "#fff", size: 17 }) }), appearance.showWaveform !== false ? _jsx(Waveform, { samples: waveform, color: c.accent }) : _jsx(View, { style: { flex: 1 } }), _jsx(Text, { style: { fontSize: 12, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(positionMs >= durationMs ? durationMs : durationMs - positionMs) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Remove voice message"), disabled: disabled, onPress: onRemove, style: { width: 30, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", color: c.incomingText, size: 16 }) })] }), !!error && _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 8, paddingHorizontal: 8 }, children: [_jsx(Text, { accessibilityRole: "alert", style: { color: c.foreground, fontSize: 12, flex: 1 }, children: error }), onRemove && _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Cancel recording"), onPress: onRemove, style: { padding: 8 }, children: _jsx(MessageIcon, { name: "close", color: c.foreground, size: 18 }) })] })] });
25
+ return _jsxs(View, { style: { width: 88, height: 84, paddingTop: 8, paddingRight: 10 }, children: [_jsxs(View, { style: { width: 76, height: 76, borderRadius: 9, borderWidth: 1, borderColor: c.secondary + '40', backgroundColor: c.background, alignItems: 'center', justifyContent: 'center', gap: 2 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause recorded voice message") : uiText("Play recorded voice message"), disabled: disabled, onPress: onToggle, style: { width: 44, height: 38, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 28, height: 28, borderRadius: 14, backgroundColor: c.accent, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: playing ? 'pause' : 'play', color: "#fff", size: 18 }) }) }), _jsx(Text, { style: { fontSize: 10, fontWeight: '800', color: c.foreground }, children: duration(positionMs >= durationMs ? durationMs : durationMs - positionMs) })] }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Remove voice message"), disabled: disabled, onPress: onRemove, style: { position: 'absolute', right: 0, top: 0, width: 30, height: 30, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: { width: 22, height: 22, borderRadius: 11, backgroundColor: c.foreground, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", color: c.background, size: 14 }) }) }), _jsx(RecordingNotice, { message: error })] });
26
+ return _jsxs(View, { style: { flex: 1, minWidth: 0, gap: 3 }, children: [_jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 7, minHeight: 44 }, children: [_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: playing ? uiText("Pause recorded voice message") : uiText("Play recorded voice message"), disabled: disabled, onPress: onToggle, style: { width: 32, height: 32, borderRadius: 16, backgroundColor: c.accent, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: playing ? 'pause' : 'play', color: "#fff", size: 17 }) }), appearance.showWaveform !== false ? _jsx(Waveform, { samples: waveform, color: c.accent }) : _jsx(View, { style: { flex: 1 } }), _jsx(Text, { style: { fontSize: 12, fontWeight: '800', color: c.incomingText, fontVariant: ['tabular-nums'] }, children: duration(positionMs >= durationMs ? durationMs : durationMs - positionMs) }), _jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: uiText("Remove voice message"), disabled: disabled, onPress: onRemove, style: { width: 30, height: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(MessageIcon, { name: "close", color: c.incomingText, size: 16 }) })] }), _jsx(RecordingNotice, { message: error })] });
26
27
  }
@@ -0,0 +1,60 @@
1
+ /** Shared voice/video voicemail lifecycle. Capture begins only after the prompt
2
+ * and tone. Stop means review; hangup, Send and the recording limit mean send. */
3
+ export type VoicemailPhase = 'preparing' | 'prompt' | 'recording' | 'stopping' | 'review' | 'sending' | 'sent' | 'cancelled' | 'error';
4
+ export type VoicemailOption = {
5
+ kind: 'voice' | 'video';
6
+ maxDurationMs: number;
7
+ maxByteSize: number;
8
+ };
9
+ export interface VoicemailCapture<D> {
10
+ prepare(option: VoicemailOption, signal: AbortSignal): Promise<void>;
11
+ prompt(kind: 'voice' | 'video', signal: AbortSignal): Promise<void>;
12
+ start(option: VoicemailOption, signal: AbortSignal, onProgress: (ms: number, level?: number) => void, onLimit: () => void): Promise<void>;
13
+ stop(): Promise<D | null>;
14
+ cancel(): Promise<void>;
15
+ release(draft: D): Promise<void>;
16
+ }
17
+ export declare class VoicemailFlow<D> {
18
+ private options;
19
+ private detachTimer;
20
+ /** Defer final disposal so React StrictMode's effect replay preserves capture. */
21
+ attach(): () => void;
22
+ private listeners;
23
+ private abort;
24
+ private epoch;
25
+ private timer;
26
+ private stopWork;
27
+ private sendAfterStop;
28
+ private started;
29
+ private sendWork;
30
+ state: {
31
+ phase: VoicemailPhase;
32
+ elapsedMs: number;
33
+ waveform: number[];
34
+ draft: D | null;
35
+ error: string;
36
+ };
37
+ constructor(options: {
38
+ authorize: () => Promise<VoicemailOption>;
39
+ capture: VoicemailCapture<D>;
40
+ send: (draft: D) => Promise<void>;
41
+ onSent: () => void;
42
+ onCancel: () => void;
43
+ onError?: (error: unknown) => void;
44
+ });
45
+ subscribe: (listener: () => void) => () => void;
46
+ getSnapshot: () => {
47
+ phase: VoicemailPhase;
48
+ elapsedMs: number;
49
+ waveform: number[];
50
+ draft: D | null;
51
+ error: string;
52
+ };
53
+ private update;
54
+ begin(): Promise<void>;
55
+ finish(send?: boolean): Promise<void>;
56
+ send(): Promise<void>;
57
+ hangUp(): Promise<void>;
58
+ cancel(): Promise<void>;
59
+ dispose(): Promise<void>;
60
+ }
@@ -0,0 +1,156 @@
1
+ export class VoicemailFlow {
2
+ options;
3
+ detachTimer;
4
+ /** Defer final disposal so React StrictMode's effect replay preserves capture. */
5
+ attach() { clearTimeout(this.detachTimer); void this.begin(); return () => { this.detachTimer = setTimeout(() => void this.dispose(), 0); }; }
6
+ listeners = new Set();
7
+ abort = new AbortController();
8
+ epoch = 0;
9
+ timer;
10
+ stopWork = null;
11
+ sendAfterStop = false;
12
+ started = false;
13
+ sendWork = null;
14
+ state = { phase: 'preparing', elapsedMs: 0, waveform: [], draft: null, error: '' };
15
+ constructor(options) {
16
+ this.options = options;
17
+ }
18
+ subscribe = (listener) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; };
19
+ getSnapshot = () => this.state;
20
+ update(value) { this.state = { ...this.state, ...value }; for (const listener of this.listeners)
21
+ listener(); }
22
+ async begin() {
23
+ if (this.state.phase === 'error' && this.state.draft)
24
+ return;
25
+ if (this.started && !['review', 'error'].includes(this.state.phase))
26
+ return;
27
+ this.started = true;
28
+ const generation = ++this.epoch;
29
+ this.abort.abort();
30
+ this.abort = new AbortController();
31
+ const signal = this.abort.signal;
32
+ const old = this.state.draft;
33
+ this.update({ phase: 'preparing', draft: null, elapsedMs: 0, waveform: [], error: '' });
34
+ if (old)
35
+ await this.options.capture.release(old);
36
+ const valid = () => generation === this.epoch && !signal.aborted;
37
+ try {
38
+ const offer = await this.options.authorize();
39
+ if (!valid())
40
+ return;
41
+ const option = { ...offer, maxDurationMs: Math.min(60_000, offer.maxDurationMs) };
42
+ if (option.maxDurationMs < 1000)
43
+ throw Error('Unavailable');
44
+ await this.options.capture.prepare(option, signal);
45
+ if (!valid())
46
+ return;
47
+ this.update({ phase: 'prompt' });
48
+ await this.options.capture.prompt(option.kind, signal);
49
+ if (!valid())
50
+ return;
51
+ let reachedLimit = false;
52
+ await this.options.capture.start(option, signal, (ms, level) => { if (valid() && this.state.phase === 'recording')
53
+ this.update({ elapsedMs: Math.min(ms, option.maxDurationMs), ...(level == null ? {} : { waveform: [...this.state.waveform, Math.max(0, Math.min(1, level))].slice(-40) }) }); }, () => { if (valid()) {
54
+ reachedLimit = true;
55
+ if (this.state.phase === 'recording')
56
+ void this.finish(true);
57
+ } });
58
+ if (!valid()) {
59
+ await this.options.capture.cancel();
60
+ return;
61
+ }
62
+ this.update({ phase: 'recording' });
63
+ this.timer = setTimeout(() => void this.finish(true), option.maxDurationMs);
64
+ if (reachedLimit)
65
+ await this.finish(true);
66
+ }
67
+ catch (error) {
68
+ this.options.onError?.(error);
69
+ if (valid()) {
70
+ await this.options.capture.cancel();
71
+ if (valid())
72
+ this.update({ phase: 'error', error: 'Recording could not start. Try again.' });
73
+ }
74
+ }
75
+ }
76
+ async finish(send = false) {
77
+ if (this.state.phase === 'review' || this.state.phase === 'error' && this.state.draft) {
78
+ if (send)
79
+ await this.send();
80
+ return;
81
+ }
82
+ if (!['recording', 'stopping'].includes(this.state.phase))
83
+ return;
84
+ this.sendAfterStop ||= send;
85
+ if (this.stopWork)
86
+ return this.stopWork;
87
+ clearTimeout(this.timer);
88
+ const generation = this.epoch;
89
+ this.update({ phase: 'stopping' });
90
+ this.stopWork = (async () => {
91
+ try {
92
+ const draft = await this.options.capture.stop();
93
+ if (generation !== this.epoch) {
94
+ if (draft)
95
+ await this.options.capture.release(draft);
96
+ return;
97
+ }
98
+ if (!draft) {
99
+ this.update({ phase: 'cancelled' });
100
+ this.options.onCancel();
101
+ return;
102
+ }
103
+ this.update({ draft, phase: 'review' });
104
+ if (this.sendAfterStop)
105
+ await this.send();
106
+ }
107
+ catch (error) {
108
+ this.options.onError?.(error);
109
+ if (generation === this.epoch)
110
+ this.update({ phase: 'error', error: 'The recording could not finish. Try again.' });
111
+ }
112
+ finally {
113
+ this.stopWork = null;
114
+ this.sendAfterStop = false;
115
+ }
116
+ })();
117
+ return this.stopWork;
118
+ }
119
+ async send() {
120
+ if (this.sendWork)
121
+ return this.sendWork;
122
+ const draft = this.state.draft;
123
+ if (!draft)
124
+ return;
125
+ const generation = this.epoch;
126
+ this.update({ phase: 'sending', error: '' });
127
+ this.sendWork = (async () => {
128
+ try {
129
+ await this.options.send(draft);
130
+ if (generation !== this.epoch)
131
+ return;
132
+ this.update({ phase: 'sent', draft: null });
133
+ await this.options.capture.release(draft).catch(() => { });
134
+ this.options.onSent();
135
+ }
136
+ catch {
137
+ if (generation === this.epoch && this.state.phase !== 'sent')
138
+ this.update({ phase: 'error', error: 'Your recording is saved here. Try sending again.' });
139
+ }
140
+ finally {
141
+ this.sendWork = null;
142
+ }
143
+ })();
144
+ return this.sendWork;
145
+ }
146
+ async hangUp() { if (['recording', 'stopping', 'review'].includes(this.state.phase) || this.state.draft)
147
+ return this.finish(true); if (this.state.phase !== 'sending')
148
+ await this.cancel(); }
149
+ async cancel() { if (this.state.phase === 'sending' || this.state.phase === 'sent')
150
+ return; await this.dispose(); this.update({ phase: 'cancelled', draft: null }); this.options.onCancel(); }
151
+ async dispose() { if (this.sendWork)
152
+ await this.sendWork; this.epoch++; clearTimeout(this.timer); this.abort.abort(); await this.options.capture.cancel(); const draft = this.state.draft; if (draft) {
153
+ this.state = { ...this.state, draft: null };
154
+ await this.options.capture.release(draft);
155
+ } }
156
+ }
@@ -0,0 +1,19 @@
1
+ import { type MessageMedia } from '@robono/messaging';
2
+ import { MessagingMediaController, type MessagingMediaDevice, type MessagingMediaStorage } from './media-controller.js';
3
+ import type { VoicemailAPI, VoicemailDraft } from './voicemail.js';
4
+ export interface VoicemailMediaDraft extends VoicemailDraft {
5
+ media: MessageMedia;
6
+ kind: 'voice' | 'video';
7
+ }
8
+ /** Reuse capture and review mechanics without inheriting ordinary messaging
9
+ * permissions. Limits come exclusively from the authorized voicemail offer. */
10
+ export declare function createVoicemailMedia({ callId, device, storage, createId }: {
11
+ callId: string;
12
+ device: MessagingMediaDevice;
13
+ storage: MessagingMediaStorage;
14
+ createId: () => string;
15
+ }): {
16
+ controller: MessagingMediaController;
17
+ record(option: Pick<Awaited<ReturnType<VoicemailAPI["options"]>>, "kind" | "maxDurationMs" | "maxByteSize">): Promise<VoicemailMediaDraft | null>;
18
+ dispose(): Promise<void>;
19
+ };
@@ -0,0 +1,45 @@
1
+ import { defaultMessagingSettings } from '@robono/messaging';
2
+ import { MessagingMediaController } from './media-controller.js';
3
+ /** Reuse capture and review mechanics without inheriting ordinary messaging
4
+ * permissions. Limits come exclusively from the authorized voicemail offer. */
5
+ export function createVoicemailMedia({ callId, device, storage, createId }) {
6
+ let disposed = false, settings = defaultMessagingSettings('Voicemail');
7
+ const controller = new MessagingMediaController({ device, storage, createId, stageLocal: true, getConversationId: () => callId, getSettings: () => settings });
8
+ return {
9
+ controller,
10
+ async record(option) {
11
+ if (disposed)
12
+ throw Error('Voicemail is closed.');
13
+ if (!['voice', 'video'].includes(option.kind) || !Number.isSafeInteger(option.maxDurationMs) || option.maxDurationMs < 1000 || option.maxDurationMs > 3600000 || !Number.isSafeInteger(option.maxByteSize) || option.maxByteSize < 1 || option.maxByteSize > 104857600)
14
+ throw Error('Voicemail recording limits are unavailable.');
15
+ settings = defaultMessagingSettings('Voicemail');
16
+ settings.enabled = true;
17
+ for (const kind of Object.keys(settings.features))
18
+ settings.features[kind] = false;
19
+ settings.features[option.kind] = true;
20
+ settings.unansweredCalls = { voice: 'voice', video: 'video' };
21
+ settings.voice.maxDurationSeconds = option.maxDurationMs / 1000;
22
+ settings.attachments.video.maxDurationSeconds = option.maxDurationMs / 1000;
23
+ settings.attachments.video.maxFileBytes = option.maxByteSize;
24
+ const media = await controller.pick(option.kind, option.kind === 'video' ? 'call-video' : undefined, 'attach');
25
+ if (!media)
26
+ return null;
27
+ if (disposed) {
28
+ await controller.releasePrepared(media.assetId);
29
+ return null;
30
+ }
31
+ if (media.byteSize > option.maxByteSize || (media.durationMs ?? 0) > option.maxDurationMs) {
32
+ await controller.releasePrepared(media.assetId);
33
+ throw Error('The recording exceeds the voicemail limit.');
34
+ }
35
+ let released = false;
36
+ return { media, kind: option.kind,
37
+ upload: async () => { if (released || disposed)
38
+ throw Error('The recording is no longer available.'); return controller.uploadPrepared(media.assetId, option.kind); },
39
+ release: async () => { if (released)
40
+ return; released = true; await controller.releasePrepared(media.assetId); },
41
+ };
42
+ },
43
+ async dispose() { disposed = true; await controller.dispose(); },
44
+ };
45
+ }
@@ -0,0 +1,41 @@
1
+ import React, { type ReactNode } from 'react';
2
+ import type { MessagingAppearance } from '@robono/messaging';
3
+ import type { VoicemailRecord } from './voicemail.js';
4
+ /** Shared compact title for voice and video recordings on native and web. */
5
+ export declare function VoicemailMessageTitle({ color, compact }: {
6
+ color: string;
7
+ compact?: boolean;
8
+ }): React.JSX.Element;
9
+ export declare const VoicemailMessageActionContext: React.Context<VoicemailMessageActions | undefined>;
10
+ export declare const VoicemailMessageMenu: React.Context<(() => void) | undefined>;
11
+ /** Host actions use the recording's identity, never the missed-call row's ID.
12
+ * Forwarding must copy authorized media through the destination's normal outbox. */
13
+ export interface VoicemailMessageActions {
14
+ quote?: (message: VoicemailRecord) => void;
15
+ forward?: (message: VoicemailRecord) => void;
16
+ /** Use the integration's ordinary media viewer, with the same permissions/actions. */
17
+ openMedia?: (message: VoicemailRecord, file: {
18
+ uri: string;
19
+ mimeType: string;
20
+ byteSize: number;
21
+ durationMs?: number;
22
+ }, previewUri?: string) => void;
23
+ delete?: (message: VoicemailRecord) => void;
24
+ }
25
+ export declare function voicemailVideoSize(aspect: number): {
26
+ width: number;
27
+ height: number;
28
+ };
29
+ /** Reuses Messenger's bidirectional swipe gesture on both native and web. */
30
+ export declare function VoicemailMessageBubble({ message, appearance, actions, children }: {
31
+ message: VoicemailRecord;
32
+ appearance: MessagingAppearance;
33
+ actions?: VoicemailMessageActions;
34
+ children: ReactNode;
35
+ }): React.JSX.Element;
36
+ /** Same inside/below/swipe setting as ordinary message timestamps. */
37
+ export declare function VoicemailTimestamp({ message, appearance, placement }: {
38
+ message: VoicemailRecord;
39
+ appearance: MessagingAppearance;
40
+ placement: 'inside' | 'below' | 'slide';
41
+ }): React.JSX.Element | null;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CallMessageTail, CallMessageStatus } from './call-message-decoration.js';
3
+ import { useMessagingAppearance } from './appearance-context.js';
4
+ import { useMessagingTimeFormat } from './message-time.js';
5
+ import { MessageIcon } from './icons.js';
6
+ import { useState, useRef, createContext } from 'react';
7
+ import { Animated, Platform, Pressable, View } from 'react-native';
8
+ import Svg, { Path } from 'react-native-svg';
9
+ import { Text, MessagingTypography } from './typography.js';
10
+ import { bubbleCorners, messageSpacing } from './bubble-design.js';
11
+ import { useQuoteGesture } from './use-quote-gesture.js';
12
+ import { MessagingPopup } from './popup.js';
13
+ /** Shared compact title for voice and video recordings on native and web. */
14
+ export function VoicemailMessageTitle({ color, compact = false }) {
15
+ return _jsxs(View, { style: { flexDirection: 'row', alignItems: 'center', gap: 4 }, children: [_jsx(Svg, { testID: "voicemail-title-icon", width: compact ? 13 : 16, height: compact ? 13 : 16, viewBox: "0 0 24 24", accessible: false, "aria-hidden": true, children: _jsx(Path, { d: "M6 17a4 4 0 1 1 0-8 4 4 0 0 1 0 8h12a4 4 0 1 0-4-4 4 4 0 0 0 4 4", fill: "none", stroke: color, strokeWidth: 1.7, strokeLinecap: "round", strokeLinejoin: "round" }) }), _jsx(Text, { testID: "voicemail-title", style: { fontSize: compact ? 11 : 14, fontWeight: '600', color }, children: "Voicemail" })] });
16
+ }
17
+ export const VoicemailMessageActionContext = createContext(undefined);
18
+ export const VoicemailMessageMenu = createContext(undefined);
19
+ export function voicemailVideoSize(aspect) {
20
+ const ratio = Number.isFinite(aspect) && aspect > 0 ? aspect : .75;
21
+ const height = Math.min(214, 160 / ratio);
22
+ return { width: Math.round(height * ratio), height: Math.round(height) };
23
+ }
24
+ /** Reuses Messenger's bidirectional swipe gesture on both native and web. */
25
+ export function VoicemailMessageBubble({ message, appearance, actions, children }) {
26
+ const formatTime = useMessagingTimeFormat();
27
+ const mine = message.direction === 'sent', c = appearance.colors;
28
+ const voice = message.kind === 'voice';
29
+ const topTail = appearance.presentation?.bubbleStyle === 'top-tail', corners = { ...bubbleCorners(appearance, mine), ...(topTail ? (mine ? { borderTopRightRadius: 0 } : { borderTopLeftRadius: 0 }) : {}) };
30
+ const [menu, setMenu] = useState(false), afterMenu = useRef(null);
31
+ const dismissed = () => { const action = afterMenu.current; afterMenu.current = null; action?.(); };
32
+ const choose = (action) => { afterMenu.current = action; setMenu(false); if (Platform.OS !== 'ios')
33
+ dismissed(); };
34
+ const gesture = useQuoteGesture(true, mine, actions?.quote ? () => actions.quote(message) : undefined);
35
+ const openMenu = () => { gesture.cancel(); setMenu(true); };
36
+ const status = message.readAt ? (message.kind === 'voice' ? 'Heard' : 'Watched') : (mine ? (message.deliveredAt ? 'Delivered' : 'Sent') : 'Received');
37
+ return _jsx(MessagingTypography, { appearance: appearance, children: _jsxs(View, { testID: 'voicemail-message:' + message.id, style: { alignSelf: 'stretch', marginTop: messageSpacing(appearance) }, children: [_jsxs(Animated.View, { pointerEvents: "none", accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: { position: 'absolute', top: 0, bottom: 0, ...(mine ? { left: 8 } : { right: 8 }), justifyContent: 'center', opacity: gesture.infoOpacity }, children: [_jsx(VoicemailTimestamp, { message: message, appearance: appearance, placement: "slide" }), _jsxs(Text, { style: { fontSize: 11, color: c.secondary }, children: [status, message.readAt ? ' · ' + formatTime(new Date(message.readAt).toISOString()) : ''] })] }), actions?.quote && _jsx(Animated.View, { pointerEvents: "none", accessible: false, accessibilityElementsHidden: true, style: { position: 'absolute', top: '50%', marginTop: -20, ...(mine ? { right: 8 } : { left: 8 }), width: 40, height: 40, borderRadius: 20, alignItems: 'center', justifyContent: 'center', backgroundColor: c.background, opacity: gesture.revealOpacity }, children: _jsx(MessageIcon, { name: "quote", color: c.accent, size: 28 }) }), _jsxs(Animated.View, { ref: gesture.webRef, ...gesture.handlers, style: { alignItems: mine ? 'flex-end' : 'flex-start', transform: [{ translateX: gesture.offset }], ...gesture.webStyle }, children: [_jsxs(Pressable, { onLongPress: openMenu, accessibilityLabel: `${message.kind === 'voice' ? 'Voice' : 'Video'} voicemail`, accessibilityActions: [...(actions?.quote ? [{ name: 'reply', label: 'Quote' }] : []), ...(actions?.forward ? [{ name: 'forward', label: 'Forward' }] : [])], onAccessibilityAction: e => { if (e.nativeEvent.actionName === 'reply')
38
+ actions?.quote?.(message); if (e.nativeEvent.actionName === 'forward')
39
+ actions?.forward?.(message); }, style: { alignSelf: mine ? 'flex-end' : 'flex-start', ...corners, maxWidth: `${appearance.screens?.chat?.messageWidth ?? 88}%`, backgroundColor: voice ? 'transparent' : mine ? c.outgoing : c.incoming }, children: [_jsx(CallMessageTail, { appearance: appearance, mine: mine }), _jsx(CallMessageStatus, { appearance: appearance, mine: mine, delivered: !!message.deliveredAt, consumed: !!message.readAt, label: status }), _jsx(View, { style: voice ? undefined : { ...corners, overflow: 'hidden' }, children: _jsx(VoicemailMessageActionContext.Provider, { value: actions, children: _jsx(VoicemailMessageMenu.Provider, { value: openMenu, children: children }) }) })] }), _jsx(CallMessageStatus, { appearance: appearance, mine: mine, delivered: !!message.deliveredAt, consumed: !!message.readAt, label: status, placement: "below" }), _jsx(VoicemailTimestamp, { message: message, appearance: appearance, placement: "below" })] }), _jsxs(MessagingPopup, { visible: menu, onDismiss: dismissed, compact: true, title: "Voicemail", foreground: c.foreground, background: c.background, onClose: () => setMenu(false), children: [actions?.quote && _jsx(Pressable, { accessibilityRole: "button", onPress: () => choose(() => actions.quote(message)), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground }, children: "Quote" }) }), actions?.forward && _jsx(Pressable, { accessibilityRole: "button", onPress: () => choose(() => actions.forward(message)), style: { minHeight: 44, justifyContent: 'center' }, children: _jsx(Text, { style: { color: c.foreground }, children: "Forward" }) }), _jsxs(Text, { style: { color: c.secondary, fontSize: 12 }, children: [status, " \u00B7 ", formatTime(new Date(message.readAt ?? message.createdAt).toISOString())] })] })] }) });
40
+ }
41
+ /** Same inside/below/swipe setting as ordinary message timestamps. */
42
+ export function VoicemailTimestamp({ message, appearance, placement }) {
43
+ const inherited = useMessagingAppearance(), format = useMessagingTimeFormat(), design = inherited ?? appearance;
44
+ if ((design.messageTime?.position ?? 'slide') !== placement)
45
+ return null;
46
+ const value = format(new Date(message.createdAt).toISOString());
47
+ return _jsx(Text, { testID: 'voicemail-time-' + placement, accessibilityLabel: 'Sent: ' + value, style: { fontSize: 10, lineHeight: 12, fontVariant: ['tabular-nums'], color: placement === 'inside' ? (message.direction === 'sent' ? design.colors.outgoingText : design.colors.incomingText) : design.colors.secondary, ...(placement === 'below' ? { marginTop: 2 } : null) }, children: value });
48
+ }