livevoice-sdk-react-native 2.0.1 → 3.0.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/README.md +105 -66
- package/android/build.gradle +5 -4
- package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +122 -188
- package/android/src/main/java/io/livevoice/react/__SDK.kt +2 -2
- package/ios/LiveVoiceRNBridge.swift +362 -0
- package/ios/LiveVoiceSdkReactNative.mm +187 -158
- package/ios/__SDK.h +1 -1
- package/ios/livevoice_spm_backport.rb +202 -0
- package/lib/module/components/BrandingView.js +58 -39
- package/lib/module/components/BrandingView.js.map +1 -1
- package/lib/module/components/ChannelView.js +355 -44
- package/lib/module/components/ChannelView.js.map +1 -1
- package/lib/module/components/ErrorView.js +5 -6
- package/lib/module/components/ErrorView.js.map +1 -1
- package/lib/module/components/LiveVoiceSpinner.js +81 -0
- package/lib/module/components/LiveVoiceSpinner.js.map +1 -0
- package/lib/module/components/LiveVoiceView.js +311 -133
- package/lib/module/components/LiveVoiceView.js.map +1 -1
- package/lib/module/components/PasswordPrompt.js +165 -0
- package/lib/module/components/PasswordPrompt.js.map +1 -0
- package/lib/module/components/PlayButtonView.js +180 -244
- package/lib/module/components/PlayButtonView.js.map +1 -1
- package/lib/module/components/ReconnectingView.js +31 -53
- package/lib/module/components/ReconnectingView.js.map +1 -1
- package/lib/module/icons/branding-ios.png +0 -0
- package/lib/module/icons/camera-off-android.png +0 -0
- package/lib/module/icons/camera-off-android@2x.png +0 -0
- package/lib/module/icons/camera-off-android@3x.png +0 -0
- package/lib/module/icons/cpu-android.png +0 -0
- package/lib/module/icons/cpu-android@2x.png +0 -0
- package/lib/module/icons/cpu-android@3x.png +0 -0
- package/lib/module/icons/cpu-ios.png +0 -0
- package/lib/module/icons/cpu-ios@2x.png +0 -0
- package/lib/module/icons/cpu-ios@3x.png +0 -0
- package/lib/module/icons/lock-android.png +0 -0
- package/lib/module/icons/lock-android@2x.png +0 -0
- package/lib/module/icons/lock-android@3x.png +0 -0
- package/lib/module/icons/lock-ios.png +0 -0
- package/lib/module/icons/lock-ios@2x.png +0 -0
- package/lib/module/icons/lock-ios@3x.png +0 -0
- package/lib/module/icons/mic-off-android.png +0 -0
- package/lib/module/icons/mic-off-android@2x.png +0 -0
- package/lib/module/icons/mic-off-android@3x.png +0 -0
- package/lib/module/icons/mic-slash-ios.png +0 -0
- package/lib/module/icons/mic-slash-ios@2x.png +0 -0
- package/lib/module/icons/mic-slash-ios@3x.png +0 -0
- package/lib/module/icons/video-slash-ios.png +0 -0
- package/lib/module/icons/video-slash-ios@2x.png +0 -0
- package/lib/module/icons/video-slash-ios@3x.png +0 -0
- package/lib/module/index.js +11 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/sdk/Bridge.js +236 -0
- package/lib/module/sdk/Bridge.js.map +1 -0
- package/lib/module/sdk/Event.js +160 -0
- package/lib/module/sdk/Event.js.map +1 -0
- package/lib/module/sdk/Lifecycle.js +331 -0
- package/lib/module/sdk/Lifecycle.js.map +1 -0
- package/lib/module/sdk/LiveVoiceSdk.js +262 -268
- package/lib/module/sdk/LiveVoiceSdk.js.map +1 -1
- package/lib/module/sdk/LiveVoiceState.js +208 -40
- package/lib/module/sdk/LiveVoiceState.js.map +1 -1
- package/lib/module/sdk/LogEntries.js +99 -0
- package/lib/module/sdk/LogEntries.js.map +1 -0
- package/lib/module/sdk/Models.js +2 -0
- package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
- package/lib/module/{util/PlayingState.js → sdk/NativeSdkVersions.js} +9 -8
- package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
- package/lib/module/sdk/Observables.js +391 -0
- package/lib/module/sdk/Observables.js.map +1 -0
- package/lib/module/sdk/Passwords.js +298 -0
- package/lib/module/sdk/Passwords.js.map +1 -0
- package/lib/module/sdk/Playback.js +35 -0
- package/lib/module/sdk/Playback.js.map +1 -0
- package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
- package/lib/module/util/Colors.js +2 -1
- package/lib/module/util/Colors.js.map +1 -1
- package/lib/module/util/Translations.js +34 -11
- package/lib/module/util/Translations.js.map +1 -1
- package/lib/module/util/freeze.js +26 -0
- package/lib/module/util/freeze.js.map +1 -0
- package/lib/module/util/logger.js +79 -41
- package/lib/module/util/logger.js.map +1 -1
- package/lib/typescript/src/components/BrandingView.d.ts +4 -0
- package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
- package/lib/typescript/src/components/ChannelView.d.ts +29 -3
- package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
- package/lib/typescript/src/components/ErrorView.d.ts +5 -3
- package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
- package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
- package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveVoiceView.d.ts +81 -21
- package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
- package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
- package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
- package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
- package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
- package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
- package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +15 -6
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
- package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Event.d.ts +97 -0
- package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
- package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
- package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +195 -190
- package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -1
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts +77 -9
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -1
- package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
- package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Models.d.ts +114 -0
- package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
- package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
- package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Observables.d.ts +123 -0
- package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
- package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
- package/lib/typescript/src/sdk/Playback.d.ts +9 -0
- package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +34 -31
- package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
- package/lib/typescript/src/util/Colors.d.ts.map +1 -1
- package/lib/typescript/src/util/Translations.d.ts +30 -8
- package/lib/typescript/src/util/Translations.d.ts.map +1 -1
- package/lib/typescript/src/util/freeze.d.ts +6 -0
- package/lib/typescript/src/util/freeze.d.ts.map +1 -0
- package/lib/typescript/src/util/logger.d.ts +17 -7
- package/lib/typescript/src/util/logger.d.ts.map +1 -1
- package/livevoice-sdk-react-native.podspec +29 -4
- package/package.json +12 -9
- package/src/components/BrandingView.tsx +42 -55
- package/src/components/ChannelView.tsx +329 -38
- package/src/components/ErrorView.tsx +9 -12
- package/src/components/LiveVoiceSpinner.tsx +87 -0
- package/src/components/LiveVoiceView.tsx +319 -201
- package/src/components/PasswordPrompt.tsx +144 -0
- package/src/components/PlayButtonView.tsx +165 -269
- package/src/components/ReconnectingView.tsx +28 -81
- package/src/icons/branding-ios.png +0 -0
- package/src/icons/camera-off-android.png +0 -0
- package/src/icons/camera-off-android@2x.png +0 -0
- package/src/icons/camera-off-android@3x.png +0 -0
- package/src/icons/cpu-android.png +0 -0
- package/src/icons/cpu-android@2x.png +0 -0
- package/src/icons/cpu-android@3x.png +0 -0
- package/src/icons/cpu-ios.png +0 -0
- package/src/icons/cpu-ios@2x.png +0 -0
- package/src/icons/cpu-ios@3x.png +0 -0
- package/src/icons/lock-android.png +0 -0
- package/src/icons/lock-android@2x.png +0 -0
- package/src/icons/lock-android@3x.png +0 -0
- package/src/icons/lock-ios.png +0 -0
- package/src/icons/lock-ios@2x.png +0 -0
- package/src/icons/lock-ios@3x.png +0 -0
- package/src/icons/mic-off-android.png +0 -0
- package/src/icons/mic-off-android@2x.png +0 -0
- package/src/icons/mic-off-android@3x.png +0 -0
- package/src/icons/mic-slash-ios.png +0 -0
- package/src/icons/mic-slash-ios@2x.png +0 -0
- package/src/icons/mic-slash-ios@3x.png +0 -0
- package/src/icons/video-slash-ios.png +0 -0
- package/src/icons/video-slash-ios@2x.png +0 -0
- package/src/icons/video-slash-ios@3x.png +0 -0
- package/src/index.tsx +92 -6
- package/src/sdk/Bridge.ts +259 -0
- package/src/sdk/Event.ts +187 -0
- package/src/sdk/Lifecycle.ts +366 -0
- package/src/sdk/LiveVoiceSdk.ts +285 -309
- package/src/sdk/LiveVoiceState.ts +230 -60
- package/src/sdk/LogEntries.ts +88 -0
- package/src/sdk/Models.ts +129 -0
- package/src/{util/PlayingState.ts → sdk/NativeSdkVersions.ts} +7 -6
- package/src/sdk/Observables.ts +414 -0
- package/src/sdk/Passwords.ts +286 -0
- package/src/sdk/Playback.ts +30 -0
- package/src/specs/NativeLiveVoiceSdk.ts +42 -38
- package/src/util/Colors.ts +2 -1
- package/src/util/Translations.ts +34 -12
- package/src/util/freeze.ts +23 -0
- package/src/util/logger.ts +79 -52
- package/lib/module/components/AudioOutputSwitchView.js +0 -138
- package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
- package/lib/module/components/index.js +0 -24
- package/lib/module/components/index.js.map +0 -1
- package/lib/module/icons/mic.png +0 -0
- package/lib/module/util/ForegroundServiceConfig.js +0 -38
- package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
- package/lib/module/util/PlayingState.js.map +0 -1
- package/lib/module/util/UIState.js +0 -4
- package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
- package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
- package/lib/typescript/src/components/index.d.ts +0 -9
- package/lib/typescript/src/components/index.d.ts.map +0 -1
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -19
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
- package/lib/typescript/src/util/PlayingState.d.ts +0 -7
- package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
- package/lib/typescript/src/util/UIState.d.ts +0 -86
- package/lib/typescript/src/util/UIState.d.ts.map +0 -1
- package/src/components/AudioOutputSwitchView.tsx +0 -146
- package/src/components/index.tsx +0 -21
- package/src/icons/mic.png +0 -0
- package/src/util/ForegroundServiceConfig.tsx +0 -42
- package/src/util/UIState.ts +0 -106
|
@@ -11,79 +11,249 @@
|
|
|
11
11
|
//
|
|
12
12
|
//===----------------------------------------------------------------------===//
|
|
13
13
|
|
|
14
|
-
// Internal
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
14
|
+
// Internal: the default view's model, the bridge's `defaultView` (bridge.md 2.4). Only
|
|
15
|
+
// LiveVoiceView reads it; nothing here is exported from the package entry point.
|
|
16
|
+
|
|
17
|
+
import { decodeState, observeState, record } from './Bridge';
|
|
18
|
+
import { decodeError, decodeRetry, LiveVoiceError, type RetryValue } from './Lifecycle';
|
|
19
|
+
import {
|
|
20
|
+
type LiveVoiceAiTranslationInfo,
|
|
21
|
+
type LiveVoiceChannel,
|
|
22
|
+
type LiveVoiceDependentChannel,
|
|
23
|
+
type LiveVoiceFeatures,
|
|
24
|
+
type LiveVoicePlayingState,
|
|
25
|
+
} from './Models';
|
|
26
|
+
import { logDecodeError, logViewState } from '../util/logger';
|
|
27
|
+
|
|
28
|
+
/** The event's brand colours, `'#RRGGBB'`. */
|
|
29
|
+
export type BrandColors = { light: string; dark: string };
|
|
30
|
+
|
|
31
|
+
/** What a double tap or a named action on a default cell does (bridge.md 2.4). */
|
|
32
|
+
export type CellActionKind = 'toggleAudio' | 'toggleSubtitles';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A default cell's accessibility, computed natively by the native default cell's own code and in
|
|
36
|
+
* the native SDK's language (bridge.md 2.4). The cell renders exactly this.
|
|
37
|
+
*/
|
|
38
|
+
export type CellAccessibility = {
|
|
39
|
+
/** The channel name. */
|
|
40
|
+
label: string;
|
|
41
|
+
/** The row's states as the native cell joins them; `''` when there are none. */
|
|
42
|
+
value: string;
|
|
43
|
+
isButton: boolean;
|
|
44
|
+
isSelected: boolean;
|
|
45
|
+
/** What a double tap does, or `null` where it does nothing. */
|
|
46
|
+
activation: CellActionKind | null;
|
|
47
|
+
/** The named actions in the native order, each with its localised name. */
|
|
48
|
+
actions: { kind: CellActionKind; name: string }[];
|
|
42
49
|
};
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
51
|
+
/** A default cell's status line under the name, as native computed it (bridge.md 2.4). */
|
|
52
|
+
export type CellStatus = {
|
|
53
|
+
/** The localised line, for example "Inactive" or "AI active". */
|
|
54
|
+
text: string;
|
|
55
|
+
/** The CPU icon precedes the text: an online AI speaker. */
|
|
56
|
+
showsAiIcon: boolean;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** A default cell's mute mark, as native computed it (bridge.md 2.4). */
|
|
60
|
+
export type CellMuteMark = 'microphone' | 'camera';
|
|
61
|
+
|
|
62
|
+
/** The part the default view shows. */
|
|
63
|
+
export type ViewPart =
|
|
64
|
+
| { kind: 'loading' }
|
|
65
|
+
| {
|
|
66
|
+
kind: 'ready';
|
|
67
|
+
channels: LiveVoiceChannel[];
|
|
68
|
+
/** Each channel's `LiveVoiceChannelCell.isEnabled`, by id. */
|
|
69
|
+
isEnabled: ReadonlyMap<number, boolean>;
|
|
70
|
+
/** Whether each channel's subtitles are the open ones, by id: the default cell's marker. */
|
|
71
|
+
subtitlesOpen: ReadonlyMap<number, boolean>;
|
|
72
|
+
/** Each default cell's accessibility, by id; `null` for one native did not send. */
|
|
73
|
+
accessibility: ReadonlyMap<number, CellAccessibility | null>;
|
|
74
|
+
/** Each default cell's status line, by id; `null` for none. */
|
|
75
|
+
status: ReadonlyMap<number, CellStatus | null>;
|
|
76
|
+
/** Each default cell's mute mark, by id; `null` for none. */
|
|
77
|
+
muteMark: ReadonlyMap<number, CellMuteMark | null>;
|
|
78
|
+
/** The list stays, drawn disabled, while the connection briefly recovers. */
|
|
79
|
+
inReconnectGrace: boolean;
|
|
80
|
+
brandColors: BrandColors | null;
|
|
81
|
+
}
|
|
82
|
+
| { kind: 'reconnecting'; retry: RetryValue }
|
|
83
|
+
| { kind: 'error'; error: LiveVoiceError };
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The default view's model: the part to show, and the permission of the join it belongs to,
|
|
87
|
+
* `null` until that join has authenticated. The gate and the branding read this permission, so
|
|
88
|
+
* channels and permission always come from the same join.
|
|
89
|
+
*/
|
|
90
|
+
export type ViewModel = { part: ViewPart; features: LiveVoiceFeatures | null };
|
|
49
91
|
|
|
50
|
-
|
|
51
|
-
|
|
92
|
+
const loading: ViewModel = { part: { kind: 'loading' }, features: null };
|
|
93
|
+
|
|
94
|
+
let current: ViewModel = loading;
|
|
95
|
+
|
|
96
|
+
// The default view's decoder in the bridge, before any observer hears of a change. An undecodable
|
|
97
|
+
// view shows the loading part, is logged, and satisfies no command's revisions.
|
|
98
|
+
decodeState('defaultView', wire => {
|
|
99
|
+
try {
|
|
100
|
+
current = viewModel(wire);
|
|
101
|
+
return true;
|
|
102
|
+
} catch {
|
|
103
|
+
current = loading;
|
|
104
|
+
logDecodeError('state', 'defaultView');
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export function getCurrentViewModel(): ViewModel {
|
|
110
|
+
return current;
|
|
52
111
|
}
|
|
53
112
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
handler(state);
|
|
113
|
+
/** Calls `handler` whenever the default view changes. */
|
|
114
|
+
export function onViewModelChanged(handler: (model: ViewModel) => void): { remove: () => void } {
|
|
115
|
+
const remove = observeState('defaultView', () => {
|
|
116
|
+
const model = getCurrentViewModel();
|
|
117
|
+
logViewState(model);
|
|
118
|
+
handler(model);
|
|
61
119
|
});
|
|
120
|
+
return { remove };
|
|
62
121
|
}
|
|
63
122
|
|
|
64
|
-
|
|
65
|
-
|
|
123
|
+
/** The model of a `defaultView` value; throws for one that is no view at all. */
|
|
124
|
+
function viewModel(wire: unknown): ViewModel {
|
|
125
|
+
if (!record(wire)) throw new TypeError('defaultView');
|
|
126
|
+
const permission = features(wire.features);
|
|
127
|
+
switch (wire.kind) {
|
|
128
|
+
case 'loading':
|
|
129
|
+
return loading;
|
|
130
|
+
case 'ready': {
|
|
131
|
+
const wireChannels = Array.isArray(wire.channels) ? wire.channels.filter(record) : [];
|
|
132
|
+
const isEnabled = new Map<number, boolean>();
|
|
133
|
+
const subtitlesOpen = new Map<number, boolean>();
|
|
134
|
+
const accessibility = new Map<number, CellAccessibility | null>();
|
|
135
|
+
const status = new Map<number, CellStatus | null>();
|
|
136
|
+
const muteMark = new Map<number, CellMuteMark | null>();
|
|
137
|
+
const channels = wireChannels.map(wireChannel => {
|
|
138
|
+
const channel = decodeChannel(wireChannel);
|
|
139
|
+
isEnabled.set(channel.id, wireChannel.isEnabled === true);
|
|
140
|
+
subtitlesOpen.set(channel.id, wireChannel.subtitlesOpen === true);
|
|
141
|
+
accessibility.set(channel.id, cellAccessibility(wireChannel.accessibility));
|
|
142
|
+
status.set(channel.id, cellStatus(wireChannel.status));
|
|
143
|
+
muteMark.set(channel.id, cellMuteMark(wireChannel.muteMark));
|
|
144
|
+
return channel;
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
part: {
|
|
148
|
+
kind: 'ready',
|
|
149
|
+
channels,
|
|
150
|
+
isEnabled,
|
|
151
|
+
subtitlesOpen,
|
|
152
|
+
accessibility,
|
|
153
|
+
status,
|
|
154
|
+
muteMark,
|
|
155
|
+
inReconnectGrace: wire.inReconnectGrace === true,
|
|
156
|
+
brandColors: brandColors(wire.brandColors),
|
|
157
|
+
},
|
|
158
|
+
features: permission,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
case 'reconnecting':
|
|
162
|
+
return {
|
|
163
|
+
part: { kind: 'reconnecting', retry: decodeRetry(wire.retry) ?? { kind: 'inProgress' } },
|
|
164
|
+
features: permission,
|
|
165
|
+
};
|
|
166
|
+
case 'error':
|
|
167
|
+
return { part: { kind: 'error', error: decodeError(wire.error) }, features: permission };
|
|
168
|
+
default:
|
|
169
|
+
throw new TypeError('defaultView');
|
|
170
|
+
}
|
|
66
171
|
}
|
|
67
172
|
|
|
68
|
-
function
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
173
|
+
function cellAccessibility(value: unknown): CellAccessibility | null {
|
|
174
|
+
if (!record(value)) return null;
|
|
175
|
+
const actions = Array.isArray(value.actions) ? value.actions.filter(record) : [];
|
|
176
|
+
return {
|
|
177
|
+
label: string(value.label),
|
|
178
|
+
value: string(value.value),
|
|
179
|
+
isButton: value.isButton === true,
|
|
180
|
+
isSelected: value.isSelected === true,
|
|
181
|
+
// iOS sends `null` and Android leaves the key out where a double tap does nothing.
|
|
182
|
+
activation: actionKind(value.activation),
|
|
183
|
+
actions: actions.flatMap(action => {
|
|
184
|
+
const kind = actionKind(action.kind);
|
|
185
|
+
return kind === null || typeof action.name !== 'string' ? [] : [{ kind, name: action.name }];
|
|
186
|
+
}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
73
189
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
190
|
+
/** The status line; `null` and a missing key both mean none. */
|
|
191
|
+
function cellStatus(value: unknown): CellStatus | null {
|
|
192
|
+
if (!record(value) || typeof value.text !== 'string') return null;
|
|
193
|
+
return { text: value.text, showsAiIcon: value.showsAiIcon === true };
|
|
194
|
+
}
|
|
77
195
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
196
|
+
/** The mute mark; `null` and a missing key both mean none. */
|
|
197
|
+
function cellMuteMark(value: unknown): CellMuteMark | null {
|
|
198
|
+
return value === 'microphone' || value === 'camera' ? value : null;
|
|
199
|
+
}
|
|
81
200
|
|
|
201
|
+
function actionKind(value: unknown): CellActionKind | null {
|
|
202
|
+
return value === 'toggleAudio' || value === 'toggleSubtitles' ? value : null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function features(value: unknown): LiveVoiceFeatures | null {
|
|
206
|
+
if (!record(value)) return null;
|
|
207
|
+
return { customUiAllowed: value.customUiAllowed === true, hideBranding: value.hideBranding === true };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function brandColors(value: unknown): BrandColors | null {
|
|
211
|
+
if (!record(value) || typeof value.light !== 'string' || typeof value.dark !== 'string') return null;
|
|
212
|
+
return { light: value.light, dark: value.dark };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** A wire channel (bridge.md 2.2) as the public `LiveVoiceChannel`. */
|
|
216
|
+
export function decodeChannel(wire: Record<string, unknown>): LiveVoiceChannel {
|
|
217
|
+
const translation = record(wire.aiTranslationInfo) ? wire.aiTranslationInfo : null;
|
|
218
|
+
const aiTranslationInfo: LiveVoiceAiTranslationInfo | null = translation === null ? null : {
|
|
219
|
+
sourceChannelId: number(translation.sourceChannelId),
|
|
220
|
+
targetLanguage: string(translation.targetLanguage),
|
|
221
|
+
};
|
|
222
|
+
const dependents = Array.isArray(wire.dependentChannels) ? wire.dependentChannels.filter(record) : [];
|
|
82
223
|
return {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
224
|
+
id: number(wire.id),
|
|
225
|
+
name: string(wire.name),
|
|
226
|
+
isOnline: wire.isOnline === true,
|
|
227
|
+
hasAudio: wire.hasAudio === true,
|
|
228
|
+
// Older native SDKs do not send it.
|
|
229
|
+
hasVideo: wire.hasVideo === true,
|
|
230
|
+
hasSubtitles: wire.hasSubtitles === true,
|
|
231
|
+
isAudioMuted: wire.isAudioMuted === true,
|
|
232
|
+
isPasswordProtected: wire.isPasswordProtected === true,
|
|
233
|
+
isAiSpeaker: wire.isAiSpeaker === true,
|
|
234
|
+
isOnDemand: wire.isOnDemand === true,
|
|
235
|
+
aiTranslationInfo,
|
|
236
|
+
dependentChannels: dependents.map((dependent): LiveVoiceDependentChannel => ({
|
|
237
|
+
id: number(dependent.id),
|
|
238
|
+
name: string(dependent.name),
|
|
239
|
+
sourceChannelId: number(dependent.sourceChannelId),
|
|
240
|
+
// The transcript has no language; an empty one from an older native SDK means the same.
|
|
241
|
+
language: typeof dependent.language === 'string' && dependent.language !== '' ? dependent.language : null,
|
|
242
|
+
hasAudio: dependent.hasAudio === true,
|
|
243
|
+
hasSubtitles: dependent.hasSubtitles === true,
|
|
244
|
+
})),
|
|
245
|
+
playingState: playingState(wire.playingState),
|
|
88
246
|
};
|
|
89
247
|
}
|
|
248
|
+
|
|
249
|
+
function playingState(value: unknown): LiveVoicePlayingState {
|
|
250
|
+
return value === 'playing' || value === 'transitioning' ? value : 'stopped';
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function number(value: unknown): number {
|
|
254
|
+
return typeof value === 'number' ? value : -1;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function string(value: unknown): string {
|
|
258
|
+
return typeof value === 'string' ? value : '';
|
|
259
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
14
|
+
import Native from '../specs/NativeLiveVoiceSdk';
|
|
15
|
+
import { logListenerError } from '../util/logger';
|
|
16
|
+
import { type LiveVoiceSubscription } from './Models';
|
|
17
|
+
|
|
18
|
+
/** `error` for a failed result and a failed connection, `info` for everything else. */
|
|
19
|
+
export type LiveVoiceLogLevel = 'info' | 'error';
|
|
20
|
+
|
|
21
|
+
/** One diagnostic event of the LiveVoice SDK. */
|
|
22
|
+
export type LiveVoiceLogEntry = {
|
|
23
|
+
/** The event's name, `LV_…`. */
|
|
24
|
+
event: string;
|
|
25
|
+
level: LiveVoiceLogLevel;
|
|
26
|
+
/** The event's details. A field without a value is left out. */
|
|
27
|
+
fields: Record<string, string>;
|
|
28
|
+
/** When it happened. */
|
|
29
|
+
timestamp: Date;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** Receives one log entry; see {@link addLogListener}. */
|
|
33
|
+
export type LiveVoiceLogListener = (entry: LiveVoiceLogEntry) => void;
|
|
34
|
+
|
|
35
|
+
/** The entry of a native event, or `undefined` for anything that is not one. */
|
|
36
|
+
function decode(data: unknown): LiveVoiceLogEntry | undefined {
|
|
37
|
+
if (typeof data !== 'string') return undefined;
|
|
38
|
+
let wire: unknown;
|
|
39
|
+
try { wire = JSON.parse(data); }
|
|
40
|
+
catch { return undefined; }
|
|
41
|
+
if (!record(wire)) return undefined;
|
|
42
|
+
const { event, level, fields, timestamp } = wire;
|
|
43
|
+
if (typeof event !== 'string' || event.length === 0) return undefined;
|
|
44
|
+
if (level !== 'info' && level !== 'error') return undefined;
|
|
45
|
+
if (typeof timestamp !== 'number' || !Number.isFinite(timestamp)) return undefined;
|
|
46
|
+
if (!record(fields)) return undefined;
|
|
47
|
+
const entries = Object.entries(fields);
|
|
48
|
+
if (!entries.every(([, value]) => typeof value === 'string')) return undefined;
|
|
49
|
+
return { event, level, fields: Object.fromEntries(entries) as Record<string, string>, timestamp: new Date(timestamp) };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function record(value: unknown): value is Record<string, unknown> {
|
|
53
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Receives the SDK's diagnostic events, the ones it also writes to the system log. Entries are
|
|
58
|
+
* not replayed: a listener gets what is logged after it was added, in order. It can be added
|
|
59
|
+
* before `initialize()` and stays until it is removed.
|
|
60
|
+
*
|
|
61
|
+
* Entries never hold the API key or a password. Return quickly and do not call the SDK from the
|
|
62
|
+
* listener; an error it throws is caught.
|
|
63
|
+
*
|
|
64
|
+
* @param listener - Called with each entry.
|
|
65
|
+
* @returns A subscription; its `remove()` stops the entries.
|
|
66
|
+
*/
|
|
67
|
+
export function addLogListener(listener: LiveVoiceLogListener): LiveVoiceSubscription {
|
|
68
|
+
let active = true;
|
|
69
|
+
let subscription: { remove(): void } | undefined;
|
|
70
|
+
const receive = (data: string) => {
|
|
71
|
+
if (!active) return; // A delivery already on its way when the listener was removed.
|
|
72
|
+
const entry = decode(data);
|
|
73
|
+
if (entry === undefined) return;
|
|
74
|
+
try { listener(entry); }
|
|
75
|
+
// Not logged into the stream, which would reach this listener again.
|
|
76
|
+
catch (error) { logListenerError('LV_LOG_LISTENER_ERROR', error); }
|
|
77
|
+
};
|
|
78
|
+
try { subscription = Native.onLogEntry(receive); }
|
|
79
|
+
catch (error) { logListenerError('LV_LOG_LISTENER_UNAVAILABLE', error); }
|
|
80
|
+
return {
|
|
81
|
+
remove: () => {
|
|
82
|
+
if (!active) return;
|
|
83
|
+
active = false;
|
|
84
|
+
try { subscription?.remove(); }
|
|
85
|
+
catch { /* The native emitter is already gone. */ }
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
14
|
+
// The public value types. They are plain data, so hosts can write them as object literals for
|
|
15
|
+
// tests and previews; the SDK never needs a value a host built.
|
|
16
|
+
|
|
17
|
+
/** A channel of the joined event. */
|
|
18
|
+
export type LiveVoiceChannel = {
|
|
19
|
+
/** The channel's id, shown in the admin web interface at the bottom of *Edit Channel*. */
|
|
20
|
+
id: number;
|
|
21
|
+
/** The channel's name, as listeners see it. */
|
|
22
|
+
name: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether a speaker is live on the channel. Playback of an offline channel cannot be started
|
|
25
|
+
* (`channel_offline`); its subtitles can.
|
|
26
|
+
*/
|
|
27
|
+
isOnline: boolean;
|
|
28
|
+
/** Whether the channel carries audio. */
|
|
29
|
+
hasAudio: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether the channel carries video. The SDK plays no video: a channel with video and audio
|
|
32
|
+
* plays its audio, and one with only video cannot be played, though its subtitles still open.
|
|
33
|
+
*/
|
|
34
|
+
hasVideo: boolean;
|
|
35
|
+
/** Whether subtitles can be started for the channel. */
|
|
36
|
+
hasSubtitles: boolean;
|
|
37
|
+
/** Whether a speaker has muted the channel's audio. */
|
|
38
|
+
isAudioMuted: boolean;
|
|
39
|
+
/** Whether listening to the channel needs a password. */
|
|
40
|
+
isPasswordProtected: boolean;
|
|
41
|
+
/** Whether an AI voice speaks on the channel. */
|
|
42
|
+
isAiSpeaker: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Whether the event added this AI translation channel because its language was requested. It is
|
|
45
|
+
* not recorded playback.
|
|
46
|
+
*/
|
|
47
|
+
isOnDemand: boolean;
|
|
48
|
+
/** Set when the channel is an AI translation of another channel. */
|
|
49
|
+
aiTranslationInfo: LiveVoiceAiTranslationInfo | null;
|
|
50
|
+
/** The AI translation channels of this channel: each has audio, subtitles or both. */
|
|
51
|
+
dependentChannels: LiveVoiceDependentChannel[];
|
|
52
|
+
/** The channel's local playback on this device. */
|
|
53
|
+
playingState: LiveVoicePlayingState;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A channel's local playback; `transitioning` while a start or stop is under way. `playing` means
|
|
58
|
+
* local playback is confirmed.
|
|
59
|
+
*/
|
|
60
|
+
export type LiveVoicePlayingState = 'stopped' | 'transitioning' | 'playing';
|
|
61
|
+
|
|
62
|
+
/** The channel an AI translation translates, and the language it translates into. */
|
|
63
|
+
export type LiveVoiceAiTranslationInfo = {
|
|
64
|
+
sourceChannelId: number;
|
|
65
|
+
targetLanguage: string;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** An AI translation channel of a source channel, with audio, subtitles or both. */
|
|
69
|
+
export type LiveVoiceDependentChannel = {
|
|
70
|
+
id: number;
|
|
71
|
+
name: string;
|
|
72
|
+
sourceChannelId: number;
|
|
73
|
+
/** The channel's language; for a translation, the language it translates into. */
|
|
74
|
+
language: string | null;
|
|
75
|
+
hasAudio: boolean;
|
|
76
|
+
hasSubtitles: boolean;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Which subtitles the SDK receives, with the fragments received so far:
|
|
81
|
+
* - `disabled`: none. The state after a join, a leave and `stopSubtitles`.
|
|
82
|
+
* - `automatic`: those of the playing channel, following whichever channel plays. It stays on
|
|
83
|
+
* while nothing plays and when a channel's subtitles are refused.
|
|
84
|
+
* - `specific`: those of the channel `channelId`. It is restored after a reconnect; if the
|
|
85
|
+
* server then refuses it, the state becomes `disabled`.
|
|
86
|
+
*
|
|
87
|
+
* The observed value follows a call shortly, also an awaited `joinEvent`: right after the promise
|
|
88
|
+
* resolves it can still show the previous value, so observe it.
|
|
89
|
+
*/
|
|
90
|
+
export type LiveVoiceSubtitleState =
|
|
91
|
+
| { kind: 'disabled' }
|
|
92
|
+
| { kind: 'automatic'; fragments: string[] }
|
|
93
|
+
| { kind: 'specific'; channelId: number; fragments: string[] };
|
|
94
|
+
|
|
95
|
+
/** Subtitles that can be started for the joined event. */
|
|
96
|
+
export type LiveVoiceAvailableSubtitle = {
|
|
97
|
+
channelId: number;
|
|
98
|
+
name: string;
|
|
99
|
+
/** `null` for a transcript. */
|
|
100
|
+
language: string | null;
|
|
101
|
+
/** The channel these subtitles belong to, `null` for a transcript. */
|
|
102
|
+
parentChannelId: number | null;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Where LiveVoice plays its audio: a preference, not a claim about the route the device uses.
|
|
107
|
+
* `system` is the route the system chooses (connected headphones, a Bluetooth device, or the
|
|
108
|
+
* phone's receiver); `speaker` is the phone's loudspeaker.
|
|
109
|
+
*/
|
|
110
|
+
export type LiveVoiceAudioOutput = 'system' | 'speaker';
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* What the API key of the joined event permits. Both stay unchanged through reconnects and are
|
|
114
|
+
* `false` after a leave and after a failure. They are not among the values an awaited `joinEvent`
|
|
115
|
+
* waits for: right after it resolves they can still show the previous value, so observe them with
|
|
116
|
+
* `addFeaturesListener` or `useLiveVoiceFeatures`.
|
|
117
|
+
*/
|
|
118
|
+
export type LiveVoiceFeatures = {
|
|
119
|
+
/**
|
|
120
|
+
* Whether custom parts of `LiveVoiceView`, `switchToLinkedEvent` and the language calls are
|
|
121
|
+
* allowed. Without it, linked events and requestable languages are `null`.
|
|
122
|
+
*/
|
|
123
|
+
customUiAllowed: boolean;
|
|
124
|
+
/** Whether the "Live Audio Streaming by LiveVoice" line is hidden. */
|
|
125
|
+
hideBranding: boolean;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Ends an observation. Calling `remove()` again does nothing. */
|
|
129
|
+
export type LiveVoiceSubscription = { remove(): void };
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
//
|
|
12
12
|
//===----------------------------------------------------------------------===//
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
TRANSITIONING = 'TRANSITIONING',
|
|
17
|
-
PLAYING = 'PLAYING'
|
|
18
|
-
};
|
|
14
|
+
// GENERATED CODE - DO NOT MODIFY BY HAND.
|
|
15
|
+
// Generated by tool/generate-native-versions.mjs from the native SDK pins.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
/** The native SDK versions this wrapper pins exactly, per platform. */
|
|
18
|
+
export const nativeSdkVersions = {
|
|
19
|
+
ios: '3.0.0',
|
|
20
|
+
android: '3.0.0',
|
|
21
|
+
} as const;
|