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
@@ -13,359 +13,353 @@
13
13
  //
14
14
  //===----------------------------------------------------------------------===//
15
15
 
16
+ import { Image, Platform } from 'react-native';
16
17
  import LiveVoiceSdkReactNative from "../specs/NativeLiveVoiceSdk.js";
17
- import { serviceDisabled, DEFAULT_MESSAGE_SENTINEL } from "../util/ForegroundServiceConfig.js";
18
- import { describeForegroundServiceConfig, LiveVoiceLogEvent, logAudioOutputChanged, logInfo } from "../util/logger.js";
19
- import { getCurrentClaims as readCurrentClaims, getCurrentUiState as readCurrentUiState, onUiStateChanged as observeUiState } from "./LiveVoiceState.js";
20
-
21
- // Claims stays part of the public type surface for backwards compatibility.
18
+ import { awaitRevisions, initializeBridge, isInitialized, record, runtimeId } from "./Bridge.js";
19
+ import { nativeSdkVersions } from "./NativeSdkVersions.js";
20
+ import { invoke, join, normalizeError, usageError, channelId as validateChannelId } from "./Lifecycle.js";
21
+ import { presetAudioOutput } from "./Observables.js";
22
+ import { LiveVoiceLogEvent, logInfo } from "../util/logger.js";
23
+ import { hasPasswordStore } from "./Passwords.js";
22
24
 
23
25
  /**
24
- * The authorization features for the joined event. Both flags are `false` until an event is joined
25
- * and ready.
26
+ * How LiveVoice shares audio with other apps while a channel plays:
27
+ * - `'exclusive'`: other audio pauses, as for a media app. The default.
28
+ * - `'duckOthers'`: other audio keeps playing, quieter.
29
+ * - `'hostManaged'`: on iOS, your app configures the audio session and output route; LiveVoice
30
+ * changes neither. On Android, LiveVoice requests no audio focus, so your app handles focus
31
+ * changes and stops playback when needed. Android output selection still applies.
32
+ *
33
+ * iOS interruptions pause LiveVoice in every mode. Android's automatic focus-loss handling
34
+ * applies only when LiveVoice owns audio focus.
26
35
  */
27
36
 
28
37
  /**
29
- * Initialize the LiveVoice SDK.
30
- *
31
- * @param {ForegroundServiceConfig} [androidServiceConfig=serviceDisabled] - Pass the service config on Android.
38
+ * Android only: whether a foreground service keeps playback alive while your app is in the
39
+ * background. Ignored on iOS.
32
40
  */
33
- export function initialize(androidServiceConfig = serviceDisabled) {
34
- logInfo(LiveVoiceLogEvent.init, {
35
- androidServiceConfig: describeForegroundServiceConfig(androidServiceConfig)
36
- });
37
- let serviceTypeAsString;
38
- switch (androidServiceConfig.type) {
39
- case 'Disabled':
40
- serviceTypeAsString = null;
41
- break;
42
- case 'Enabled':
43
- if (androidServiceConfig.message == null) {
44
- serviceTypeAsString = DEFAULT_MESSAGE_SENTINEL;
45
- } else {
46
- serviceTypeAsString = androidServiceConfig.message;
47
- }
48
- break;
49
- }
50
41
 
51
- // Interface cannot take default-parameter, so we need to wrap it here
52
- LiveVoiceSdkReactNative.initialize(serviceTypeAsString);
53
- }
42
+ /** Options for {@link initialize}. Every option has a default. */
43
+
44
+ const audioFocusValues = ['exclusive', 'duckOthers', 'hostManaged'];
54
45
 
55
46
  /**
56
- * Join an event.
47
+ * Initializes the LiveVoice SDK. Await it before joining an event; reading values and adding
48
+ * listeners works before it.
57
49
  *
58
- * @abstract By joining an event you can display the event's channels.
50
+ * Calling it again with the same options (after defaults) succeeds. Changed options apply while
51
+ * no event is joined (the connection is `idle` or `failed`) and reject with `invalid_argument`
52
+ * otherwise; an option a platform ignores never counts as a change there.
59
53
  *
60
- * @param {string} joinCode - The listener code of your event. You can find it on the event page of the admin web-interface by clicking on 'Share with your audience'.
61
- * @param {string | null} password - The optional password to join the event. If a password has been set for listeners in your event, it can be found in the 'Access' tab of the event page of the admin web-interface.
62
- * @param {string} apiKey - Your API key. You can find your API key in the account page when logged in on the website.
54
+ * @param options - See {@link LiveVoiceInitializeOptions}; every option has a default.
55
+ * @throws {LiveVoiceError} `invalid_argument` for an option of the wrong type or a change while
56
+ * joined, `unsupported_sdk` when the native SDK is not the version this package was built for.
63
57
  */
64
- export function joinEvent(joinCode, password, apiKey) {
65
- logInfo(LiveVoiceLogEvent.joinRequest, {
66
- hasPassword: password != null,
67
- joinCode
58
+ export async function initialize(options = {}) {
59
+ const configuration = initializeConfiguration(options);
60
+ logInfo(LiveVoiceLogEvent.init, {
61
+ androidForegroundService: configuration.androidForegroundService,
62
+ audioFocus: configuration.audioFocus,
63
+ showsSystemMediaControls: configuration.showsSystemMediaControls
68
64
  });
69
- return LiveVoiceSdkReactNative.joinEvent(joinCode, password, apiKey);
65
+ // Every key is always sent, so native compares complete configurations (bridge.md 3.2).
66
+ try {
67
+ await initializeBridge({
68
+ ...configuration,
69
+ hasPasswordStore: hasPasswordStore(),
70
+ nativeSdkVersion: Platform.OS === 'android' ? nativeSdkVersions.android : nativeSdkVersions.ios,
71
+ runtimeId
72
+ });
73
+ } catch (error) {
74
+ throw normalizeError(error);
75
+ }
76
+ sendPendingArtwork();
70
77
  }
71
78
 
72
- /**
73
- * Leave the current event.
74
- *
75
- * @abstract You can explicitly leave an event to tear down any network connections the SDK uses when you no longer display any channels.
76
- */
77
- export function leaveEvent() {
78
- logInfo(LiveVoiceLogEvent.leave);
79
- return LiveVoiceSdkReactNative.leaveEvent();
79
+ /** The options with their defaults applied, or `invalid_argument` without reaching native. */
80
+ function initializeConfiguration(options) {
81
+ const invalid = explanation => usageError('invalid_argument', 'initialize', explanation);
82
+ if (options === null || typeof options !== 'object') throw invalid('The options are an object.');
83
+ const {
84
+ androidServiceConfig,
85
+ showsSystemMediaControls,
86
+ audioFocus
87
+ } = options;
88
+ if (showsSystemMediaControls !== undefined && typeof showsSystemMediaControls !== 'boolean') {
89
+ throw invalid('showsSystemMediaControls is a boolean.');
90
+ }
91
+ if (audioFocus !== undefined && !audioFocusValues.includes(audioFocus)) {
92
+ throw invalid("audioFocus is 'exclusive', 'duckOthers' or 'hostManaged'.");
93
+ }
94
+ if (androidServiceConfig !== undefined) {
95
+ const kind = androidServiceConfig !== null && typeof androidServiceConfig === 'object' ? androidServiceConfig.kind : undefined;
96
+ if (kind !== 'enabled' && kind !== 'disabled') {
97
+ throw invalid("androidServiceConfig is { kind: 'enabled' } or { kind: 'disabled' }.");
98
+ }
99
+ }
100
+ return {
101
+ audioFocus: audioFocus ?? 'exclusive',
102
+ showsSystemMediaControls: showsSystemMediaControls ?? true,
103
+ // Enabled by default, so background playback works without setup.
104
+ androidForegroundService: androidServiceConfig?.kind === 'disabled' ? 'disabled' : 'enabled'
105
+ };
80
106
  }
81
107
 
82
108
  /**
83
- * Reconnect when a connection error occurred.
109
+ * Joins an event and resolves with the joined event once it is ready: authenticated, its initial
110
+ * state loaded, and commands accepted. A channel can be started right away; nothing plays yet and
111
+ * no subtitles are received.
84
112
  *
85
- * @abstract Call this method to try to reconnect when a connection error has occurred.
86
- */
87
- export function reconnect() {
88
- logInfo(LiveVoiceLogEvent.reconnectRequest);
89
- return LiveVoiceSdkReactNative.reconnect();
90
- }
91
-
92
- /**
93
- * Get the claims for the current event.
113
+ * When the promise resolves, the observed values (connection, current event, linked events,
114
+ * requestable languages, available subtitles) already show the joined event, or the result of a
115
+ * newer call. If an update of those values cannot be delivered, the call still resolves, after 5
116
+ * seconds, and the problem is logged; the same holds for `leaveEvent`, the joined event's
117
+ * `leave()`, `reconnect` and `switchToLinkedEvent`. The features and the subtitle state are not
118
+ * among these values: right after the promise resolves they can still show the previous value, so
119
+ * observe them.
94
120
  *
95
- * @deprecated Use {@link getCurrentFeatures} / {@link onFeaturesChanged} to read the authorization
96
- * features, or build your UI with the `renderChannel` prop on `LiveVoiceView` (which applies the
97
- * customization gating for you). Scheduled for removal in a future major version.
98
- * @returns {Claims | null} The authorization claims, or `null` if not yet joined
99
- */
100
- export function getCurrentClaims() {
101
- return readCurrentClaims();
102
- }
103
-
104
- /**
105
- * Get the authorization features for the joined event.
121
+ * Every call is a fresh join, also to the same code: it replaces whatever is joined or joining,
122
+ * and it never retries by itself.
106
123
  *
107
- * @abstract Reflects what the joined API key permits. Both flags are `false` until an event is
108
- * joined and ready. You should only need this for an initial value; use {@link onFeaturesChanged}
109
- * to observe changes.
110
- * @returns {Features} The current features (`customUiAllowed` / `hideBranding`).
124
+ * @param request - The join code, the API key and an optional password.
125
+ * @returns The joined event; its `leave()` leaves only this join.
126
+ * @throws {LiveVoiceError} `invalid_argument` for an empty API key, a malformed join code or a
127
+ * speaker's code; `superseded` when a newer join replaced it; `cancelled` when a leave ended it;
128
+ * `timed_out` when the event was not ready within 30 seconds, which leaves the connection
129
+ * `failed` (waiting for an earlier event's cleanup counts, entering a password does not);
130
+ * `not_initialized` before `initialize()`; otherwise why the join failed, see the joining codes
131
+ * of {@link LiveVoiceErrorCode}.
111
132
  */
112
- export function getCurrentFeatures() {
113
- const claims = readCurrentClaims();
114
- return {
115
- customUiAllowed: claims?.customUiAllowed ?? false,
116
- hideBranding: claims?.hideBranding ?? false
117
- };
133
+ export function joinEvent(request) {
134
+ return join(request);
118
135
  }
119
136
 
120
137
  /**
121
- * Get the current state of the LiveVoice SDK.
138
+ * Leaves whatever event is joined or joining. Call it as often as you like once `initialize()`
139
+ * has resolved.
122
140
  *
123
- * @deprecated Build your UI with the `renderChannel` prop on `LiveVoiceView` instead of reading the
124
- * raw UI state. Scheduled for removal in a future major version.
125
- * @returns {UiState} The current view state
126
- */
127
- export function getCurrentUiState() {
128
- return readCurrentUiState();
129
- }
130
-
131
- /**
132
- * Get the current available subtitle configurations.
141
+ * Resolves when the event's local cleanup has ended, or at once when nothing is joined and no
142
+ * cleanup is still running. The observed values then already show the result: the connection is
143
+ * `idle` unless a newer join exists, and the current event and its lists are `null`. A pending
144
+ * `joinEvent`, `switchToLinkedEvent` or `reconnect` rejects with `cancelled`. To leave only one
145
+ * join, use the `leave()` of the joined event `joinEvent` returned.
133
146
  *
134
- * @abstract Returns `null` until the SDK has joined an event and reached the `ready` state, so you
135
- * can tell "not loaded yet" (`null`) apart from "loaded, but none available" (`[]`). You should
136
- * only need this for an initial value; use {@link onAvailableSubtitleConfigsChanged} to observe
137
- * changes.
138
- * @returns {AvailableSubtitle[] | null} The available subtitles, or `null` if not yet loaded.
147
+ * @throws {LiveVoiceError} `leave_incomplete` when the cleanup has not finished within 5 seconds:
148
+ * the event is left all the same, the connection is `idle` and the cleanup continues. Another
149
+ * leave then waits for the same cleanup and can fail with `leave_incomplete` again.
150
+ * `not_initialized` before `initialize()`.
139
151
  */
140
- export function getCurrentSubtitleConfiguration() {
141
- if (readCurrentUiState().type !== 'ready') return null;
142
- return JSON.parse(LiveVoiceSdkReactNative.getCurrentAvailableSubtitleConfigs());
152
+ export async function leaveEvent() {
153
+ logInfo(LiveVoiceLogEvent.leave);
154
+ // When leaveEvent() resolves, the values already show the idle connection.
155
+ const reply = await invoke('leave');
156
+ await awaitRevisions(record(reply) ? reply.revisions : undefined);
143
157
  }
144
158
 
145
159
  /**
146
- * Get the current subtitle fragments.
160
+ * Reconnects the joined event with a fresh connection and resolves once that connection is ready.
147
161
  *
148
- * @deprecated Use {@link getCurrentSubtitleState}, which returns the full subtitle state (type +
149
- * channel + fragments). Scheduled for removal in a future major version.
150
- * @returns {string[]} The current subtitle fragments
151
- */
152
- export function getCurrentSubtitles() {
153
- return JSON.parse(LiveVoiceSdkReactNative.getCurrentSubtitles());
154
- }
155
-
156
- /**
157
- * Get the current subtitle state.
162
+ * It keeps the join. Allowed while the connection is `ready` or `reconnecting`, where it forces
163
+ * an attempt now, and after a failure with a retryable error, where it joins again with the same
164
+ * code and key and the connection shows `joining`. Playback and the subtitle choice are restored
165
+ * unless a stop or a leave came in between; ready does not promise that playback has resumed.
158
166
  *
159
- * @abstract Unlike {@link getCurrentSubtitles} (fragments only), this returns the full state: the
160
- * {@link SubtitleState.type} (`disabled`/`automatic`/`specific`), the channel for `specific`, and
161
- * the fragments. You should only need to call this for an initial value; use
162
- * {@link onSubtitleStateChanged} to observe changes.
163
- * @returns {SubtitleState} The current subtitle state
164
- */
165
- export function getCurrentSubtitleState() {
166
- return parseSubtitleState(LiveVoiceSdkReactNative.getCurrentSubtitleState());
167
- }
168
-
169
- /**
170
- * Get the current state of the audio output.
167
+ * When the promise resolves, the observed values already show the result, or that of a newer
168
+ * call. The connection can already show `reconnecting` again if it dropped meanwhile.
171
169
  *
172
- * @abstract You should only need to call this method to get an initial value. Use {@link onAudioOutputChanged}
173
- ` to be updated about the audio state.
174
- * @returns {boolean} `true` for the speaker and `false` for the receiver.
170
+ * @throws {LiveVoiceError} `not_joined` without a join and while the first join or a switch is
171
+ * still pending, which is not disturbed; `superseded` when a newer reconnect, join or switch
172
+ * replaced it; `cancelled` when a leave ended it; `timed_out` after 30 seconds. For an
173
+ * established connection only this call fails then: the event stays joined, the connection keeps
174
+ * showing `reconnecting` and recovery continues by itself. The retry of a failed join that times
175
+ * out leaves the connection `failed`. After a failure that is not retryable, that same error
176
+ * again. See {@link LiveVoiceErrorCode}.
175
177
  */
176
- export function getCurrentAudioState() {
177
- return LiveVoiceSdkReactNative.getCurrentAudioState();
178
+ export async function reconnect() {
179
+ logInfo(LiveVoiceLogEvent.reconnectRequest);
180
+ const reply = await invoke('reconnect');
181
+ // When reconnect() resolves, the values already show its result (18 item 110).
182
+ await awaitRevisions(record(reply) ? reply.revisions : undefined);
178
183
  }
179
184
 
180
185
  /**
181
- * Set the audio output.
182
- * @param {boolean} value - Set to `true` to use the speaker, and `false` to use the receiver.
186
+ * Sets where LiveVoice plays its audio: a preference the SDK keeps and applies whenever it plays.
187
+ * It works at any time, also before {@link initialize} and before joining an event, and never
188
+ * rejects. {@link getCurrentAudioOutput} reports it.
189
+ *
190
+ * @param output - `'system'` for the route the system chooses, `'speaker'` for the loudspeaker.
183
191
  */
184
- export function setLiveVoiceUseSpeaker(value) {
192
+ export async function setAudioOutput(output) {
193
+ // The public type allows nothing else; another value is ignored, as native ignores it.
194
+ if (output !== 'system' && output !== 'speaker') return;
185
195
  logInfo(LiveVoiceLogEvent.audioOutputSet, {
186
- mode: value ? 'speaker' : 'receiver'
196
+ output
187
197
  });
188
- return LiveVoiceSdkReactNative.setLiveVoiceUseSpeaker(value);
198
+ // Until native reports a value, the wrapper's own one follows the preference (18 item 74).
199
+ presetAudioOutput(output);
200
+ try {
201
+ LiveVoiceSdkReactNative.setAudioOutput(JSON.stringify({
202
+ output
203
+ }));
204
+ } catch {/* It never rejects. */}
189
205
  }
190
206
 
191
- /**
192
- * Start playing a channel.
193
- * @abstract You can find the channel ID for a channel in the admin web-interface at the bottom when tapping *Edit Channel*.
194
- * @deprecated Manual audio playback control should only be driven through `LiveVoiceView` channel
195
- * cells. Use the `onAudioPress` helper passed to `renderChannel` instead. Scheduled for removal in
196
- * a future major version.
197
- * @param {number} [id] - The channel ID.
198
- */
199
- export function startChannel(id) {
200
- logInfo(LiveVoiceLogEvent.channelStart, {
201
- channelId: id
202
- });
203
- return LiveVoiceSdkReactNative.startChannel(id);
204
- }
207
+ /** The artwork set before {@link initialize}, which sends it once it succeeds; `{}` clears it. */
208
+ let pendingArtwork;
205
209
 
206
210
  /**
207
- * Stop playing the currently playing channel.
211
+ * Sets the image the system's media controls show for the playing channel: the Lock Screen and
212
+ * Control Center on iOS, the media notification and the quick-settings player on Android. It is
213
+ * drawn fitted, with a margin, centred on a white square. Without one, the joined event's logo
214
+ * shows, if it has one.
208
215
  *
209
- * @deprecated Manual audio playback control should only be driven through `LiveVoiceView` channel
210
- * cells. Use the `onAudioPress` helper passed to `renderChannel` instead. Scheduled for removal in
211
- * a future major version.
212
- */
213
- export function stopChannel() {
214
- logInfo(LiveVoiceLogEvent.channelStop);
215
- return LiveVoiceSdkReactNative.stopChannel();
216
- }
217
-
218
- /**
219
- * Start receiving subtitles.
220
- * @abstract The SDK can receive a single stream of subtitle fragments at a time.
221
- * You can stop receiving subtitles using {@link stopSubtitles()}.
222
- * Whenever you call this method, any previous subtitle streams are stopped automatically and you receive the subtitles for the requested channel and language instead.
216
+ * It works at any time, and a change shows at once. Before `initialize()` the image is kept and
217
+ * applied once `initialize()` succeeds; a failure to load it is then only logged.
223
218
  *
224
- * Note: You have to make sure that subtitles for the given channel and language are enabled in the web-interface. You can use the {@link onAvailableSubtitleConfigsChanged} handler to check if subtitles are available for a given channel in a given language.
219
+ * ```tsx
220
+ * await setNowPlayingArtwork(require('./assets/artwork.png'));
221
+ * ```
225
222
  *
226
- * @param {number | null} channelId - The channel to receive subtitles for. Set to `null` to always receive subtitles for the currently playing channel.
223
+ * @param image - A bundled image (`require(…)`) or a `{ uri }` source with a `file://` or
224
+ * `http(s)://` URL (on Android also `content://` or `android.resource://`), PNG or JPEG. `null`
225
+ * removes it, so the event's logo shows again.
226
+ * @throws {LiveVoiceError} `invalid_argument` for a source without a URI, or for an image that
227
+ * cannot be loaded or decoded; the previous image then stays.
227
228
  */
228
- export function startSubtitles(channelId) {
229
- logInfo(LiveVoiceLogEvent.subtitlesStart, {
230
- channelId: channelId == null ? 'current' : channelId
229
+ export async function setNowPlayingArtwork(image) {
230
+ const artwork = image === null ? {} : {
231
+ uri: artworkUri(image)
232
+ };
233
+ logInfo(LiveVoiceLogEvent.nowPlayingArtworkSet, {
234
+ artwork: image === null ? 'none' : 'image'
231
235
  });
232
- const nativeSafeId = channelId == null ? -1 : channelId;
233
- LiveVoiceSdkReactNative.startSubtitles(nativeSafeId);
236
+ if (!isInitialized()) {
237
+ pendingArtwork = artwork;
238
+ return;
239
+ }
240
+ // A newer call replaces one still waiting for initialize.
241
+ pendingArtwork = undefined;
242
+ await invoke('setNowPlayingArtwork', artwork);
234
243
  }
235
244
 
236
- /**
237
- * Stop receiving subtitles.
238
- */
239
- export function stopSubtitles() {
240
- logInfo(LiveVoiceLogEvent.subtitlesStop);
241
- return LiveVoiceSdkReactNative.stopSubtitles();
245
+ /** The URI of a single image source, or `invalid_argument` without reaching native. */
246
+ function artworkUri(image) {
247
+ let uri;
248
+ try {
249
+ uri = Image.resolveAssetSource(image)?.uri;
250
+ } catch {
251
+ uri = undefined;
252
+ }
253
+ if (typeof uri !== 'string' || uri.trim() === '') {
254
+ throw usageError('invalid_argument', 'setNowPlayingArtwork', 'The image is null or a single image source that resolves to a URI.');
255
+ }
256
+ return uri;
242
257
  }
243
258
 
244
- // Event handlers
245
-
246
- /**
247
- * Handle changes of the audio output.
248
- *
249
- * @returns {object} - An object with a `remove` method to unsubscribe from the event.
250
- */
251
- export function onAudioOutputChanged(handler) {
252
- return LiveVoiceSdkReactNative.onAudioOutputChanged(data => {
253
- logAudioOutputChanged(data);
254
- handler(data);
255
- });
259
+ /** Sends the artwork set before `initialize`. Native logs a failure, which keeps the previous one. */
260
+ function sendPendingArtwork() {
261
+ const artwork = pendingArtwork;
262
+ if (artwork === undefined) return;
263
+ pendingArtwork = undefined;
264
+ invoke('setNowPlayingArtwork', artwork).catch(() => {/* Nobody awaits it any more. */});
256
265
  }
257
266
 
258
267
  /**
259
- * Handle changes of the UI state.
268
+ * Stops the playing channel and resolves once local playback has stopped.
260
269
  *
261
- * @deprecated Build your UI with the `renderChannel` prop on `LiveVoiceView` instead of observing
262
- * the raw UI state. Scheduled for removal in a future major version.
263
- * @returns {object} - An object with a `remove` method to unsubscribe from the event.
264
- */
265
- export function onUiStateChanged(handler) {
266
- return observeUiState(handler);
267
- }
268
-
269
- /**
270
- * Handle changes of the authorization features.
270
+ * Allowed whenever an event is joined, joining, reconnecting or failed; while joining or failed
271
+ * it resolves once an earlier event's audio is released. A pending start rejects with
272
+ * `cancelled`, and a later reconnect restores nothing. The channel's `playingState` shows
273
+ * `stopped` shortly after the promise resolves.
271
274
  *
272
- * @abstract Re-emits whenever the joined session changes (join/leave/ready), so the
273
- * `customUiAllowed` / `hideBranding` flags stay in sync with the current API key. Both are `false`
274
- * while not joined.
275
- * @returns {object} - An object with a `remove` method to unsubscribe from the event.
275
+ * @throws {LiveVoiceError} `not_joined` when no event is joined; `timed_out` when playback has
276
+ * not stopped within 10 seconds while connected; `leave_incomplete` when, while joining or
277
+ * failed, that audio is not released within 5 seconds (in both cases the stop itself continues);
278
+ * `generic` with `detail.reason` `stop_failed`. It can also fail with `cancelled`. See
279
+ * {@link LiveVoiceErrorCode}.
276
280
  */
277
- export function onFeaturesChanged(handler) {
278
- return observeUiState(() => handler(getCurrentFeatures()));
281
+ export async function stopChannel() {
282
+ logInfo(LiveVoiceLogEvent.channelStop);
283
+ await invoke('stopChannel');
279
284
  }
280
285
 
281
286
  /**
282
- * Handle changes of the available subtitle configurations.
287
+ * Starts receiving subtitles. The SDK receives one subtitle stream at a time: a new start
288
+ * replaces the previous selection. It never starts or stops playback.
289
+ * {@link getCurrentAvailableSubtitles} lists what can be started; the subtitles of an offline
290
+ * channel can be started too.
291
+ *
292
+ * For a given channel the promise resolves once the server accepted the subscription. Without a
293
+ * channel the subtitles follow the playing channel. That mode is on from the call and stays on
294
+ * when a channel's subtitles are refused, also when this call rejects for the channel playing
295
+ * now. While nothing plays the promise resolves at once; otherwise once the server accepted the
296
+ * playing channel's subscription. {@link getCurrentSubtitles} shows the selection shortly after
297
+ * the promise resolves.
283
298
  *
284
- * @abstract Reports `null` until the SDK reaches the `ready` state (see
285
- * {@link getCurrentSubtitleConfiguration}), then the loaded array (`[]` when none are available).
286
- * Re-emits when the configs change while ready, and when the ready state itself changes.
287
- * @returns { object } - An object with a`remove` method to unsubscribe from the event.
299
+ * @param options - `channelId`: the channel to receive subtitles for; leave it out or pass `null`
300
+ * to follow the playing channel. `password`: the channel's password, if it is protected; a
301
+ * password you pass is final. Without one, a given channel's password comes from the SDK's
302
+ * memory, the password store, then the password provider or the built-in prompt. Subtitles that
303
+ * follow the playing channel never ask for a password: they use the one you pass, for the channel
304
+ * playing now, or one the SDK remembers, such as the one playback was started with.
305
+ * @throws {LiveVoiceError} `invalid_argument` for a channel id that is not a positive integer;
306
+ * `not_joined` unless the connection is `ready`; `command_in_progress` when the same start is
307
+ * still pending; `cancelled` when a different start, `stopSubtitles`, a leave or a new join ended
308
+ * it; `timed_out` when the server does not accept within 10 seconds (entering a password does not
309
+ * count); `leave_incomplete` when an unfinished subtitle stop holds it up for more than 5
310
+ * seconds; a channel error such as `channel_wrong_password`. A connection loss during the call
311
+ * can fail it with `cancelled` or `network_failed`; observe the connection to follow recovery,
312
+ * the rejection and the connection update need not arrive in a particular order. See
313
+ * {@link LiveVoiceErrorCode}.
288
314
  */
289
- export function onAvailableSubtitleConfigsChanged(handler) {
290
- const isReady = () => readCurrentUiState().type === 'ready';
291
-
292
- // Configs changed: emit them only once the SDK is ready, otherwise `null`.
293
- const configsSubscription = LiveVoiceSdkReactNative.onAvailableSubtitleConfigsChanged(data => {
294
- handler(isReady() ? JSON.parse(data) : null);
315
+ export async function startSubtitles(options = {}) {
316
+ if (options === null || typeof options !== 'object' || options.password != null && typeof options.password !== 'string') {
317
+ throw usageError('invalid_argument', 'startSubtitles', 'The options are an object with an optional channel id and a password that is a string or null.');
318
+ }
319
+ const channelId = options.channelId ?? null;
320
+ logInfo(LiveVoiceLogEvent.subtitlesStart, {
321
+ channelId: channelId == null ? 'current' : channelId
295
322
  });
296
- // Readiness changed: re-emit the current configs (or `null` if no longer ready).
297
- const uiStateSubscription = observeUiState(() => {
298
- handler(getCurrentSubtitleConfiguration());
323
+ await invoke('startSubtitles', {
324
+ channelId: channelId == null ? null : validateChannelId(channelId, 'startSubtitles'),
325
+ // `null` is the same as no password: the lookup provides it.
326
+ password: options.password ?? undefined
299
327
  });
300
- return {
301
- remove: () => {
302
- configsSubscription.remove();
303
- uiStateSubscription.remove();
304
- }
305
- };
306
328
  }
307
329
 
308
330
  /**
309
- * Handle changes of the subtitle fragments.
331
+ * Stops receiving subtitles and resolves once their local delivery has ended.
310
332
  *
311
- * @deprecated Use {@link onSubtitleStateChanged}, which reports the full subtitle state (type +
312
- * channel + fragments). Scheduled for removal in a future major version.
313
- * @returns {object} - An object with a `remove` method to unsubscribe from the event.
314
- */
315
- export function onSubtitlesChanged(handler) {
316
- return LiveVoiceSdkReactNative.onSubtitlesChanged(data => {
317
- const subtitles = JSON.parse(data);
318
- handler(subtitles);
319
- });
320
- }
321
-
322
- /**
323
- * Handle changes of the subtitle state.
333
+ * It does not wait for the server and has no time limit. Allowed whenever an event is joined,
334
+ * joining, reconnecting or failed. A subtitle start that is still pending rejects with
335
+ * `cancelled`; playback is not affected. {@link getCurrentSubtitles} shows `disabled` shortly
336
+ * after the promise resolves at the latest.
324
337
  *
325
- * @abstract Reports the full state (type + channel + fragments), unlike the fragments-only
326
- * {@link onSubtitlesChanged}.
327
- * @returns {object} - An object with a `remove` method to unsubscribe from the event.
338
+ * @throws {LiveVoiceError} `not_joined` when no event is joined. It can also fail with
339
+ * `cancelled`. See {@link LiveVoiceErrorCode}.
328
340
  */
329
- export function onSubtitleStateChanged(handler) {
330
- return LiveVoiceSdkReactNative.onSubtitleStateChanged(data => {
331
- handler(parseSubtitleState(data));
332
- });
341
+ export async function stopSubtitles() {
342
+ logInfo(LiveVoiceLogEvent.subtitlesStop);
343
+ await invoke('stopSubtitles');
333
344
  }
334
345
 
335
346
  /**
336
- * Open the LiveVoice website in the device's default browser.
347
+ * Opens the LiveVoice website in the device's default browser.
337
348
  */
338
349
  export function openLiveVoiceWebsite() {
339
350
  logInfo(LiveVoiceLogEvent.openWebsite);
340
351
  return LiveVoiceSdkReactNative.openLiveVoiceWebsite();
341
352
  }
342
353
 
343
- /**
344
- * Get the version of the LiveVoice React Native SDK.
345
- *
346
- * @returns {string} The SDK version, e.g. `"2.0.1"`.
347
- */
354
+ /** Returns the version of this React Native package, for example `"3.0.0"`. */
348
355
  export function getSdkVersion() {
349
356
  return LiveVoiceSdkReactNative.getSdkVersion();
350
357
  }
351
- function parseSubtitleState(data) {
352
- const wire = JSON.parse(data);
353
- switch (wire.type) {
354
- case 'automatic':
355
- return {
356
- type: 'automatic',
357
- fragments: wire.fragments ?? []
358
- };
359
- case 'specific':
360
- return {
361
- type: 'specific',
362
- channelId: wire.channelId ?? -1,
363
- fragments: wire.fragments ?? []
364
- };
365
- default:
366
- return {
367
- type: 'disabled'
368
- };
369
- }
358
+
359
+ /**
360
+ * Returns the version of the native LiveVoice SDK this package uses, for example `"3.0.0"`.
361
+ */
362
+ export function getNativeSdkVersion() {
363
+ return LiveVoiceSdkReactNative.getNativeSdkVersion();
370
364
  }
371
365
  //# sourceMappingURL=LiveVoiceSdk.js.map