livevoice-sdk-react-native 2.0.0 → 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 (221) hide show
  1. package/README.md +158 -7
  2. package/android/build.gradle +18 -6
  3. package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +121 -221
  4. package/android/src/main/java/io/livevoice/react/__SDK.kt +17 -3
  5. package/ios/LiveVoiceRNBridge.swift +362 -0
  6. package/ios/LiveVoiceSdkReactNative.mm +247 -145
  7. package/ios/__SDK.h +16 -2
  8. package/ios/livevoice_spm_backport.rb +202 -0
  9. package/lib/module/components/BrandingView.js +71 -50
  10. package/lib/module/components/BrandingView.js.map +1 -1
  11. package/lib/module/components/ChannelView.js +368 -54
  12. package/lib/module/components/ChannelView.js.map +1 -1
  13. package/lib/module/components/ErrorView.js +17 -16
  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 +351 -104
  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 +192 -254
  22. package/lib/module/components/PlayButtonView.js.map +1 -1
  23. package/lib/module/components/ReconnectingView.js +43 -62
  24. package/lib/module/components/ReconnectingView.js.map +1 -1
  25. package/lib/module/components/WarningView.js +12 -10
  26. package/lib/module/components/WarningView.js.map +1 -1
  27. package/lib/module/icons/branding-ios.png +0 -0
  28. package/lib/module/icons/camera-off-android.png +0 -0
  29. package/lib/module/icons/camera-off-android@2x.png +0 -0
  30. package/lib/module/icons/camera-off-android@3x.png +0 -0
  31. package/lib/module/icons/cpu-android.png +0 -0
  32. package/lib/module/icons/cpu-android@2x.png +0 -0
  33. package/lib/module/icons/cpu-android@3x.png +0 -0
  34. package/lib/module/icons/cpu-ios.png +0 -0
  35. package/lib/module/icons/cpu-ios@2x.png +0 -0
  36. package/lib/module/icons/cpu-ios@3x.png +0 -0
  37. package/lib/module/icons/lock-android.png +0 -0
  38. package/lib/module/icons/lock-android@2x.png +0 -0
  39. package/lib/module/icons/lock-android@3x.png +0 -0
  40. package/lib/module/icons/lock-ios.png +0 -0
  41. package/lib/module/icons/lock-ios@2x.png +0 -0
  42. package/lib/module/icons/lock-ios@3x.png +0 -0
  43. package/lib/module/icons/mic-off-android.png +0 -0
  44. package/lib/module/icons/mic-off-android@2x.png +0 -0
  45. package/lib/module/icons/mic-off-android@3x.png +0 -0
  46. package/lib/module/icons/mic-slash-ios.png +0 -0
  47. package/lib/module/icons/mic-slash-ios@2x.png +0 -0
  48. package/lib/module/icons/mic-slash-ios@3x.png +0 -0
  49. package/lib/module/icons/video-slash-ios.png +0 -0
  50. package/lib/module/icons/video-slash-ios@2x.png +0 -0
  51. package/lib/module/icons/video-slash-ios@3x.png +0 -0
  52. package/lib/module/index.js +24 -225
  53. package/lib/module/index.js.map +1 -1
  54. package/lib/module/sdk/Bridge.js +236 -0
  55. package/lib/module/sdk/Bridge.js.map +1 -0
  56. package/lib/module/sdk/Event.js +160 -0
  57. package/lib/module/sdk/Event.js.map +1 -0
  58. package/lib/module/sdk/Lifecycle.js +331 -0
  59. package/lib/module/sdk/Lifecycle.js.map +1 -0
  60. package/lib/module/sdk/LiveVoiceSdk.js +365 -0
  61. package/lib/module/sdk/LiveVoiceSdk.js.map +1 -0
  62. package/lib/module/sdk/LiveVoiceState.js +234 -0
  63. package/lib/module/sdk/LiveVoiceState.js.map +1 -0
  64. package/lib/module/sdk/LogEntries.js +99 -0
  65. package/lib/module/sdk/LogEntries.js.map +1 -0
  66. package/lib/module/sdk/Models.js +2 -0
  67. package/lib/module/{util/UIState.js.map → sdk/Models.js.map} +1 -1
  68. package/lib/module/sdk/NativeSdkVersions.js +24 -0
  69. package/lib/module/sdk/NativeSdkVersions.js.map +1 -0
  70. package/lib/module/sdk/Observables.js +391 -0
  71. package/lib/module/sdk/Observables.js.map +1 -0
  72. package/lib/module/sdk/Passwords.js +298 -0
  73. package/lib/module/sdk/Passwords.js.map +1 -0
  74. package/lib/module/sdk/Playback.js +35 -0
  75. package/lib/module/sdk/Playback.js.map +1 -0
  76. package/lib/module/specs/NativeLiveVoiceSdk.js +12 -10
  77. package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
  78. package/lib/module/util/Colors.js +14 -11
  79. package/lib/module/util/Colors.js.map +1 -1
  80. package/lib/module/util/Translations.js +46 -21
  81. package/lib/module/util/Translations.js.map +1 -1
  82. package/lib/module/util/freeze.js +26 -0
  83. package/lib/module/util/freeze.js.map +1 -0
  84. package/lib/module/util/logger.js +114 -0
  85. package/lib/module/util/logger.js.map +1 -0
  86. package/lib/typescript/src/components/BrandingView.d.ts +4 -0
  87. package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
  88. package/lib/typescript/src/components/ChannelView.d.ts +29 -3
  89. package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
  90. package/lib/typescript/src/components/ErrorView.d.ts +5 -3
  91. package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
  92. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts +16 -0
  93. package/lib/typescript/src/components/LiveVoiceSpinner.d.ts.map +1 -0
  94. package/lib/typescript/src/components/LiveVoiceView.d.ts +85 -3
  95. package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
  96. package/lib/typescript/src/components/PasswordPrompt.d.ts +13 -0
  97. package/lib/typescript/src/components/PasswordPrompt.d.ts.map +1 -0
  98. package/lib/typescript/src/components/PlayButtonView.d.ts +12 -329
  99. package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
  100. package/lib/typescript/src/components/ReconnectingView.d.ts +6 -3
  101. package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
  102. package/lib/typescript/src/components/WarningView.d.ts.map +1 -1
  103. package/lib/typescript/src/index.d.ts +15 -144
  104. package/lib/typescript/src/index.d.ts.map +1 -1
  105. package/lib/typescript/src/sdk/Bridge.d.ts +36 -0
  106. package/lib/typescript/src/sdk/Bridge.d.ts.map +1 -0
  107. package/lib/typescript/src/sdk/Event.d.ts +97 -0
  108. package/lib/typescript/src/sdk/Event.d.ts.map +1 -0
  109. package/lib/typescript/src/sdk/Lifecycle.d.ts +191 -0
  110. package/lib/typescript/src/sdk/Lifecycle.d.ts.map +1 -0
  111. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +215 -0
  112. package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -0
  113. package/lib/typescript/src/sdk/LiveVoiceState.d.ts +80 -0
  114. package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -0
  115. package/lib/typescript/src/sdk/LogEntries.d.ts +28 -0
  116. package/lib/typescript/src/sdk/LogEntries.d.ts.map +1 -0
  117. package/lib/typescript/src/sdk/Models.d.ts +114 -0
  118. package/lib/typescript/src/sdk/Models.d.ts.map +1 -0
  119. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts +6 -0
  120. package/lib/typescript/src/sdk/NativeSdkVersions.d.ts.map +1 -0
  121. package/lib/typescript/src/sdk/Observables.d.ts +123 -0
  122. package/lib/typescript/src/sdk/Observables.d.ts.map +1 -0
  123. package/lib/typescript/src/sdk/Passwords.d.ts +72 -0
  124. package/lib/typescript/src/sdk/Passwords.d.ts.map +1 -0
  125. package/lib/typescript/src/sdk/Playback.d.ts +9 -0
  126. package/lib/typescript/src/sdk/Playback.d.ts.map +1 -0
  127. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +35 -29
  128. package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
  129. package/lib/typescript/src/util/Colors.d.ts.map +1 -1
  130. package/lib/typescript/src/util/Translations.d.ts +30 -8
  131. package/lib/typescript/src/util/Translations.d.ts.map +1 -1
  132. package/lib/typescript/src/util/freeze.d.ts +6 -0
  133. package/lib/typescript/src/util/freeze.d.ts.map +1 -0
  134. package/lib/typescript/src/util/logger.d.ts +33 -0
  135. package/lib/typescript/src/util/logger.d.ts.map +1 -0
  136. package/livevoice-sdk-react-native.podspec +41 -16
  137. package/package.json +26 -14
  138. package/src/components/BrandingView.tsx +55 -66
  139. package/src/components/ChannelView.tsx +342 -48
  140. package/src/components/ErrorView.tsx +21 -22
  141. package/src/components/LiveVoiceSpinner.tsx +87 -0
  142. package/src/components/LiveVoiceView.tsx +360 -151
  143. package/src/components/PasswordPrompt.tsx +144 -0
  144. package/src/components/PlayButtonView.tsx +177 -279
  145. package/src/components/ReconnectingView.tsx +40 -86
  146. package/src/components/WarningView.tsx +12 -10
  147. package/src/icons/branding-ios.png +0 -0
  148. package/src/icons/camera-off-android.png +0 -0
  149. package/src/icons/camera-off-android@2x.png +0 -0
  150. package/src/icons/camera-off-android@3x.png +0 -0
  151. package/src/icons/cpu-android.png +0 -0
  152. package/src/icons/cpu-android@2x.png +0 -0
  153. package/src/icons/cpu-android@3x.png +0 -0
  154. package/src/icons/cpu-ios.png +0 -0
  155. package/src/icons/cpu-ios@2x.png +0 -0
  156. package/src/icons/cpu-ios@3x.png +0 -0
  157. package/src/icons/lock-android.png +0 -0
  158. package/src/icons/lock-android@2x.png +0 -0
  159. package/src/icons/lock-android@3x.png +0 -0
  160. package/src/icons/lock-ios.png +0 -0
  161. package/src/icons/lock-ios@2x.png +0 -0
  162. package/src/icons/lock-ios@3x.png +0 -0
  163. package/src/icons/mic-off-android.png +0 -0
  164. package/src/icons/mic-off-android@2x.png +0 -0
  165. package/src/icons/mic-off-android@3x.png +0 -0
  166. package/src/icons/mic-slash-ios.png +0 -0
  167. package/src/icons/mic-slash-ios@2x.png +0 -0
  168. package/src/icons/mic-slash-ios@3x.png +0 -0
  169. package/src/icons/video-slash-ios.png +0 -0
  170. package/src/icons/video-slash-ios@2x.png +0 -0
  171. package/src/icons/video-slash-ios@3x.png +0 -0
  172. package/src/index.tsx +105 -252
  173. package/src/sdk/Bridge.ts +259 -0
  174. package/src/sdk/Event.ts +187 -0
  175. package/src/sdk/Lifecycle.ts +366 -0
  176. package/src/sdk/LiveVoiceSdk.ts +384 -0
  177. package/src/sdk/LiveVoiceState.ts +259 -0
  178. package/src/sdk/LogEntries.ts +88 -0
  179. package/src/sdk/Models.ts +129 -0
  180. package/src/sdk/NativeSdkVersions.ts +21 -0
  181. package/src/sdk/Observables.ts +414 -0
  182. package/src/sdk/Passwords.ts +286 -0
  183. package/src/sdk/Playback.ts +30 -0
  184. package/src/specs/NativeLiveVoiceSdk.ts +56 -46
  185. package/src/util/Colors.ts +14 -11
  186. package/src/util/Translations.ts +46 -22
  187. package/src/util/freeze.ts +23 -0
  188. package/src/util/logger.ts +119 -0
  189. package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeLiveVoiceSdkSpec.java +0 -186
  190. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -28
  191. package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec-generated.cpp +0 -235
  192. package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec.h +0 -31
  193. package/android/app/build/generated/source/codegen/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +0 -341
  194. package/android/src/main/java/io/livevoice/react/Mappings.kt +0 -85
  195. package/android/src/main/java/io/livevoice/react/NativeModels.kt +0 -79
  196. package/lib/module/components/AudioOutputSwitchView.js +0 -138
  197. package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
  198. package/lib/module/components/index.js +0 -22
  199. package/lib/module/components/index.js.map +0 -1
  200. package/lib/module/icons/mic.png +0 -0
  201. package/lib/module/util/ForegroundServiceConfig.js +0 -28
  202. package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
  203. package/lib/module/util/PlayingState.js +0 -21
  204. package/lib/module/util/PlayingState.js.map +0 -1
  205. package/lib/module/util/UIState.js +0 -4
  206. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts +0 -6
  207. package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +0 -1
  208. package/lib/typescript/src/components/index.d.ts +0 -9
  209. package/lib/typescript/src/components/index.d.ts.map +0 -1
  210. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +0 -12
  211. package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +0 -1
  212. package/lib/typescript/src/util/PlayingState.d.ts +0 -7
  213. package/lib/typescript/src/util/PlayingState.d.ts.map +0 -1
  214. package/lib/typescript/src/util/UIState.d.ts +0 -66
  215. package/lib/typescript/src/util/UIState.d.ts.map +0 -1
  216. package/src/components/AudioOutputSwitchView.tsx +0 -146
  217. package/src/components/index.tsx +0 -19
  218. package/src/icons/mic.png +0 -0
  219. package/src/util/ForegroundServiceConfig.tsx +0 -32
  220. package/src/util/PlayingState.ts +0 -18
  221. package/src/util/UIState.ts +0 -89
@@ -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 };
@@ -0,0 +1,21 @@
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
+ // GENERATED CODE - DO NOT MODIFY BY HAND.
15
+ // Generated by tool/generate-native-versions.mjs from the native SDK pins.
16
+
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;
@@ -0,0 +1,414 @@
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
+ // Every public state of the SDK as `getCurrent…()`, `add…Listener()` and `useLiveVoice…()`. Each
15
+ // has one store: hydrated from the snapshot the bridge's `initialize` returns, kept current by the
16
+ // one `onState` callback with its revisions (Bridge.ts), and changed only when the value changes.
17
+ // Values are frozen, nested objects and arrays too, and keep their identity until they change, as
18
+ // `useSyncExternalStore` requires. Before `initialize()` each store has its initial value.
19
+
20
+ import { useMemo, useSyncExternalStore } from 'react';
21
+
22
+ import { currentEncoded, decodeState, record, type StateName } from './Bridge';
23
+ import {
24
+ decodeEvent,
25
+ decodeLanguages,
26
+ decodeLinkedEvents,
27
+ type LiveVoiceEvent,
28
+ type LiveVoiceLinkedEvent,
29
+ type LiveVoiceRequestableLanguage,
30
+ } from './Event';
31
+ import {
32
+ decodeConnection,
33
+ publicConnection,
34
+ type ConnectionValue,
35
+ type LiveVoiceConnection,
36
+ } from './Lifecycle';
37
+ import {
38
+ type LiveVoiceAudioOutput,
39
+ type LiveVoiceAvailableSubtitle,
40
+ type LiveVoiceFeatures,
41
+ type LiveVoiceSubscription,
42
+ type LiveVoiceSubtitleState,
43
+ } from './Models';
44
+ import { deepFreeze } from '../util/freeze';
45
+ import { logDecodeError, logListenerError } from '../util/logger';
46
+
47
+ type Store<Value, Public> = {
48
+ /** The current value, in public form. */
49
+ get(): Public;
50
+ /** Calls `listener` with the current value at once, then once for every change. */
51
+ add(listener: (value: Public) => void): LiveVoiceSubscription;
52
+ /** The current value in a component, which re-renders on every change. */
53
+ use(): Public;
54
+ /** Sets the value as long as native has delivered none, as before `initialize()`. */
55
+ preset(value: Value): void;
56
+ };
57
+
58
+ /**
59
+ * A store of the state `name`, which is that state's decoder in the bridge. `decode` reads the
60
+ * wire's value and throws for one it cannot read, which is dropped: the last good value stays, the
61
+ * SDK log gets `LV_BRIDGE_DECODE_ERROR`, and the value satisfies no command's revisions.
62
+ * `publish` turns the cached value into the one hosts get; it creates the `Date`s, so every
63
+ * getter call and listener delivery gets its own, and a hook one per update.
64
+ */
65
+ function store<Value, Public = Value>(
66
+ name: StateName,
67
+ decode: (wire: unknown) => Value,
68
+ initial: Value,
69
+ publish: (value: Value) => Public = value => value as unknown as Public,
70
+ ): Store<Value, Public> {
71
+ let value = deepFreeze(initial);
72
+ /** The wire's JSON of the last value native delivered and this store applied. */
73
+ let applied: string | undefined;
74
+ const subscribers = new Set<() => void>();
75
+
76
+ const change = (next: Value) => {
77
+ value = deepFreeze(next);
78
+ for (const subscriber of [...subscribers]) {
79
+ try { subscriber(); }
80
+ catch (error) { logListenerError('LV_LISTENER_ERROR', error); }
81
+ }
82
+ };
83
+ /** Whether the store holds the wire's value, decoded, afterwards. */
84
+ const receive = (wire: unknown): boolean => {
85
+ // The bridge reports only changed values; after a dropped one, the last good one can return.
86
+ const encoded = currentEncoded(name) ?? JSON.stringify(wire ?? null);
87
+ if (encoded === applied) return true;
88
+ let next: Value;
89
+ try { next = decode(wire); }
90
+ catch {
91
+ logDecodeError('state', name);
92
+ return false;
93
+ }
94
+ // The first value from native may equal the initial one: nothing changed, nobody hears.
95
+ const unchanged = applied === undefined && JSON.stringify(next) === JSON.stringify(value);
96
+ applied = encoded;
97
+ if (!unchanged) change(next);
98
+ return true;
99
+ };
100
+ // Also decodes the value the bridge already holds.
101
+ decodeState(name, receive);
102
+
103
+ const subscribe = (onChange: () => void) => {
104
+ subscribers.add(onChange);
105
+ return () => { subscribers.delete(onChange); };
106
+ };
107
+ const snapshot = () => value;
108
+
109
+ return {
110
+ get: () => publish(value),
111
+ add(listener) {
112
+ let active = true;
113
+ const deliver = () => {
114
+ if (!active) return;
115
+ // A listener that throws reaches neither the other listeners nor the SDK.
116
+ try { listener(publish(value)); }
117
+ catch (error) { logListenerError('LV_LISTENER_ERROR', error); }
118
+ };
119
+ subscribers.add(deliver);
120
+ deliver();
121
+ return {
122
+ remove: () => {
123
+ if (!active) return;
124
+ active = false;
125
+ subscribers.delete(deliver);
126
+ },
127
+ };
128
+ },
129
+ use() {
130
+ const current = useSyncExternalStore(subscribe, snapshot, snapshot);
131
+ return useMemo(() => publish(current), [current]);
132
+ },
133
+ preset(next) {
134
+ if (applied !== undefined || JSON.stringify(next) === JSON.stringify(value)) return;
135
+ change(next);
136
+ },
137
+ };
138
+ }
139
+
140
+ // MARK: Decoders of bridge.md 2.5 to 2.8
141
+
142
+ function decodeFeatures(wire: unknown): LiveVoiceFeatures {
143
+ if (!record(wire) || typeof wire.customUiAllowed !== 'boolean' || typeof wire.hideBranding !== 'boolean') {
144
+ throw new TypeError('features');
145
+ }
146
+ return { customUiAllowed: wire.customUiAllowed, hideBranding: wire.hideBranding };
147
+ }
148
+
149
+ function decodeAudioOutput(wire: unknown): LiveVoiceAudioOutput {
150
+ if (wire !== 'system' && wire !== 'speaker') throw new TypeError('audioOutput');
151
+ return wire;
152
+ }
153
+
154
+ function fragments(wire: Record<string, unknown>): string[] {
155
+ if (!Array.isArray(wire.fragments)) throw new TypeError('subtitles');
156
+ return wire.fragments.filter((fragment): fragment is string => typeof fragment === 'string');
157
+ }
158
+
159
+ function decodeSubtitles(wire: unknown): LiveVoiceSubtitleState {
160
+ if (!record(wire)) throw new TypeError('subtitles');
161
+ switch (wire.kind) {
162
+ case 'disabled':
163
+ return { kind: 'disabled' };
164
+ case 'automatic':
165
+ return { kind: 'automatic', fragments: fragments(wire) };
166
+ case 'specific':
167
+ if (typeof wire.channelId !== 'number') throw new TypeError('subtitles');
168
+ return { kind: 'specific', channelId: wire.channelId, fragments: fragments(wire) };
169
+ default:
170
+ throw new TypeError('subtitles');
171
+ }
172
+ }
173
+
174
+ /** `null` until the joined event's list arrived, `[]` when it has none (bridge.md 2.8). */
175
+ function decodeAvailableSubtitles(wire: unknown): LiveVoiceAvailableSubtitle[] | null {
176
+ if (wire === null) return null;
177
+ if (!Array.isArray(wire)) throw new TypeError('availableSubtitles');
178
+ return wire.filter(record).flatMap(subtitle =>
179
+ typeof subtitle.channelId === 'number' && typeof subtitle.name === 'string'
180
+ ? [{
181
+ channelId: subtitle.channelId,
182
+ name: subtitle.name,
183
+ language: typeof subtitle.language === 'string' ? subtitle.language : null,
184
+ parentChannelId: typeof subtitle.parentChannelId === 'number' ? subtitle.parentChannelId : null,
185
+ }]
186
+ : []);
187
+ }
188
+
189
+ // MARK: The stores
190
+
191
+ const connection = store<ConnectionValue, LiveVoiceConnection>(
192
+ 'connection', decodeConnection, { status: 'idle' }, publicConnection,
193
+ );
194
+ const subtitles = store<LiveVoiceSubtitleState>('subtitles', decodeSubtitles, { kind: 'disabled' });
195
+ const availableSubtitles = store('availableSubtitles', decodeAvailableSubtitles, null);
196
+ const audioOutput = store<LiveVoiceAudioOutput>('audioOutput', decodeAudioOutput, 'system');
197
+ const features = store('features', decodeFeatures, { customUiAllowed: false, hideBranding: false });
198
+ const currentEvent = store('currentEvent', decodeEvent, null);
199
+ const requestableLanguages = store('requestableLanguages', decodeLanguages, null);
200
+ const linkedEvents = store('linkedEvents', decodeLinkedEvents, null);
201
+
202
+ // MARK: Connection
203
+
204
+ /**
205
+ * The connection to the event: `idle` before `initialize()` and while nothing is joined or
206
+ * joining.
207
+ */
208
+ export function getCurrentConnection(): LiveVoiceConnection {
209
+ return connection.get();
210
+ }
211
+
212
+ /**
213
+ * Calls `listener` with the current connection at once, then on every change. A state change is a
214
+ * display update; await `joinEvent()` to confirm a particular join.
215
+ *
216
+ * @param listener - Called with the current value at once, then with every change.
217
+ * @returns A subscription; its `remove()` ends the observation.
218
+ */
219
+ export function addConnectionListener(listener: (connection: LiveVoiceConnection) => void): LiveVoiceSubscription {
220
+ return connection.add(listener);
221
+ }
222
+
223
+ /** The connection in a component. */
224
+ export function useLiveVoiceConnection(): LiveVoiceConnection {
225
+ return connection.use();
226
+ }
227
+
228
+ // MARK: Subtitles
229
+
230
+ /**
231
+ * Which subtitles the SDK receives, with the fragments so far. It is `disabled` after a join, a
232
+ * leave and `stopSubtitles`. The value follows a call shortly, also an awaited `joinEvent`: right
233
+ * after the promise resolves it can still show the previous value, so observe it with
234
+ * {@link addSubtitlesListener} or {@link useLiveVoiceSubtitles}.
235
+ */
236
+ export function getCurrentSubtitles(): LiveVoiceSubtitleState {
237
+ return subtitles.get();
238
+ }
239
+
240
+ /**
241
+ * Calls `listener` with the current subtitles at once, then on every change.
242
+ *
243
+ * @param listener - Called with the current value at once, then with every change.
244
+ * @returns A subscription; its `remove()` ends the observation.
245
+ */
246
+ export function addSubtitlesListener(listener: (subtitles: LiveVoiceSubtitleState) => void): LiveVoiceSubscription {
247
+ return subtitles.add(listener);
248
+ }
249
+
250
+ /** The subtitles in a component. */
251
+ export function useLiveVoiceSubtitles(): LiveVoiceSubtitleState {
252
+ return subtitles.use();
253
+ }
254
+
255
+ /**
256
+ * The subtitles that can be started: `null` while no event is joined, a list once `joinEvent` has
257
+ * resolved, `[]` when the event has none. The list stays during a reconnect.
258
+ */
259
+ export function getCurrentAvailableSubtitles(): LiveVoiceAvailableSubtitle[] | null {
260
+ return availableSubtitles.get();
261
+ }
262
+
263
+ /**
264
+ * Calls `listener` with the current available subtitles at once, then on every change.
265
+ *
266
+ * @param listener - Called with the current value at once, then with every change.
267
+ * @returns A subscription; its `remove()` ends the observation.
268
+ */
269
+ export function addAvailableSubtitlesListener(
270
+ listener: (availableSubtitles: LiveVoiceAvailableSubtitle[] | null) => void,
271
+ ): LiveVoiceSubscription {
272
+ return availableSubtitles.add(listener);
273
+ }
274
+
275
+ /** The available subtitles in a component. */
276
+ export function useLiveVoiceAvailableSubtitles(): LiveVoiceAvailableSubtitle[] | null {
277
+ return availableSubtitles.use();
278
+ }
279
+
280
+ // MARK: Audio output
281
+
282
+ /**
283
+ * The audio output preference. Before `initialize()` it is `'system'` until `setAudioOutput()`
284
+ * sets a preference, then that preference.
285
+ */
286
+ export function getCurrentAudioOutput(): LiveVoiceAudioOutput {
287
+ return audioOutput.get();
288
+ }
289
+
290
+ /**
291
+ * Calls `listener` with the current audio output at once, then on every change.
292
+ *
293
+ * @param listener - Called with the current value at once, then with every change.
294
+ * @returns A subscription; its `remove()` ends the observation.
295
+ */
296
+ export function addAudioOutputListener(listener: (audioOutput: LiveVoiceAudioOutput) => void): LiveVoiceSubscription {
297
+ return audioOutput.add(listener);
298
+ }
299
+
300
+ /** The audio output in a component. */
301
+ export function useLiveVoiceAudioOutput(): LiveVoiceAudioOutput {
302
+ return audioOutput.use();
303
+ }
304
+
305
+ /** Internal: `setAudioOutput()` before native reported a value, which then replaces it. */
306
+ export function presetAudioOutput(output: LiveVoiceAudioOutput): void {
307
+ audioOutput.preset(output);
308
+ }
309
+
310
+ // MARK: Features
311
+
312
+ /**
313
+ * What the API key of the joined event permits; `false` for both before the first join, after a
314
+ * leave and after a failure. Right after an awaited `joinEvent` it can still show the previous
315
+ * value; observe it with {@link addFeaturesListener} or {@link useLiveVoiceFeatures}.
316
+ */
317
+ export function getCurrentFeatures(): LiveVoiceFeatures {
318
+ return features.get();
319
+ }
320
+
321
+ /**
322
+ * Calls `listener` with the current features at once, then whenever they change.
323
+ *
324
+ * @param listener - Called with the current value at once, then with every change.
325
+ * @returns A subscription; its `remove()` ends the observation.
326
+ */
327
+ export function addFeaturesListener(listener: (features: LiveVoiceFeatures) => void): LiveVoiceSubscription {
328
+ return features.add(listener);
329
+ }
330
+
331
+ /** The features in a component. */
332
+ export function useLiveVoiceFeatures(): LiveVoiceFeatures {
333
+ return features.use();
334
+ }
335
+
336
+ // MARK: Current event
337
+
338
+ /**
339
+ * The joined event: `null` whenever no event is ready, set once the join is ready, kept during a
340
+ * reconnect, and following a linked switch. Its brand colours come with every API key.
341
+ */
342
+ export function getCurrentEvent(): LiveVoiceEvent | null {
343
+ return currentEvent.get();
344
+ }
345
+
346
+ /**
347
+ * Calls `listener` with the current event at once, then on every change.
348
+ *
349
+ * @param listener - Called with the current value at once, then with every change.
350
+ * @returns A subscription; its `remove()` ends the observation.
351
+ */
352
+ export function addCurrentEventListener(listener: (event: LiveVoiceEvent | null) => void): LiveVoiceSubscription {
353
+ return currentEvent.add(listener);
354
+ }
355
+
356
+ /** The current event in a component. */
357
+ export function useLiveVoiceCurrentEvent(): LiveVoiceEvent | null {
358
+ return currentEvent.use();
359
+ }
360
+
361
+ // MARK: Requestable languages
362
+
363
+ /**
364
+ * The languages listeners can request: `null` until the join has authenticated, for a key without
365
+ * the custom-UI permission, when the event disables requests, and whenever no event is ready; kept
366
+ * during a reconnect.
367
+ */
368
+ export function getCurrentRequestableLanguages(): LiveVoiceRequestableLanguage[] | null {
369
+ return requestableLanguages.get();
370
+ }
371
+
372
+ /**
373
+ * Calls `listener` with the current languages at once, then on every change.
374
+ *
375
+ * @param listener - Called with the current value at once, then with every change.
376
+ * @returns A subscription; its `remove()` ends the observation.
377
+ */
378
+ export function addRequestableLanguagesListener(
379
+ listener: (languages: LiveVoiceRequestableLanguage[] | null) => void,
380
+ ): LiveVoiceSubscription {
381
+ return requestableLanguages.add(listener);
382
+ }
383
+
384
+ /** The requestable languages in a component. */
385
+ export function useLiveVoiceRequestableLanguages(): LiveVoiceRequestableLanguage[] | null {
386
+ return requestableLanguages.use();
387
+ }
388
+
389
+ // MARK: Linked events
390
+
391
+ /**
392
+ * The events linked to the joined one: `null` until the join has authenticated, for a key without
393
+ * the custom-UI permission, and whenever no event is ready; kept during a reconnect.
394
+ */
395
+ export function getCurrentLinkedEvents(): LiveVoiceLinkedEvent[] | null {
396
+ return linkedEvents.get();
397
+ }
398
+
399
+ /**
400
+ * Calls `listener` with the current linked events at once, then on every change.
401
+ *
402
+ * @param listener - Called with the current value at once, then with every change.
403
+ * @returns A subscription; its `remove()` ends the observation.
404
+ */
405
+ export function addLinkedEventsListener(
406
+ listener: (linkedEvents: LiveVoiceLinkedEvent[] | null) => void,
407
+ ): LiveVoiceSubscription {
408
+ return linkedEvents.add(listener);
409
+ }
410
+
411
+ /** The linked events in a component. */
412
+ export function useLiveVoiceLinkedEvents(): LiveVoiceLinkedEvent[] | null {
413
+ return linkedEvents.use();
414
+ }