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.
Files changed (207) hide show
  1. package/README.md +105 -66
  2. package/android/build.gradle +5 -4
  3. package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +122 -188
  4. package/android/src/main/java/io/livevoice/react/__SDK.kt +2 -2
  5. package/ios/LiveVoiceRNBridge.swift +362 -0
  6. package/ios/LiveVoiceSdkReactNative.mm +187 -158
  7. package/ios/__SDK.h +1 -1
  8. package/ios/livevoice_spm_backport.rb +202 -0
  9. package/lib/module/components/BrandingView.js +58 -39
  10. package/lib/module/components/BrandingView.js.map +1 -1
  11. package/lib/module/components/ChannelView.js +355 -44
  12. package/lib/module/components/ChannelView.js.map +1 -1
  13. package/lib/module/components/ErrorView.js +5 -6
  14. package/lib/module/components/ErrorView.js.map +1 -1
  15. package/lib/module/components/LiveVoiceSpinner.js +81 -0
  16. package/lib/module/components/LiveVoiceSpinner.js.map +1 -0
  17. package/lib/module/components/LiveVoiceView.js +311 -133
  18. package/lib/module/components/LiveVoiceView.js.map +1 -1
  19. package/lib/module/components/PasswordPrompt.js +165 -0
  20. package/lib/module/components/PasswordPrompt.js.map +1 -0
  21. package/lib/module/components/PlayButtonView.js +180 -244
  22. package/lib/module/components/PlayButtonView.js.map +1 -1
  23. package/lib/module/components/ReconnectingView.js +31 -53
  24. package/lib/module/components/ReconnectingView.js.map +1 -1
  25. package/lib/module/icons/branding-ios.png +0 -0
  26. package/lib/module/icons/camera-off-android.png +0 -0
  27. package/lib/module/icons/camera-off-android@2x.png +0 -0
  28. package/lib/module/icons/camera-off-android@3x.png +0 -0
  29. package/lib/module/icons/cpu-android.png +0 -0
  30. package/lib/module/icons/cpu-android@2x.png +0 -0
  31. package/lib/module/icons/cpu-android@3x.png +0 -0
  32. package/lib/module/icons/cpu-ios.png +0 -0
  33. package/lib/module/icons/cpu-ios@2x.png +0 -0
  34. package/lib/module/icons/cpu-ios@3x.png +0 -0
  35. package/lib/module/icons/lock-android.png +0 -0
  36. package/lib/module/icons/lock-android@2x.png +0 -0
  37. package/lib/module/icons/lock-android@3x.png +0 -0
  38. package/lib/module/icons/lock-ios.png +0 -0
  39. package/lib/module/icons/lock-ios@2x.png +0 -0
  40. package/lib/module/icons/lock-ios@3x.png +0 -0
  41. package/lib/module/icons/mic-off-android.png +0 -0
  42. package/lib/module/icons/mic-off-android@2x.png +0 -0
  43. package/lib/module/icons/mic-off-android@3x.png +0 -0
  44. package/lib/module/icons/mic-slash-ios.png +0 -0
  45. package/lib/module/icons/mic-slash-ios@2x.png +0 -0
  46. package/lib/module/icons/mic-slash-ios@3x.png +0 -0
  47. package/lib/module/icons/video-slash-ios.png +0 -0
  48. package/lib/module/icons/video-slash-ios@2x.png +0 -0
  49. package/lib/module/icons/video-slash-ios@3x.png +0 -0
  50. package/lib/module/index.js +11 -6
  51. package/lib/module/index.js.map +1 -1
  52. package/lib/module/sdk/Bridge.js +236 -0
  53. package/lib/module/sdk/Bridge.js.map +1 -0
  54. package/lib/module/sdk/Event.js +160 -0
  55. package/lib/module/sdk/Event.js.map +1 -0
  56. package/lib/module/sdk/Lifecycle.js +331 -0
  57. package/lib/module/sdk/Lifecycle.js.map +1 -0
  58. package/lib/module/sdk/LiveVoiceSdk.js +262 -268
  59. package/lib/module/sdk/LiveVoiceSdk.js.map +1 -1
  60. package/lib/module/sdk/LiveVoiceState.js +208 -40
  61. package/lib/module/sdk/LiveVoiceState.js.map +1 -1
  62. package/lib/module/sdk/LogEntries.js +99 -0
  63. package/lib/module/sdk/LogEntries.js.map +1 -0
  64. package/lib/module/sdk/Models.js +2 -0
  65. package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
  66. package/lib/module/{util/PlayingState.js → sdk/NativeSdkVersions.js} +9 -8
  67. package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
  68. package/lib/module/sdk/Observables.js +391 -0
  69. package/lib/module/sdk/Observables.js.map +1 -0
  70. package/lib/module/sdk/Passwords.js +298 -0
  71. package/lib/module/sdk/Passwords.js.map +1 -0
  72. package/lib/module/sdk/Playback.js +35 -0
  73. package/lib/module/sdk/Playback.js.map +1 -0
  74. package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
  75. package/lib/module/util/Colors.js +2 -1
  76. package/lib/module/util/Colors.js.map +1 -1
  77. package/lib/module/util/Translations.js +34 -11
  78. package/lib/module/util/Translations.js.map +1 -1
  79. package/lib/module/util/freeze.js +26 -0
  80. package/lib/module/util/freeze.js.map +1 -0
  81. package/lib/module/util/logger.js +79 -41
  82. package/lib/module/util/logger.js.map +1 -1
  83. package/lib/typescript/src/components/BrandingView.d.ts +4 -0
  84. package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
  85. package/lib/typescript/src/components/ChannelView.d.ts +29 -3
  86. package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
  87. package/lib/typescript/src/components/ErrorView.d.ts +5 -3
  88. package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
  89. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
  90. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
  91. package/lib/typescript/src/components/LiveVoiceView.d.ts +81 -21
  92. package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
  93. package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
  94. package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
  95. package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
  96. package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
  97. package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
  98. package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
  99. package/lib/typescript/src/index.d.ts +15 -6
  100. package/lib/typescript/src/index.d.ts.map +1 -1
  101. package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
  102. package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
  103. package/lib/typescript/src/sdk/Event.d.ts +97 -0
  104. package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
  105. package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
  106. package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +195 -190
  108. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -1
  109. package/lib/typescript/src/sdk/LiveVoiceState.d.ts +77 -9
  110. package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -1
  111. package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
  112. package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
  113. package/lib/typescript/src/sdk/Models.d.ts +114 -0
  114. package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
  115. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
  116. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
  117. package/lib/typescript/src/sdk/Observables.d.ts +123 -0
  118. package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
  119. package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
  120. package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
  121. package/lib/typescript/src/sdk/Playback.d.ts +9 -0
  122. package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +34 -31
  124. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
  125. package/lib/typescript/src/util/Colors.d.ts.map +1 -1
  126. package/lib/typescript/src/util/Translations.d.ts +30 -8
  127. package/lib/typescript/src/util/Translations.d.ts.map +1 -1
  128. package/lib/typescript/src/util/freeze.d.ts +6 -0
  129. package/lib/typescript/src/util/freeze.d.ts.map +1 -0
  130. package/lib/typescript/src/util/logger.d.ts +17 -7
  131. package/lib/typescript/src/util/logger.d.ts.map +1 -1
  132. package/livevoice-sdk-react-native.podspec +29 -4
  133. package/package.json +12 -9
  134. package/src/components/BrandingView.tsx +42 -55
  135. package/src/components/ChannelView.tsx +329 -38
  136. package/src/components/ErrorView.tsx +9 -12
  137. package/src/components/LiveVoiceSpinner.tsx +87 -0
  138. package/src/components/LiveVoiceView.tsx +319 -201
  139. package/src/components/PasswordPrompt.tsx +144 -0
  140. package/src/components/PlayButtonView.tsx +165 -269
  141. package/src/components/ReconnectingView.tsx +28 -81
  142. package/src/icons/branding-ios.png +0 -0
  143. package/src/icons/camera-off-android.png +0 -0
  144. package/src/icons/camera-off-android@2x.png +0 -0
  145. package/src/icons/camera-off-android@3x.png +0 -0
  146. package/src/icons/cpu-android.png +0 -0
  147. package/src/icons/cpu-android@2x.png +0 -0
  148. package/src/icons/cpu-android@3x.png +0 -0
  149. package/src/icons/cpu-ios.png +0 -0
  150. package/src/icons/cpu-ios@2x.png +0 -0
  151. package/src/icons/cpu-ios@3x.png +0 -0
  152. package/src/icons/lock-android.png +0 -0
  153. package/src/icons/lock-android@2x.png +0 -0
  154. package/src/icons/lock-android@3x.png +0 -0
  155. package/src/icons/lock-ios.png +0 -0
  156. package/src/icons/lock-ios@2x.png +0 -0
  157. package/src/icons/lock-ios@3x.png +0 -0
  158. package/src/icons/mic-off-android.png +0 -0
  159. package/src/icons/mic-off-android@2x.png +0 -0
  160. package/src/icons/mic-off-android@3x.png +0 -0
  161. package/src/icons/mic-slash-ios.png +0 -0
  162. package/src/icons/mic-slash-ios@2x.png +0 -0
  163. package/src/icons/mic-slash-ios@3x.png +0 -0
  164. package/src/icons/video-slash-ios.png +0 -0
  165. package/src/icons/video-slash-ios@2x.png +0 -0
  166. package/src/icons/video-slash-ios@3x.png +0 -0
  167. package/src/index.tsx +92 -6
  168. package/src/sdk/Bridge.ts +259 -0
  169. package/src/sdk/Event.ts +187 -0
  170. package/src/sdk/Lifecycle.ts +366 -0
  171. package/src/sdk/LiveVoiceSdk.ts +285 -309
  172. package/src/sdk/LiveVoiceState.ts +230 -60
  173. package/src/sdk/LogEntries.ts +88 -0
  174. package/src/sdk/Models.ts +129 -0
  175. package/src/{util/PlayingState.ts → sdk/NativeSdkVersions.ts} +7 -6
  176. package/src/sdk/Observables.ts +414 -0
  177. package/src/sdk/Passwords.ts +286 -0
  178. package/src/sdk/Playback.ts +30 -0
  179. package/src/specs/NativeLiveVoiceSdk.ts +42 -38
  180. package/src/util/Colors.ts +2 -1
  181. package/src/util/Translations.ts +34 -12
  182. package/src/util/freeze.ts +23 -0
  183. package/src/util/logger.ts +79 -52
  184. package/lib/module/components/AudioOutputSwitchView.js +0 -138
  185. package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
  186. package/lib/module/components/index.js +0 -24
  187. package/lib/module/components/index.js.map +0 -1
  188. package/lib/module/icons/mic.png +0 -0
  189. package/lib/module/util/ForegroundServiceConfig.js +0 -38
  190. package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
  191. package/lib/module/util/PlayingState.js.map +0 -1
  192. package/lib/module/util/UIState.js +0 -4
  193. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
  194. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
  195. package/lib/typescript/src/components/index.d.ts +0 -9
  196. package/lib/typescript/src/components/index.d.ts.map +0 -1
  197. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -19
  198. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
  199. package/lib/typescript/src/util/PlayingState.d.ts +0 -7
  200. package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
  201. package/lib/typescript/src/util/UIState.d.ts +0 -86
  202. package/lib/typescript/src/util/UIState.d.ts.map +0 -1
  203. package/src/components/AudioOutputSwitchView.tsx +0 -146
  204. package/src/components/index.tsx +0 -21
  205. package/src/icons/mic.png +0 -0
  206. package/src/util/ForegroundServiceConfig.tsx +0 -42
  207. package/src/util/UIState.ts +0 -106
@@ -11,79 +11,249 @@
11
11
  //
12
12
  //===----------------------------------------------------------------------===//
13
13
 
14
- // Internal state accessors used by LiveVoiceView. These are intentionally NOT re-exported from
15
- // the package entry point (`src/index.tsx`); the public, app-facing way to consume state is the
16
- // `renderChannel` prop on `LiveVoiceView`. The deprecated public wrappers in `LiveVoiceSdk.ts`
17
- // delegate here, which keeps the SDK's own usage free of deprecation warnings.
18
-
19
- import LiveVoiceSdkReactNative from '../specs/NativeLiveVoiceSdk';
20
- import { type UiState, type Channel } from '../util/UIState';
21
- import { logUiState } from '../util/logger';
22
-
23
- /** Authorization features for the joined event. Internal: the view uses it for branding/gating. */
24
- export type Claims = { hideBranding: boolean; customUiAllowed: boolean };
25
-
26
- type UiStateWire = {
27
- type: 'loading';
28
- } | {
29
- type: 'ready';
30
- channels: Channel[];
31
- isHeadphonesOnly: boolean;
32
- outputMode: string;
33
- } | {
34
- type: 'error';
35
- message: string;
36
- canBeRetried: boolean;
37
- } | {
38
- type: 'reconnecting';
39
- state:
40
- | { type: 'inProgress' }
41
- | { type: 'awaitingRetry'; atTimestamp: number };
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
- export function getCurrentClaims(): Claims | null {
45
- const claims = LiveVoiceSdkReactNative.getCurrentClaims();
46
- if (claims == null) return null;
47
- return JSON.parse(claims);
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
- export function getCurrentUiState(): UiState {
51
- return parseUiState(LiveVoiceSdkReactNative.getCurrentUiState());
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
- export function onUiStateChanged(handler: (arg: UiState) => void): {
55
- remove: () => void;
56
- } {
57
- return LiveVoiceSdkReactNative.onUiStateChanged((data: string) => {
58
- const state = parseUiState(data);
59
- logUiState(state);
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
- function parseUiState(data: string): UiState {
65
- return hydrateUiState(JSON.parse(data) as UiStateWire);
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 hydrateUiState(state: UiStateWire): UiState {
69
- if (state.type === 'ready') {
70
- const { isHeadphonesOnly: _ignored, ...publicState } = state;
71
- return publicState;
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
- if (state.type !== 'reconnecting') {
75
- return state as UiState;
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
- if (state.state.type !== 'awaitingRetry') {
79
- return state as UiState;
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
- ...state,
84
- state: {
85
- ...state.state,
86
- retryAt: new Date(state.state.atTimestamp * 1000),
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
- export enum PlayingState {
15
- STOPPED = 'STOPPED',
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
- export type OutputMode = 'HEADPHONES' | 'SPEAKER';
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;