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
package/README.md CHANGED
@@ -6,11 +6,14 @@ The React Native SDK for integrating the LiveVoice service into your app.
6
6
 
7
7
  The LiveVoice SDK enables your app to browse and listen to your configured LiveVoice channels,
8
8
  as well as present a channel's live subtitles where available.
9
+ The SDK plays audio and subtitles; video will be supported in an upcoming version. Until
10
+ then a channel with video and audio plays its audio, one with only video cannot be played, and
11
+ a channel's `hasVideo` tells which channels have video.
9
12
 
10
13
  Using the LiveVoice SDK requires an account with SDK access enabled. Depending on your
11
14
  subscription, the SDK allows for hiding the LiveVoice branding or building a fully customized
12
15
  presentation. For more information contact sdk-support@livevoice.io. Once SDK access has been
13
- granted, you can find your personal API key in the API key section of your account page at
16
+ granted, you can find your personal API key in the 'API/SDK Keys' section of your account page at
14
17
  https://livevoice.io/en/account/api.
15
18
 
16
19
  ## Features
@@ -18,14 +21,19 @@ https://livevoice.io/en/account/api.
18
21
  - Browse and play the channels of a LiveVoice event
19
22
  - Live subtitles where the channel provides them
20
23
  - A drop-in `LiveVoiceView`, or a fully custom presentation with your own channel cells
21
- - Audio output selection (speaker, receiver, headphones)
24
+ - Password-protected events and channels, with a built-in prompt or your own
25
+ - Audio output preference (system route or loudspeaker), audio focus and the system media
26
+ controls
27
+ - The event's brand colours, language requests and linked events
28
+ - Diagnostic events for your own logging
22
29
  - Optional branding control and custom UI (subscription-dependent)
23
30
 
24
31
  ## Requirements
25
32
 
26
- - React Native 0.80 or newer
27
- - iOS 15.1 or newer
28
- - Android 7.0 (API level 24) or newer
33
+ - React Native 0.81 or newer
34
+ - iOS 15.1 or newer; Xcode 26.5 or newer (Swift 6.3)
35
+ - Android 7.0 (API level 24) or newer; the app's `compileSdk` must be 36 or newer
36
+ - JDK 21 for Android builds
29
37
 
30
38
  ## Installation
31
39
 
@@ -35,90 +43,121 @@ npm install livevoice-sdk-react-native
35
43
  yarn add livevoice-sdk-react-native
36
44
  ```
37
45
 
38
- On iOS, install the native pods from your app's `ios/` directory:
46
+ On iOS, CocoaPods is the supported setup. Install the pods from your app's
47
+ `ios/` directory:
39
48
 
40
49
  ```sh
41
50
  pod install
42
51
  ```
43
52
 
44
- ## Usage
53
+ This also fetches the native LiveVoice SDK, as a Swift package; do not add it
54
+ to your app yourself, and remove any `pod 'LiveVoiceSDK'` line left from 2.x. On Android there is nothing else to add.
45
55
 
46
- ```tsx
47
- import {
48
- initialize,
49
- joinEvent,
50
- leaveEvent,
51
- LiveVoiceView,
52
- } from 'livevoice-sdk-react-native';
56
+ Each release of this package is built for exactly one version of the native
57
+ iOS and Android SDKs, which it pins. Other combinations are not supported:
58
+ `initialize()` rejects with `unsupported_sdk`.
53
59
 
54
- // Initialize the SDK once, early in your app's lifecycle.
55
- initialize();
60
+ ## Usage
56
61
 
57
- // Join an event to load its channels. Arguments: (joinCode, password, apiKey).
58
- joinEvent('YOUR_JOIN_CODE', null /* no password */, 'YOUR_API_KEY');
62
+ ```tsx
63
+ import { useEffect, useState } from 'react';
64
+ import { Text } from 'react-native';
65
+ import { initialize, joinEvent, LiveVoiceError, LiveVoiceView } from 'livevoice-sdk-react-native';
66
+
67
+ // Your app's root: initialize once, and render the screens that join after it.
68
+ export function App() {
69
+ // `null` while initializing, then 'ready' or the error.
70
+ const [launch, setLaunch] = useState<'ready' | LiveVoiceError | null>(null);
71
+ useEffect(() => {
72
+ initialize().then(() => setLaunch('ready'), (error: LiveVoiceError) => setLaunch(error));
73
+ }, []);
74
+ if (launch === 'ready') return <EventScreen />;
75
+ // For example `unsupported_sdk`, when the native SDK isn't the version this package needs.
76
+ if (launch) return <Text>Unable to initialize LiveVoice: {launch.code}</Text>;
77
+ return null;
78
+ }
59
79
 
60
- // Render the drop-in UI anywhere in your component tree.
61
- function Channels() {
80
+ function EventScreen() {
81
+ useEffect(() => {
82
+ // This effect's own join. Under StrictMode the second run's join supersedes the first.
83
+ const joining = joinEvent({ joinCode: 'YOUR_JOIN_CODE', apiKey: 'YOUR_API_KEY' })
84
+ .catch((error: unknown) => {
85
+ // `superseded` or `cancelled`: a newer join or a leave ended it. LiveVoiceView shows
86
+ // connection errors itself.
87
+ const ended = error instanceof LiveVoiceError &&
88
+ (error.code === 'superseded' || error.code === 'cancelled');
89
+ if (!ended) console.warn(error);
90
+ return undefined;
91
+ });
92
+ return () => {
93
+ // Leaves this join, also one that resolves after unmounting, and never a newer one.
94
+ joining.then(joined => joined?.leave()).catch(error => console.warn(error));
95
+ };
96
+ }, []);
97
+
98
+ // Mounted at once: it shows loading while joining, asks for a protected event's password,
99
+ // and shows errors and reconnects.
62
100
  return <LiveVoiceView />;
63
101
  }
64
-
65
- // Leave the event when you no longer display any channels.
66
- leaveEvent();
67
102
  ```
68
103
 
69
- `joinEvent(joinCode, password, apiKey)` takes an optional listener `password` (pass `null` when
70
- the event has none). The join code and password come from the event page of the admin web
71
- interface; the API key is on your account page.
104
+ Await `initialize()` before joining an event; commands before it reject with
105
+ `not_initialized`. The join code and password come from the event's admin page.
72
106
 
73
- ### Custom channel cells
107
+ `joinEvent()` is a fresh join on every call: it replaces whatever is joined or
108
+ joining, and resolves once the event is ready. The joined event it returns
109
+ only leaves that join, never a newer one; `leaveEvent()` leaves whatever is
110
+ joined. Joining, switching, reconnecting and leaving resolve only when their
111
+ result is final, so the next line of your code can rely on it.
74
112
 
75
- To render your own channel rows instead of the built-in ones, pass `renderChannel` to
76
- `LiveVoiceView`.
113
+ Channels start from the cells of `LiveVoiceView`: a tap on a default cell, or
114
+ your custom cell's `togglePlayback()`. `stopChannel()` stops the playing
115
+ channel.
77
116
 
78
- ```tsx
79
- import { LiveVoiceView, PlayingState } from 'livevoice-sdk-react-native';
80
-
81
- // Custom cells require an API key that permits
82
- // custom UI. If you provide renderChannel but the
83
- // joined key isn't allowed, the SDK shows the
84
- // invalid-api-key error instead of your cells.
85
- <LiveVoiceView
86
- renderChannel={(channel, { isLastInList, onAudioPress }) => (
87
- <MyCustomCell
88
- name={channel.name}
89
- online={channel.isOnline}
90
- playing={channel.playingState === PlayingState.PLAYING}
91
- isLast={isLastInList}
92
- onPlayPress={onAudioPress}
93
- />
94
- )}
95
- />;
96
- ```
117
+ Errors are `LiveVoiceError`s with a `code`, `isRetryable` and a localised
118
+ `message` to show as it is. `superseded` and `cancelled` generally need no
119
+ message to the listener.
97
120
 
98
- ### Android background playback
121
+ Every state (the connection, the subtitles, the features, the joined event and
122
+ more) has a getter, a listener and a React hook, such as
123
+ `useLiveVoiceConnection()`.
99
124
 
100
- On Android, keeping playback alive in the background requires a foreground service. It is
101
- disabled by default — enable it by passing a configuration to `initialize`:
125
+ ## Background playback
102
126
 
103
- ```tsx
104
- import {
105
- initialize,
106
- serviceEnabledWithDefaultMessage,
107
- serviceEnabledWithMessage,
108
- } from 'livevoice-sdk-react-native';
127
+ To keep audio playing while the app is in the background or the screen is locked, the iOS app
128
+ needs the audio background mode: select the app target in Xcode, open **Signing & Capabilities**,
129
+ add **Background Modes** and check **Audio, AirPlay, and Picture in Picture**. Without it, iOS
130
+ stops playback when the app leaves the foreground.
109
131
 
110
- // Enable the foreground service with the SDK's default notification message.
111
- initialize(serviceEnabledWithDefaultMessage);
112
-
113
- // Or provide your own text; %s becomes the playing channel's name.
114
- initialize(serviceEnabledWithMessage('Channel %s is playing'));
115
- ```
132
+ On Android, the SDK keeps playback alive in the background with a foreground service, enabled by
133
+ default; `initialize({ androidServiceConfig: { kind: 'disabled' } })` turns it off.
116
134
 
117
- ## Examples and support
135
+ ## Examples and documentation
118
136
 
119
137
  The [example apps](https://github.com/LiveVoiceOfficial/livevoice-sdk-examples) are the best
120
- place to start — each is a working integration you can run and read. Find your API key on your
121
- [account page](https://livevoice.io/en/account/api). Questions: sdk-support@livevoice.io.
138
+ place to start: each is a working integration you can run and read. The
139
+ [React Native sample](https://github.com/LiveVoiceOfficial/livevoice-sdk-examples/tree/main/react-native)
140
+ explains the integration step by step, including what an awaited call guarantees and how
141
+ passwords work, and has a screen for each feature in `src/screens`:
142
+
143
+ | Topic | Screen |
144
+ |---|---|
145
+ | Joining and leaving an event | `GettingStarted/JoiningEventScreen.tsx` |
146
+ | Subtitles | `Subtitles/SubtitlesScreen.tsx` |
147
+ | Custom channel cells, loading, error and empty parts, filtering | `Channels/` |
148
+ | Passwords, your own prompt and password store | `EventFeatures/PasswordsScreen.tsx` |
149
+ | Language requests and linked events | `EventFeatures/` |
150
+ | Audio output, audio focus, media controls and artwork | `AudioAndSystem/` |
151
+ | Branding, localization and diagnostic events | `Customization/` |
152
+
153
+ Every function and type of this package is documented in its TypeScript declarations, which
154
+ your editor shows.
155
+
156
+ Migrating from 2.x: see
157
+ [`react-native/MIGRATION.md`](https://github.com/LiveVoiceOfficial/livevoice-sdk-examples/blob/main/react-native/MIGRATION.md)
158
+ in the example apps repository.
159
+
160
+ Questions: sdk-support@livevoice.io.
122
161
 
123
162
  ## License
124
163
 
@@ -15,8 +15,8 @@ buildscript {
15
15
  ext.LiveVoiceSdkReactNative = [
16
16
  kotlinVersion: "2.0.21",
17
17
  minSdkVersion: 24,
18
- compileSdkVersion: 36,
19
- targetSdkVersion: 36
18
+ compileSdkVersion: 37,
19
+ targetSdkVersion: 37
20
20
  ]
21
21
 
22
22
  ext.getExtOrDefault = { prop ->
@@ -85,7 +85,6 @@ android {
85
85
  * see: https://github.com/facebook/react-native/issues/39114
86
86
  */
87
87
  rootProject.allprojects { Project project ->
88
- println "Adding LiveVoice repository to project \"$project.name\""
89
88
  project.repositories {
90
89
  google()
91
90
  mavenCentral()
@@ -96,7 +95,9 @@ android {
96
95
 
97
96
  dependencies {
98
97
  implementation "com.facebook.react:react-android"
99
- implementation("io.livevoice.sdk:android:2.0.2") {
98
+ // Exact: another requested version of the native SDK fails the build.
99
+ implementation("io.livevoice.sdk:android") {
100
+ version { strictly("3.0.0") }
100
101
  exclude group: 'org.jspecify', module: 'jspecify'
101
102
  }
102
103
  implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
@@ -13,261 +13,195 @@
13
13
 
14
14
  package io.livevoice.react
15
15
 
16
- import android.util.Log
17
- import androidx.activity.ComponentActivity
18
- import androidx.appcompat.app.AppCompatActivity
19
- import androidx.lifecycle.lifecycleScope
16
+ import com.facebook.react.bridge.Promise
20
17
  import com.facebook.react.bridge.ReactApplicationContext
18
+ import com.facebook.react.bridge.UiThreadUtil
21
19
  import com.facebook.react.module.annotations.ReactModule
22
20
  import com.facebook.react.modules.systeminfo.ReactNativeVersion
21
+ import io.livevoice.sdk.android.internal.wrappers.LiveVoiceWrapperApi
22
+ import io.livevoice.sdk.android.internal.wrappers.LiveVoiceWrapperBridge
23
23
  import io.livevoice.sdk.android.publicApi.core.LiveVoice
24
- import io.livevoice.sdk.android.publicApi.core.model.ForegroundServiceConfig
25
- import io.livevoice.sdk.android.publicApi.core.model.channel.LiveVoicePlayingState.Connecting
26
- import io.livevoice.sdk.android.publicApi.core.model.channel.LiveVoicePlayingState.Playing
27
- import io.livevoice.sdk.android.publicApi.core.model.NotificationText
28
- import io.livevoice.sdk.android.publicApi.core.model.SdkPlatform
29
- import io.livevoice.sdk.android.publicApi.core.model.SdkUiState.Ready
30
- import io.livevoice.sdk.android.publicApi.core.model.exceptions.SdkNotConnectedException
31
- import io.livevoice.sdk.android.publicApi.serialization.LiveVoiceSerialization
24
+ import io.livevoice.sdk.android.publicApi.core.model.LiveVoiceErrorCode
25
+ import io.livevoice.sdk.android.publicApi.core.model.LiveVoiceException
26
+ import kotlinx.coroutines.CoroutineScope
27
+ import kotlinx.coroutines.Dispatchers
28
+ import kotlinx.coroutines.Job
29
+ import kotlinx.coroutines.SupervisorJob
30
+ import kotlinx.coroutines.flow.first
32
31
  import kotlinx.coroutines.launch
33
32
 
33
+ /**
34
+ * The only place the React Native wrapper talks to the native SDK, through its wrapper bridge.
35
+ * Every structured value is a JSON string the SDK encodes and decodes; this module only forwards
36
+ * them (bridge.md 1.1). Internal: only [LiveVoiceSdkReactNativePackage] creates it.
37
+ */
38
+ @OptIn(LiveVoiceWrapperApi::class)
34
39
  @ReactModule(name = LiveVoiceModule.NAME)
35
- class LiveVoiceModule(reactContext: ReactApplicationContext) :
40
+ internal class LiveVoiceModule(reactContext: ReactApplicationContext) :
36
41
  NativeLiveVoiceSdkSpec(reactContext) {
37
42
 
38
43
  override fun getName(): String {
39
44
  return NAME
40
45
  }
41
46
 
42
- override fun initialize(androidServiceConfig: String?) {
43
- val parsedServiceConfig = when (androidServiceConfig) {
44
- null -> ForegroundServiceConfig.Disabled
45
- DEFAULT_MESSAGE_SENTINEL -> ForegroundServiceConfig.enabledWithDefaultMessage
46
- else -> ForegroundServiceConfig.Enabled(NotificationText.RawValue(androidServiceConfig))
47
- }
47
+ @Volatile private var bridge: LiveVoiceWrapperBridge? = null
48
+ @Volatile private var invalidated = false
49
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
48
50
 
49
- try {
50
- val activity: AppCompatActivity =
51
- currentActivity as? AppCompatActivity ?: run {
52
- logError(EVENT_BRIDGE_ERROR, "action" to "initialize", "reason" to "missingActivity")
53
- return
54
- }
55
-
56
- val versionInfo = ReactNativeVersion.VERSION
57
- val reactVersion = "${versionInfo["major"]}.${versionInfo["minor"]}.${versionInfo["patch"]}"
58
-
59
- //initialize SDK
60
- LiveVoice.initializeLiveVoice(
61
- applicationContext = activity,
62
- foregroundServiceConfig = parsedServiceConfig,
63
- sdkPlatform = SdkPlatform.ReactNative(
64
- sdkVersion = Version.SDK_VERSION,
65
- reactVersion = reactVersion
66
- )
67
- )
68
-
69
- logInfo(EVENT_INIT, "platformVersion" to reactVersion)
70
-
71
- //forward serialized state and events from the SDK
72
- launchObservations(activity)
73
-
74
- } catch (ex: Exception) {
75
- logError(EVENT_BRIDGE_ERROR, ex, "action" to "initialize")
76
- }
51
+ private fun reject(promise: Promise, error: Throwable) {
52
+ val code = (error as? LiveVoiceException)?.code?.value ?: "generic"
53
+ promise.reject(code, LiveVoiceWrapperBridge.errorJSON(error), error)
77
54
  }
78
55
 
79
- /**
80
- * Forward the SDK's serialized state and events to JS. The SDK owns the JSON serialization
81
- * (see [LiveVoiceSerialization]) so the wire format is identical across Android and iOS.
82
- */
83
- private fun launchObservations(activity: AppCompatActivity) {
84
- activity.lifecycleScope.launch {
85
- LiveVoiceSerialization.viewState.collect { emitOnUiStateChanged(it) }
86
- }
87
- activity.lifecycleScope.launch {
88
- LiveVoiceSerialization.audioOutputIsSpeaker.collect { emitOnAudioOutputChanged(it) }
89
- }
90
- activity.lifecycleScope.launch {
91
- LiveVoiceSerialization.availableSubtitles.collect { emitOnAvailableSubtitleConfigsChanged(it) }
92
- }
93
- activity.lifecycleScope.launch {
94
- LiveVoiceSerialization.subtitles.collect { emitOnSubtitlesChanged(it) }
95
- }
96
- activity.lifecycleScope.launch {
97
- LiveVoiceSerialization.subtitleState.collect { emitOnSubtitleStateChanged(it) }
98
- }
56
+ private fun reject(promise: Promise, code: LiveVoiceErrorCode) {
57
+ promise.reject(code.value, LiveVoiceWrapperBridge.errorJSON(code, reactApplicationContext))
99
58
  }
100
59
 
101
- override fun startChannel(id: Double) =
102
- whenConnected("startChannel") { LiveVoice.startChannel(id.toLong()) }
60
+ /** The attached bridge, attaching it first; `null` once the runtime went away. */
61
+ private fun attachedBridge(): LiveVoiceWrapperBridge? {
62
+ if (invalidated) return null
63
+ bridge?.let { return it }
64
+ val owner = LiveVoiceWrapperBridge.attach()
65
+ bridge = owner
66
+ launchObservations(owner)
67
+ return owner
68
+ }
103
69
 
104
- override fun stopChannel() {
105
- val ready = LiveVoice.uiState.value as? Ready ?: run {
106
- logWarn(EVENT_ACTION_IGNORED, "action" to "stopChannel", "reason" to "wrongState")
107
- return
70
+ // The configuration is the JSON object of bridge.md 3.2; the SDK applies it, initializing itself
71
+ // with the application context and this wrapper's identity.
72
+ override fun initialize(configuration: String, promise: Promise) { UiThreadUtil.runOnUiThread {
73
+ val owner = attachedBridge()
74
+ if (owner == null || !owner.isCurrent) { reject(promise, LiveVoiceErrorCode.CANCELLED); return@runOnUiThread }
75
+ val version = ReactNativeVersion.VERSION
76
+ owner.initializeReactNative(reactApplicationContext, Version.SDK_VERSION,
77
+ "${version["major"]}.${version["minor"]}.${version["patch"]}", configuration) { result ->
78
+ result.fold({ promise.resolve(it) }, { reject(promise, it) })
108
79
  }
109
- val channel = ready.channels.firstOrNull { it.playingState in listOf(Connecting, Playing) }
110
- ?: run {
111
- logWarn(EVENT_ACTION_IGNORED, "action" to "stopChannel", "reason" to "noActiveChannel")
112
- return
113
- }
80
+ } }
114
81
 
115
- whenConnected("stopChannel") { LiveVoice.stopChannel(channel.id) }
82
+ private fun launchObservations(owner: LiveVoiceWrapperBridge) {
83
+ scope.launch {
84
+ owner.invalidation.first { it }
85
+ invalidated = true
86
+ scope.coroutineContext[Job]?.cancel()
87
+ }
88
+ // Not replayed: collection starts here, before initialize, and ends with the bridge.
89
+ scope.launch { owner.logEntries.collect { emitOnLogEntry(it) } }
90
+ scope.launch { owner.states.collect { emitOnState(it) } }
91
+ scope.launch { owner.passwordRequests.collect { emitOnPasswordRequest(it) } }
92
+ scope.launch { owner.passwordRequestCancellations.collect { emitOnPasswordRequestCancelled(it) } }
93
+ scope.launch { owner.passwordStoreRequests.collect { emitOnPasswordStoreRequest(it) } }
94
+ }
95
+
96
+ override fun execute(command: String, arguments: String, promise: Promise) {
97
+ UiThreadUtil.runOnUiThread {
98
+ val owner = bridge
99
+ if (invalidated || owner?.isCurrent == false) {
100
+ reject(promise, LiveVoiceErrorCode.CANCELLED)
101
+ } else if (owner == null) {
102
+ reject(promise, LiveVoiceErrorCode.NOT_INITIALIZED)
103
+ } else owner.execute(command, arguments) { result ->
104
+ result.fold({ promise.resolve(it ?: "null") }, { reject(promise, it) })
105
+ }
106
+ }
116
107
  }
117
108
 
118
- override fun getCurrentUiState(): String = LiveVoiceSerialization.currentViewState()
119
-
120
- override fun getCurrentAudioState(): Boolean = LiveVoiceSerialization.currentAudioOutputIsSpeaker()
121
-
122
- override fun getCurrentSubtitles(): String = LiveVoiceSerialization.currentSubtitles()
123
-
124
- override fun getCurrentSubtitleState(): String = LiveVoiceSerialization.currentSubtitleState()
125
-
126
- override fun getCurrentAvailableSubtitleConfigs(): String =
127
- LiveVoiceSerialization.currentAvailableSubtitles()
128
-
129
- override fun getCurrentClaims(): String? = LiveVoiceSerialization.currentClaims()
109
+ override fun getErrorMessages(): String = LiveVoiceWrapperBridge.errorMessagesJSON(reactApplicationContext)
130
110
 
131
- override fun setLiveVoiceUseSpeaker(value: Boolean) {
132
- LiveVoice.changeOutput(value)
111
+ // Works before `initialize`: attaches the bridge first if needed, so the preference reaches the
112
+ // SDK and the snapshot later carries it. Ignored once the runtime went away.
113
+ override fun setAudioOutput(payload: String) {
114
+ UiThreadUtil.runOnUiThread { attachedBridge()?.setAudioOutput(payload) }
133
115
  }
134
116
 
135
- override fun startSubtitles(channelId: Double) = whenConnected("startSubtitles") {
136
- val nullableChannelId = if (channelId.toLong() == -1L) null else channelId.toLong()
137
- LiveVoice.startSubtitles(nullableChannelId)
117
+ override fun writeLogEntry(payload: String) {
118
+ LiveVoiceWrapperBridge.writeLogEntry(payload)
138
119
  }
139
120
 
140
- override fun stopSubtitles() = whenConnected("stopSubtitles") { LiveVoice.stopSubtitles() }
141
-
142
- override fun openLiveVoiceWebsite() {
143
- LiveVoice.openLiveVoiceWebsite()
121
+ override fun answerPasswordRequest(payload: String) {
122
+ UiThreadUtil.runOnUiThread { if (!invalidated) bridge?.answerPasswordRequest(payload) }
144
123
  }
145
124
 
146
- override fun getSdkVersion(): String = Version.SDK_VERSION
125
+ override fun answerPasswordStoreRequest(payload: String) {
126
+ UiThreadUtil.runOnUiThread { if (!invalidated) bridge?.answerPasswordStoreRequest(payload) }
127
+ }
147
128
 
148
- override fun joinEvent(joinCode: String, password: String?, apiKey: String) {
149
- val scope = (reactApplicationContext.currentActivity as? ComponentActivity)?.lifecycleScope
150
- ?: run {
151
- logError(EVENT_BRIDGE_ERROR, "action" to "joinEvent", "reason" to "missingActivity")
152
- error("Could not create scope to connect! activity: ${reactApplicationContext.currentActivity}")
153
- }
129
+ override fun setPasswordStore(payload: String) {
130
+ UiThreadUtil.runOnUiThread { if (!invalidated) bridge?.setPasswordStore(payload) }
131
+ }
154
132
 
155
- scope.launch {
156
- LiveVoice.joinEvent(joinCode, password, apiKey)
133
+ override fun invalidate() {
134
+ invalidated = true
135
+ bridge?.requestInvalidation()
136
+ UiThreadUtil.runOnUiThread {
137
+ bridge?.invalidate(); bridge = null
138
+ scope.coroutineContext[Job]?.cancel()
157
139
  }
140
+ super.invalidate()
158
141
  }
159
142
 
160
- override fun leaveEvent() {
161
- LiveVoice.leaveEvent()
143
+ override fun openLiveVoiceWebsite() {
144
+ LiveVoiceWrapperBridge.openLiveVoiceWebsite(reactApplicationContext)
162
145
  }
163
146
 
164
- override fun reconnect() = LiveVoice.reconnect()
147
+ override fun getSdkVersion(): String = Version.SDK_VERSION
148
+
149
+ override fun getNativeSdkVersion(): String = LiveVoice.sdkVersion
165
150
 
166
- override fun channelStatusOffline(): String = LiveVoice.translations.channelStatusOffline()
151
+ override fun channelStatusOffline(): String = LiveVoiceWrapperBridge.channelStatusOffline(reactApplicationContext)
167
152
 
168
- override fun noChannels(): String = LiveVoice.translations.noChannels()
153
+ override fun noChannels(): String = LiveVoiceWrapperBridge.noChannels(reactApplicationContext)
169
154
 
170
155
  override fun isAiChannelStatusMessage(): String =
171
- LiveVoice.translations.isAiChannelStatusMessage()
156
+ LiveVoiceWrapperBridge.isAiChannelStatusMessage(reactApplicationContext)
172
157
 
173
158
  override fun errorScreenRetrying(): String =
174
- LiveVoice.translations.errorScreenRetrying()
159
+ LiveVoiceWrapperBridge.errorScreenRetrying(reactApplicationContext)
175
160
 
176
161
  override fun errorScreenRetryingIn(seconds: Double): String =
177
- LiveVoice.translations.errorScreenRetryingIn(seconds.toLong())
178
-
179
- override fun sdkErrorGeneric(): String =
180
- LiveVoice.translations.sdkErrorGeneric()
181
-
182
- override fun sdkErrorInactive(): String =
183
- LiveVoice.translations.sdkErrorInactive()
184
-
185
- override fun sdkErrorInvalidApiKey(): String =
186
- LiveVoice.translations.sdkErrorInvalidApiKey()
187
-
188
- override fun sdkErrorListenerLimitReached(): String =
189
- LiveVoice.translations.sdkErrorListenerLimitReached()
190
-
191
- override fun sdkErrorNoNetwork(): String =
192
- LiveVoice.translations.sdkErrorNoNetwork()
193
-
194
- override fun sdkErrorNotFound(): String =
195
- LiveVoice.translations.sdkErrorNotFound()
196
-
197
- override fun sdkErrorRequestFailed(errorCode: Double): String =
198
- LiveVoice.translations.sdkErrorRequestFailed(errorCode.toInt())
199
-
200
- override fun sdkErrorWrongPassword(): String =
201
- LiveVoice.translations.sdkErrorWrongPassword()
162
+ LiveVoiceWrapperBridge.errorScreenRetryingIn(reactApplicationContext, seconds.toLong())
202
163
 
203
164
  override fun sdkNoMatchingChannels(): String =
204
- LiveVoice.translations.sdkNoMatchingChannels()
165
+ LiveVoiceWrapperBridge.sdkNoMatchingChannels(reactApplicationContext)
205
166
 
206
167
  override fun streamingByTitle(): String =
207
- LiveVoice.translations.streamingByTitle()
168
+ LiveVoiceWrapperBridge.streamingByTitle(reactApplicationContext)
208
169
 
209
170
  override fun errorRetryNowButton(): String =
210
- LiveVoice.translations.errorRetryNowButton()
171
+ LiveVoiceWrapperBridge.errorRetryNowButton(reactApplicationContext)
211
172
 
212
173
  override fun accessibilityChannelPlay(): String =
213
- LiveVoice.translations.accessibilityChannelPlay()
174
+ LiveVoiceWrapperBridge.accessibilityChannelPlay(reactApplicationContext)
214
175
 
215
176
  override fun accessibilityChannelStatusMuted(): String =
216
- LiveVoice.translations.accessibilityChannelStatusMuted()
177
+ LiveVoiceWrapperBridge.accessibilityChannelStatusMuted(reactApplicationContext)
217
178
 
218
179
  override fun accessibilityChannelStop(): String =
219
- LiveVoice.translations.accessibilityChannelStop()
180
+ LiveVoiceWrapperBridge.accessibilityChannelStop(reactApplicationContext)
220
181
 
182
+ override fun passwordPromptTitle(): String = LiveVoiceWrapperBridge.passwordPromptTitle(reactApplicationContext)
221
183
 
222
- /** Runs [block] against the connected SDK, logging instead of crashing if not connected. */
223
- private inline fun whenConnected(methodName: String, block: () -> Unit) {
224
- try {
225
- block()
226
- } catch (ex: SdkNotConnectedException) {
227
- logError(EVENT_BRIDGE_ERROR, ex, "action" to methodName, "reason" to "notConnected")
228
- }
229
- }
184
+ override fun passwordPromptChannelMessage(): String =
185
+ LiveVoiceWrapperBridge.passwordPromptChannelMessage(reactApplicationContext)
230
186
 
231
- private fun logInfo(event: String, vararg fields: Pair<String, Any?>) {
232
- Log.i(NAME, formatMessage(event, *fields))
233
- }
187
+ override fun passwordPromptEventMessage(): String =
188
+ LiveVoiceWrapperBridge.passwordPromptEventMessage(reactApplicationContext)
234
189
 
235
- private fun logWarn(event: String, vararg fields: Pair<String, Any?>) {
236
- Log.w(NAME, formatMessage(event, *fields))
237
- }
190
+ override fun passwordPromptWrongPassword(): String =
191
+ LiveVoiceWrapperBridge.passwordPromptWrongPassword(reactApplicationContext)
238
192
 
239
- private fun logError(event: String, vararg fields: Pair<String, Any?>) {
240
- Log.e(NAME, formatMessage(event, *fields))
241
- }
193
+ override fun passwordPromptField(): String = LiveVoiceWrapperBridge.passwordPromptField(reactApplicationContext)
242
194
 
243
- private fun logError(event: String, throwable: Throwable, vararg fields: Pair<String, Any?>) {
244
- Log.e(NAME, formatMessage(event, *fields), throwable)
245
- }
195
+ override fun passwordPromptCancelButton(): String =
196
+ LiveVoiceWrapperBridge.passwordPromptCancelButton(reactApplicationContext)
246
197
 
247
- private fun formatMessage(event: String, vararg fields: Pair<String, Any?>): String {
248
- val fieldText = fields
249
- .filter { it.second != null }
250
- .sortedBy { it.first }
251
- .joinToString(" ") { (key, value) -> "$key=$value" }
198
+ override fun passwordPromptChannelConfirmButton(): String =
199
+ LiveVoiceWrapperBridge.passwordPromptChannelConfirmButton(reactApplicationContext)
252
200
 
253
- return if (fieldText.isEmpty()) {
254
- event
255
- } else {
256
- "$event $fieldText"
257
- }
258
- }
201
+ override fun passwordPromptEventConfirmButton(): String =
202
+ LiveVoiceWrapperBridge.passwordPromptEventConfirmButton(reactApplicationContext)
259
203
 
260
204
  companion object {
261
- private const val EVENT_ACTION_IGNORED = "LV_ACTION_IGNORED"
262
- private const val EVENT_BRIDGE_ERROR = "LV_BRIDGE_ERROR"
263
- private const val EVENT_INIT = "LV_INIT"
264
205
  const val NAME = "LiveVoiceModule"
265
-
266
- /**
267
- * Sentinel the JS layer sends when the foreground service is enabled without a custom
268
- * message. Must stay in sync with `serviceEnabledWithDefaultMessage` in
269
- * `src/util/ForegroundServiceConfig.tsx`.
270
- */
271
- const val DEFAULT_MESSAGE_SENTINEL = "LV_NOTIFICATION_DEFAULT_MESSAGE"
272
206
  }
273
207
  }
@@ -15,6 +15,6 @@
15
15
  // Generated by tool/generate-native-versions.mjs from package.json.
16
16
  package io.livevoice.react
17
17
 
18
- object Version {
19
- const val SDK_VERSION = "2.0.1"
18
+ internal object Version {
19
+ const val SDK_VERSION = "3.0.0"
20
20
  }