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,286 @@
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 password round trips of the bridge (bridge.md 4.2, 4.3). Native looks up its memory and the
15
+ // host's store first; it asks here only for a password neither had. This module answers from the
16
+ // host's provider when one is set, otherwise from the built-in prompt of the most recently shown
17
+ // LiveVoiceView, otherwise it gives up. It never logs a password or a host exception's text.
18
+
19
+ import Native from '../specs/NativeLiveVoiceSdk';
20
+ import { writeLogEntry } from '../util/logger';
21
+
22
+ /** What a password is for, keyed by join code, since an event's id is unknown before joining. */
23
+ export type LiveVoicePasswordSubject =
24
+ | { kind: 'channel'; joinCode: string; channelId: number }
25
+ | { kind: 'event'; joinCode: string };
26
+
27
+ /** A password the SDK needs. `isRetry` is `true` after a rejected password in the same operation. */
28
+ export type LiveVoicePasswordRequest = {
29
+ subject: LiveVoicePasswordSubject;
30
+ isRetry: boolean;
31
+ };
32
+
33
+ /**
34
+ * Supplies a password, or `null` to give up. Giving up fails the call with `password_required`
35
+ * (for a channel `channel_password_required`), or after a rejected password with `wrong_password`
36
+ * (`channel_wrong_password`). A rejection or a thrown error gives up as well.
37
+ */
38
+ export type LiveVoicePasswordProvider = (request: LiveVoicePasswordRequest) => Promise<string | null>;
39
+
40
+ /**
41
+ * Keeps passwords between launches. The SDK loads one before asking for it, saves it once the
42
+ * server accepted it and removes it once the server rejected it. Calls for one subject complete in
43
+ * the order they were made. A failure is a cache miss; it never fails an operation.
44
+ */
45
+ export type LiveVoicePasswordStore = {
46
+ load(subject: LiveVoicePasswordSubject): Promise<string | null>;
47
+ save(subject: LiveVoicePasswordSubject, password: string): Promise<void>;
48
+ remove(subject: LiveVoicePasswordSubject): Promise<void>;
49
+ };
50
+
51
+ /** A request waiting for the built-in prompt. `name` is its title when known. */
52
+ export type PromptRequest = {
53
+ requestId: string;
54
+ subject: LiveVoicePasswordSubject;
55
+ isRetry: boolean;
56
+ name: string | null;
57
+ };
58
+
59
+ let provider: LiveVoicePasswordProvider | null = null;
60
+ let store: LiveVoicePasswordStore | null = null;
61
+ let bridgeInitialized = false;
62
+
63
+ /** Requests already taken or cancelled: a snapshot delivering one again never reopens it. */
64
+ const seen = new Set<string>();
65
+ const cancelled = new Set<string>();
66
+ /** Requests for the built-in prompt, oldest first; the first one is shown. */
67
+ const queue: PromptRequest[] = [];
68
+
69
+ /** Views that can present the prompt, in the order they were shown; the last one presents. */
70
+ const presenters: number[] = [];
71
+ let nextPresenter = 1;
72
+ const promptListeners = new Set<() => void>();
73
+
74
+ /**
75
+ * Sets the provider every later password request asks, or `null` for the built-in prompt. It can
76
+ * be set before `initialize()`. The built-in prompt needs a `LiveVoiceView` on screen: without a
77
+ * provider and without a view, a request gives up and its call fails with the password error.
78
+ */
79
+ export function setPasswordProvider(newProvider: LiveVoicePasswordProvider | null): void {
80
+ provider = typeof newProvider === 'function' ? newProvider : null;
81
+ }
82
+
83
+ /**
84
+ * Sets the store the SDK loads passwords from and saves them to, or `null` for none. It can be set
85
+ * before `initialize()`.
86
+ */
87
+ export function setPasswordStore(newStore: LiveVoicePasswordStore | null): void {
88
+ store = newStore != null && typeof newStore === 'object' ? newStore : null;
89
+ if (bridgeInitialized) Native.setPasswordStore(JSON.stringify({ isSet: store !== null }));
90
+ }
91
+
92
+ /** Whether a store is set, for `initialize`'s configuration. */
93
+ export function hasPasswordStore(): boolean {
94
+ return store !== null;
95
+ }
96
+
97
+ /** `initialize` delivered its configuration; later store changes go to native at once. */
98
+ export function bridgeDidInitialize(): void {
99
+ bridgeInitialized = true;
100
+ }
101
+
102
+ /** `onPasswordRequest` and the snapshot's waiting requests. Each id is answered once. */
103
+ export function receivePasswordRequest(wire: unknown): void {
104
+ const request = promptRequest(wire);
105
+ if (request === undefined || seen.has(request.requestId) || cancelled.has(request.requestId)) return;
106
+ seen.add(request.requestId);
107
+
108
+ const host = provider;
109
+ if (host !== null) {
110
+ const publicRequest = Object.freeze({ subject: Object.freeze({ ...request.subject }), isRetry: request.isRetry });
111
+ let answer: Promise<string | null>;
112
+ try { answer = Promise.resolve(host(publicRequest)); }
113
+ catch { answerPasswordRequest(request.requestId, null, true); return; }
114
+ answer.then(
115
+ password => answerPasswordRequest(request.requestId, typeof password === 'string' ? password : null),
116
+ () => answerPasswordRequest(request.requestId, null, true),
117
+ );
118
+ return;
119
+ }
120
+
121
+ if (presenters.length === 0) {
122
+ // No view on screen to ask: give up with the password error.
123
+ logPrompt(request, 'noView');
124
+ answerPasswordRequest(request.requestId, null);
125
+ return;
126
+ }
127
+ queue.push(request);
128
+ notifyPrompt();
129
+ }
130
+
131
+ /** `onPasswordRequestCancelled`: the operation ended without the password. */
132
+ export function receivePasswordRequestCancellation(wire: unknown): void {
133
+ const requestId = record(wire) && typeof wire.requestId === 'string' ? wire.requestId : undefined;
134
+ if (requestId === undefined) return;
135
+ cancelled.add(requestId);
136
+ const index = queue.findIndex(request => request.requestId === requestId);
137
+ if (index >= 0) {
138
+ const [dismissed] = queue.splice(index, 1);
139
+ logPrompt(dismissed!, 'dismissed');
140
+ notifyPrompt();
141
+ }
142
+ }
143
+
144
+ /** `onPasswordStoreRequest`: calls the host's store and answers once its call has finished. */
145
+ export function receivePasswordStoreRequest(wire: unknown): void {
146
+ if (!record(wire) || typeof wire.requestId !== 'string') return;
147
+ const requestId = wire.requestId;
148
+ const subject = passwordSubject(wire.subject);
149
+ const host = store;
150
+ if (subject === undefined || host === null) {
151
+ answerStoreRequest(requestId, false);
152
+ return;
153
+ }
154
+ const frozenSubject = Object.freeze(subject);
155
+ let call: Promise<unknown>;
156
+ try {
157
+ switch (wire.operation) {
158
+ case 'load':
159
+ call = Promise.resolve(host.load(frozenSubject)).then(password => {
160
+ answerStoreRequest(requestId, true, typeof password === 'string' ? password : null);
161
+ });
162
+ break;
163
+ case 'save':
164
+ if (typeof wire.password !== 'string') { answerStoreRequest(requestId, false); return; }
165
+ call = Promise.resolve(host.save(frozenSubject, wire.password)).then(() => answerStoreRequest(requestId, true));
166
+ break;
167
+ case 'remove':
168
+ call = Promise.resolve(host.remove(frozenSubject)).then(() => answerStoreRequest(requestId, true));
169
+ break;
170
+ default:
171
+ answerStoreRequest(requestId, false);
172
+ return;
173
+ }
174
+ } catch {
175
+ answerStoreRequest(requestId, false);
176
+ return;
177
+ }
178
+ // Native logs a failure without credentials; a failed load is a cache miss.
179
+ call.catch(() => answerStoreRequest(requestId, false));
180
+ }
181
+
182
+ // MARK: The built-in prompt
183
+
184
+ /** A view that can present the prompt. The most recently registered one still mounted presents. */
185
+ export function registerPresenter(): number {
186
+ const id = nextPresenter++;
187
+ presenters.push(id);
188
+ notifyPrompt();
189
+ return id;
190
+ }
191
+
192
+ /**
193
+ * The view went away. If it was presenting, its request gives up with the password error; with no
194
+ * view left, every waiting request does.
195
+ */
196
+ export function unregisterPresenter(id: number): void {
197
+ const index = presenters.indexOf(id);
198
+ if (index < 0) return;
199
+ const wasPresenting = index === presenters.length - 1;
200
+ presenters.splice(index, 1);
201
+ if (wasPresenting && queue.length > 0) {
202
+ const shown = queue.shift()!;
203
+ logPrompt(shown, 'dismissed');
204
+ answerPasswordRequest(shown.requestId, null);
205
+ }
206
+ if (presenters.length === 0) {
207
+ for (const request of queue.splice(0)) {
208
+ logPrompt(request, 'noView');
209
+ answerPasswordRequest(request.requestId, null);
210
+ }
211
+ }
212
+ notifyPrompt();
213
+ }
214
+
215
+ /** The request `presenter` shows now, or `null`. */
216
+ export function promptFor(presenter: number): PromptRequest | null {
217
+ if (presenters[presenters.length - 1] !== presenter) return null;
218
+ return queue[0] ?? null;
219
+ }
220
+
221
+ /** Calls `listener` whenever the shown prompt or its presenter changes. */
222
+ export function observePrompt(listener: () => void): () => void {
223
+ promptListeners.add(listener);
224
+ return () => { promptListeners.delete(listener); };
225
+ }
226
+
227
+ /** The prompt's answer: a password, or `null` for Cancel. */
228
+ export function answerPrompt(requestId: string, password: string | null): void {
229
+ const index = queue.findIndex(request => request.requestId === requestId);
230
+ if (index < 0) return;
231
+ const [answered] = queue.splice(index, 1);
232
+ logPrompt(answered!, password === null ? 'cancelled' : 'entered');
233
+ answerPasswordRequest(requestId, password);
234
+ notifyPrompt();
235
+ }
236
+
237
+ /** How the built-in prompt ended (bridge.md 3.6); never with the password. */
238
+ function logPrompt(request: PromptRequest, result: 'entered' | 'cancelled' | 'dismissed' | 'noView'): void {
239
+ writeLogEntry('LV_PASSWORD_PROMPT', 'info', {
240
+ subject: request.subject.kind,
241
+ result,
242
+ isRetry: String(request.isRetry),
243
+ });
244
+ }
245
+
246
+ function notifyPrompt(): void {
247
+ for (const listener of [...promptListeners]) {
248
+ try { listener(); }
249
+ catch { /* A view's update must not stop the others. */ }
250
+ }
251
+ }
252
+
253
+ // MARK: Wire
254
+
255
+ function answerPasswordRequest(requestId: string, password: string | null, failed = false): void {
256
+ Native.answerPasswordRequest(JSON.stringify(failed ? { requestId, password: null, failed: true } : { requestId, password }));
257
+ }
258
+
259
+ function answerStoreRequest(requestId: string, ok: boolean, password?: string | null): void {
260
+ Native.answerPasswordStoreRequest(JSON.stringify(ok && password !== undefined ? { requestId, ok, password } : { requestId, ok }));
261
+ }
262
+
263
+ function promptRequest(wire: unknown): PromptRequest | undefined {
264
+ if (!record(wire) || typeof wire.requestId !== 'string') return undefined;
265
+ const subject = passwordSubject(wire.subject);
266
+ if (subject === undefined) return undefined;
267
+ return {
268
+ requestId: wire.requestId,
269
+ subject,
270
+ isRetry: wire.isRetry === true,
271
+ name: typeof wire.name === 'string' && wire.name !== '' ? wire.name : null,
272
+ };
273
+ }
274
+
275
+ function passwordSubject(wire: unknown): LiveVoicePasswordSubject | undefined {
276
+ if (!record(wire) || typeof wire.joinCode !== 'string') return undefined;
277
+ if (wire.kind === 'event') return { kind: 'event', joinCode: wire.joinCode };
278
+ if (wire.kind === 'channel' && typeof wire.channelId === 'number') {
279
+ return { kind: 'channel', joinCode: wire.joinCode, channelId: wire.channelId };
280
+ }
281
+ return undefined;
282
+ }
283
+
284
+ function record(value: unknown): value is Record<string, unknown> {
285
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
286
+ }
@@ -0,0 +1,30 @@
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
+ // Internal: the action of a channel cell, the wrapper's only playback start. It is not exported
15
+ // from the package entry point; only `LiveVoiceView` calls it, for its default cells and for the
16
+ // `LiveVoiceChannelCell` objects it hands to `renderChannelCell`.
17
+
18
+ import { channelId as validateChannelId, invoke } from './Lifecycle';
19
+
20
+ /** Which kind of cell acts: native checks the custom-UI permission again for `custom`. */
21
+ export type CellKind = 'default' | 'custom';
22
+
23
+ /**
24
+ * Starts the channel if it is stopped, stops it if it is playing, as native decides from the
25
+ * current playback state at admission (bridge.md 3.3). Resolves once the channel plays or has
26
+ * stopped; rejects with the native error otherwise.
27
+ */
28
+ export async function togglePlayback(channelId: number, cell: CellKind): Promise<void> {
29
+ await invoke('togglePlayback', { channelId: validateChannelId(channelId, 'togglePlayback'), cell });
30
+ }
@@ -1,13 +1,15 @@
1
- /*
2
- * This source file is part of the LiveVoice SDK project
3
- *
4
- * Copyright (c) LiveVoice GmbH
5
- * Licensed under the MIT license
6
- *
7
- * See LICENSE for license information
8
- *
9
- * SPDX-License-Identifier: MIT
10
- */
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
+ //===----------------------------------------------------------------------===//
11
13
 
12
14
  import { TurboModuleRegistry, type TurboModule, type CodegenTypes } from 'react-native';
13
15
 
@@ -16,39 +18,44 @@ import { TurboModuleRegistry, type TurboModule, type CodegenTypes } from 'react-
16
18
  type EventEmitter<T> = CodegenTypes.EventEmitter<T>;
17
19
 
18
20
  export interface Spec extends TurboModule {
19
- initialize(androidServiceConfig: string | null): void
20
- joinEvent(joinCode: string, password: string | null, apiKey: string): void;
21
- leaveEvent(): void;
22
- reconnect(): void;
23
-
24
- getCurrentClaims(): string|null;
25
- // EventEmitter will only emit new values but not the current one.
26
- // Use these for initial/current value.
27
- getCurrentUiState(): string;
28
- getCurrentAudioState(): boolean; //true=speaker, false=headphones
29
- getCurrentSubtitles(): string;
30
- getCurrentAvailableSubtitleConfigs(): string;
31
-
32
- // applicable for 'ready' state
33
- setLiveVoiceUseSpeaker(value: boolean): void
34
-
35
- startChannel(id: number): void
36
- stopChannel(): void
37
-
38
- /**
39
- * @param channelId: -1 denotes an unspecified channel (i.e: the currently playing one)
40
- */
41
- startSubtitles(channelId: number): void
42
- stopSubtitles(): void
21
+ // The wrapper bridge of the native SDKs (internal; see bridge.md). Every structured value is
22
+ // one JSON string, encoded and decoded by the native SDK.
23
+
24
+ /** Attaches the bridge, applies the configuration and resolves with the snapshot. */
25
+ initialize(configuration: string): Promise<string>;
26
+ /** Runs one command; resolves with its reply, rejects with the bridge form of its error. */
27
+ execute(command: string, payload: string): Promise<string>;
28
+ /** `{ "<code>": "<text>", … }`, the localised text of every error code. Works before `initialize`. */
29
+ getErrorMessages(): string;
30
+ /** `{output}`, the audio output preference. Works before `initialize`; never fails. */
31
+ setAudioOutput(payload: string): void;
32
+ /** `{event, level, fields}`: one of the wrapper's own entries for the SDK log. Works before `initialize`. */
33
+ writeLogEntry(payload: string): void;
34
+ /** `{requestId, password, failed?}`, the answer to an `onPasswordRequest`. */
35
+ answerPasswordRequest(payload: string): void;
36
+ /** `{requestId, ok, password?}`, the answer to an `onPasswordStoreRequest`. */
37
+ answerPasswordStoreRequest(payload: string): void;
38
+ /** `{isSet}`: whether the host set a password store, for changes after `initialize`. */
39
+ setPasswordStore(payload: string): void;
43
40
 
44
41
  openLiveVoiceWebsite(): void
45
42
 
43
+ getSdkVersion(): string
44
+ getNativeSdkVersion(): string
45
+
46
46
  // Events
47
47
 
48
- readonly onUiStateChanged: EventEmitter<string>
49
- readonly onAudioOutputChanged: EventEmitter<boolean>
50
- readonly onAvailableSubtitleConfigsChanged: EventEmitter<string>
51
- readonly onSubtitlesChanged: EventEmitter<string>
48
+ /** `{state, revision, value}` for every change of a state after `initialize`. */
49
+ readonly onState: EventEmitter<string>
50
+ /** `{requestId, subject, isRetry, name?}`; answer each once with `answerPasswordRequest`. */
51
+ readonly onPasswordRequest: EventEmitter<string>
52
+ /** `{requestId}` of a request no operation waits for any more; dismiss its prompt. */
53
+ readonly onPasswordRequestCancelled: EventEmitter<string>
54
+ /** `{requestId, operation, subject, password?}` for the host's store; answer each once. */
55
+ readonly onPasswordStoreRequest: EventEmitter<string>
56
+ // One entry of the SDK log as JSON, the native SDK's or one the wrapper wrote with
57
+ // `writeLogEntry`: { event, level, fields, timestamp }. No current value and no replay.
58
+ readonly onLogEntry: EventEmitter<string>
52
59
 
53
60
  // Translations
54
61
 
@@ -60,20 +67,23 @@ export interface Spec extends TurboModule {
60
67
  errorScreenRetrying(): string
61
68
  errorScreenRetryingIn(seconds: number): string
62
69
 
63
- sdkErrorGeneric(): string
64
- sdkErrorInactive(): string
65
- sdkErrorInvalidApiKey(): string
66
- sdkErrorListenerLimitReached(): string
67
- sdkErrorNoNetwork(): string
68
- sdkErrorNotFound(): string
69
- sdkErrorRequestFailed(errorCode: number): string
70
- sdkErrorWrongPassword(): string
71
70
  streamingByTitle(): string
72
71
  errorRetryNowButton(): string
73
72
 
74
73
  accessibilityChannelPlay(): string
75
74
  accessibilityChannelStatusMuted(): string
76
75
  accessibilityChannelStop(): string
76
+
77
+ // The built-in password prompt (bridge.md 3.5)
78
+
79
+ passwordPromptTitle(): string
80
+ passwordPromptChannelMessage(): string
81
+ passwordPromptEventMessage(): string
82
+ passwordPromptWrongPassword(): string
83
+ passwordPromptField(): string
84
+ passwordPromptCancelButton(): string
85
+ passwordPromptChannelConfirmButton(): string
86
+ passwordPromptEventConfirmButton(): string
77
87
  }
78
88
 
79
89
  export default TurboModuleRegistry.getEnforcing<Spec>('LiveVoiceModule');
@@ -1,13 +1,15 @@
1
- /*
2
- * This source file is part of the LiveVoice SDK project
3
- *
4
- * Copyright (c) LiveVoice GmbH
5
- * Licensed under the MIT license
6
- *
7
- * See LICENSE for license information
8
- *
9
- * SPDX-License-Identifier: MIT
10
- */
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
+ //===----------------------------------------------------------------------===//
11
13
 
12
14
  export const COLORS = {
13
15
  primary: '#F1521B',
@@ -16,7 +18,8 @@ export const COLORS = {
16
18
  bgDark: '#1E1F23',
17
19
 
18
20
  cardBg: '#fff',
19
- cardBgDark: '#212429',
21
+ // Both native SDK views' dark background (Android `veryDarkGray`).
22
+ cardBgDark: '#212529',
20
23
 
21
24
  divider: '#f0f0f0',
22
25
  dividerDark: '#333333',
@@ -1,39 +1,63 @@
1
- /*
2
- * This source file is part of the LiveVoice SDK project
3
- *
4
- * Copyright (c) LiveVoice GmbH
5
- * Licensed under the MIT license
6
- *
7
- * See LICENSE for license information
8
- *
9
- * SPDX-License-Identifier: MIT
10
- */
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
+ //===----------------------------------------------------------------------===//
11
13
 
12
14
  /**
13
- * @fileoverview Translated strings for the React Native SDK.
14
- * These methods will return a translated string for the current locale.
15
- * German, English, and Spanish are supported at this time.
15
+ * @fileoverview The native SDK's texts: the public `Translations` of the default view, and the
16
+ * built-in password prompt's own texts, which stay internal.
16
17
  */
17
18
  import LiveVoiceSdkReactNative from '../specs/NativeLiveVoiceSdk';
18
19
 
20
+ /**
21
+ * Localized strings the SDK uses for its default UI, in the device's language (English, German and
22
+ * Spanish).
23
+ *
24
+ * Reuse them in your own parts, such as a custom channel cell, so your UI matches the SDK's
25
+ * wording. Each call reads the text synchronously from the native SDK and needs no join. Error
26
+ * texts are not here: every error carries its own `message`.
27
+ */
19
28
  export const Translations = {
29
+ /** "Inactive": a channel without a speaker. */
20
30
  channelStatusOffline: (): string => LiveVoiceSdkReactNative.channelStatusOffline(),
31
+ /** "This event currently has no channels visible for listeners." */
21
32
  noChannels: (): string => LiveVoiceSdkReactNative.noChannels(),
33
+ /** "AI active": a channel whose speaker is an AI voice. */
22
34
  isAiChannelStatusMessage: (): string => LiveVoiceSdkReactNative.isAiChannelStatusMessage(),
35
+ /** "No matching channels": a channel filter that leaves none. */
23
36
  sdkNoMatchingChannels: (): string => LiveVoiceSdkReactNative.sdkNoMatchingChannels(),
37
+ /** "Attempting to reconnect…" */
24
38
  errorScreenRetrying: (): string => LiveVoiceSdkReactNative.errorScreenRetrying(),
39
+ /** "Reconnecting in `seconds` seconds…" */
25
40
  errorScreenRetryingIn: (seconds: number): string => LiveVoiceSdkReactNative.errorScreenRetryingIn(seconds),
26
- sdkErrorGeneric: (): string => LiveVoiceSdkReactNative.sdkErrorGeneric(),
27
- sdkErrorInactive: (): string => LiveVoiceSdkReactNative.sdkErrorInactive(),
28
- sdkErrorInvalidApiKey: (): string => LiveVoiceSdkReactNative.sdkErrorInvalidApiKey(),
29
- sdkErrorListenerLimitReached: (): string => LiveVoiceSdkReactNative.sdkErrorListenerLimitReached(),
30
- sdkErrorNoNetwork: (): string => LiveVoiceSdkReactNative.sdkErrorNoNetwork(),
31
- sdkErrorNotFound: (): string => LiveVoiceSdkReactNative.sdkErrorNotFound(),
32
- sdkErrorRequestFailed: (errorCode: number): string => LiveVoiceSdkReactNative.sdkErrorRequestFailed(errorCode),
33
- sdkErrorWrongPassword: (): string => LiveVoiceSdkReactNative.sdkErrorWrongPassword(),
41
+ /** "Retry now" */
34
42
  errorRetryNowButton: (): string => LiveVoiceSdkReactNative.errorRetryNowButton(),
43
+ /** "Live Audio Streaming by", before the LiveVoice logo. */
35
44
  streamingByTitle: (): string => LiveVoiceSdkReactNative.streamingByTitle(),
45
+ /** "Play channel", the accessibility label of a channel's play button. */
36
46
  accessibilityChannelPlay: (): string => LiveVoiceSdkReactNative.accessibilityChannelPlay(),
47
+ /** "Muted by speaker" */
37
48
  accessibilityChannelStatusMuted: (): string => LiveVoiceSdkReactNative.accessibilityChannelStatusMuted(),
49
+ /** "Stop channel", the accessibility label of a channel's stop button. */
38
50
  accessibilityChannelStop: (): string => LiveVoiceSdkReactNative.accessibilityChannelStop(),
39
- };
51
+ };
52
+
53
+ /** Internal: the built-in password prompt's texts. Its title is the channel's or event's name when known. */
54
+ export const PasswordPromptTexts = {
55
+ title: (): string => LiveVoiceSdkReactNative.passwordPromptTitle(),
56
+ channelMessage: (): string => LiveVoiceSdkReactNative.passwordPromptChannelMessage(),
57
+ eventMessage: (): string => LiveVoiceSdkReactNative.passwordPromptEventMessage(),
58
+ wrongPassword: (): string => LiveVoiceSdkReactNative.passwordPromptWrongPassword(),
59
+ field: (): string => LiveVoiceSdkReactNative.passwordPromptField(),
60
+ cancelButton: (): string => LiveVoiceSdkReactNative.passwordPromptCancelButton(),
61
+ channelConfirmButton: (): string => LiveVoiceSdkReactNative.passwordPromptChannelConfirmButton(),
62
+ eventConfirmButton: (): string => LiveVoiceSdkReactNative.passwordPromptEventConfirmButton(),
63
+ };
@@ -0,0 +1,23 @@
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
+ /**
15
+ * Freezes `value` and every plain object and array inside it, so a host cannot change what the
16
+ * SDK handed out. `Date`s and errors are left as they are.
17
+ */
18
+ export function deepFreeze<T>(value: T): T {
19
+ if (value === null || typeof value !== 'object' || Object.isFrozen(value)) return value;
20
+ if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype) return value;
21
+ for (const nested of Object.values(value as object)) deepFreeze(nested);
22
+ return Object.freeze(value);
23
+ }