livevoice-sdk-react-native 2.0.0 → 2.0.1
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.
- package/README.md +119 -7
- package/android/build.gradle +14 -3
- package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +89 -123
- package/android/src/main/java/io/livevoice/react/__SDK.kt +16 -2
- package/ios/LiveVoiceSdkReactNative.mm +110 -37
- package/ios/__SDK.h +16 -2
- package/lib/module/components/AudioOutputSwitchView.js +13 -13
- package/lib/module/components/AudioOutputSwitchView.js.map +1 -1
- package/lib/module/components/BrandingView.js +13 -11
- package/lib/module/components/BrandingView.js.map +1 -1
- package/lib/module/components/ChannelView.js +14 -11
- package/lib/module/components/ChannelView.js.map +1 -1
- package/lib/module/components/ErrorView.js +12 -10
- package/lib/module/components/ErrorView.js.map +1 -1
- package/lib/module/components/LiveVoiceView.js +141 -72
- package/lib/module/components/LiveVoiceView.js.map +1 -1
- package/lib/module/components/PlayButtonView.js +12 -10
- package/lib/module/components/PlayButtonView.js.map +1 -1
- package/lib/module/components/ReconnectingView.js +16 -13
- package/lib/module/components/ReconnectingView.js.map +1 -1
- package/lib/module/components/WarningView.js +12 -10
- package/lib/module/components/WarningView.js.map +1 -1
- package/lib/module/components/index.js +12 -10
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/index.js +14 -220
- package/lib/module/index.js.map +1 -1
- package/lib/module/sdk/LiveVoiceSdk.js +371 -0
- package/lib/module/sdk/LiveVoiceSdk.js.map +1 -0
- package/lib/module/sdk/LiveVoiceState.js +66 -0
- package/lib/module/sdk/LiveVoiceState.js.map +1 -0
- package/lib/module/specs/NativeLiveVoiceSdk.js +12 -10
- package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
- package/lib/module/util/Colors.js +12 -10
- package/lib/module/util/Colors.js.map +1 -1
- package/lib/module/util/ForegroundServiceConfig.js +21 -11
- package/lib/module/util/ForegroundServiceConfig.js.map +1 -1
- package/lib/module/util/PlayingState.js +12 -10
- package/lib/module/util/PlayingState.js.map +1 -1
- package/lib/module/util/Translations.js +12 -10
- package/lib/module/util/Translations.js.map +1 -1
- package/lib/module/util/logger.js +76 -0
- package/lib/module/util/logger.js.map +1 -0
- package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +1 -1
- package/lib/typescript/src/components/BrandingView.d.ts.map +1 -1
- package/lib/typescript/src/components/ChannelView.d.ts.map +1 -1
- package/lib/typescript/src/components/ErrorView.d.ts.map +1 -1
- package/lib/typescript/src/components/LiveVoiceView.d.ts +22 -0
- package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -1
- package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -1
- package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -1
- package/lib/typescript/src/components/WarningView.d.ts.map +1 -1
- package/lib/typescript/src/components/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -144
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts +210 -0
- package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -0
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts +12 -0
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -0
- package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts +3 -0
- package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -1
- package/lib/typescript/src/util/Colors.d.ts.map +1 -1
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +7 -0
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +1 -1
- package/lib/typescript/src/util/PlayingState.d.ts.map +1 -1
- package/lib/typescript/src/util/Translations.d.ts.map +1 -1
- package/lib/typescript/src/util/UIState.d.ts +22 -2
- package/lib/typescript/src/util/UIState.d.ts.map +1 -1
- package/lib/typescript/src/util/logger.d.ts +23 -0
- package/lib/typescript/src/util/logger.d.ts.map +1 -0
- package/livevoice-sdk-react-native.podspec +14 -14
- package/package.json +16 -7
- package/src/components/AudioOutputSwitchView.tsx +13 -13
- package/src/components/BrandingView.tsx +13 -11
- package/src/components/ChannelView.tsx +14 -11
- package/src/components/ErrorView.tsx +12 -10
- package/src/components/LiveVoiceView.tsx +183 -92
- package/src/components/PlayButtonView.tsx +12 -10
- package/src/components/ReconnectingView.tsx +20 -13
- package/src/components/WarningView.tsx +12 -10
- package/src/components/index.tsx +12 -10
- package/src/index.tsx +19 -252
- package/src/sdk/LiveVoiceSdk.ts +408 -0
- package/src/sdk/LiveVoiceState.ts +89 -0
- package/src/specs/NativeLiveVoiceSdk.ts +16 -10
- package/src/util/Colors.ts +12 -10
- package/src/util/ForegroundServiceConfig.tsx +21 -11
- package/src/util/PlayingState.ts +12 -10
- package/src/util/Translations.ts +12 -10
- package/src/util/UIState.ts +30 -13
- package/src/util/logger.ts +92 -0
- package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeLiveVoiceSdkSpec.java +0 -186
- package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -28
- package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec-generated.cpp +0 -235
- package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec.h +0 -31
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +0 -341
- package/android/src/main/java/io/livevoice/react/Mappings.kt +0 -85
- package/android/src/main/java/io/livevoice/react/NativeModels.kt +0 -79
package/README.md
CHANGED
|
@@ -1,13 +1,125 @@
|
|
|
1
|
-
#
|
|
1
|
+
# LiveVoice SDK for React Native
|
|
2
2
|
|
|
3
3
|
The React Native SDK for integrating the LiveVoice service into your app.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The LiveVoice SDK enables your app to browse and listen to your configured LiveVoice channels
|
|
8
|
-
well as present a channel's live subtitles
|
|
7
|
+
The LiveVoice SDK enables your app to browse and listen to your configured LiveVoice channels,
|
|
8
|
+
as well as present a channel's live subtitles where available.
|
|
9
9
|
|
|
10
|
-
Using the LiveVoice SDK requires an account with SDK access enabled. Depending on your
|
|
11
|
-
the SDK allows for hiding the LiveVoice branding or
|
|
12
|
-
information contact sdk-support@livevoice.io
|
|
13
|
-
personal API
|
|
10
|
+
Using the LiveVoice SDK requires an account with SDK access enabled. Depending on your
|
|
11
|
+
subscription, the SDK allows for hiding the LiveVoice branding or building a fully customized
|
|
12
|
+
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
|
|
14
|
+
https://livevoice.io/en/account/api.
|
|
15
|
+
|
|
16
|
+
## Features
|
|
17
|
+
|
|
18
|
+
- Browse and play the channels of a LiveVoice event
|
|
19
|
+
- Live subtitles where the channel provides them
|
|
20
|
+
- A drop-in `LiveVoiceView`, or a fully custom presentation with your own channel cells
|
|
21
|
+
- Audio output selection (speaker, receiver, headphones)
|
|
22
|
+
- Optional branding control and custom UI (subscription-dependent)
|
|
23
|
+
|
|
24
|
+
## Requirements
|
|
25
|
+
|
|
26
|
+
- React Native 0.80 or newer
|
|
27
|
+
- iOS 15.1 or newer
|
|
28
|
+
- Android 7.0 (API level 24) or newer
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
npm install livevoice-sdk-react-native
|
|
34
|
+
# or
|
|
35
|
+
yarn add livevoice-sdk-react-native
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
On iOS, install the native pods from your app's `ios/` directory:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
pod install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
import {
|
|
48
|
+
initialize,
|
|
49
|
+
joinEvent,
|
|
50
|
+
leaveEvent,
|
|
51
|
+
LiveVoiceView,
|
|
52
|
+
} from 'livevoice-sdk-react-native';
|
|
53
|
+
|
|
54
|
+
// Initialize the SDK once, early in your app's lifecycle.
|
|
55
|
+
initialize();
|
|
56
|
+
|
|
57
|
+
// Join an event to load its channels. Arguments: (joinCode, password, apiKey).
|
|
58
|
+
joinEvent('YOUR_JOIN_CODE', null /* no password */, 'YOUR_API_KEY');
|
|
59
|
+
|
|
60
|
+
// Render the drop-in UI anywhere in your component tree.
|
|
61
|
+
function Channels() {
|
|
62
|
+
return <LiveVoiceView />;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Leave the event when you no longer display any channels.
|
|
66
|
+
leaveEvent();
|
|
67
|
+
```
|
|
68
|
+
|
|
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.
|
|
72
|
+
|
|
73
|
+
### Custom channel cells
|
|
74
|
+
|
|
75
|
+
To render your own channel rows instead of the built-in ones, pass `renderChannel` to
|
|
76
|
+
`LiveVoiceView`.
|
|
77
|
+
|
|
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
|
+
```
|
|
97
|
+
|
|
98
|
+
### Android background playback
|
|
99
|
+
|
|
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`:
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import {
|
|
105
|
+
initialize,
|
|
106
|
+
serviceEnabledWithDefaultMessage,
|
|
107
|
+
serviceEnabledWithMessage,
|
|
108
|
+
} from 'livevoice-sdk-react-native';
|
|
109
|
+
|
|
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
|
+
```
|
|
116
|
+
|
|
117
|
+
## Examples and support
|
|
118
|
+
|
|
119
|
+
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.
|
|
122
|
+
|
|
123
|
+
## License
|
|
124
|
+
|
|
125
|
+
MIT
|
package/android/build.gradle
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
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
|
+
|
|
1
14
|
buildscript {
|
|
2
15
|
ext.LiveVoiceSdkReactNative = [
|
|
3
16
|
kotlinVersion: "2.0.21",
|
|
@@ -76,7 +89,6 @@ android {
|
|
|
76
89
|
project.repositories {
|
|
77
90
|
google()
|
|
78
91
|
mavenCentral()
|
|
79
|
-
maven { url "https://jitpack.io" }
|
|
80
92
|
maven { url "https://sdks.livevoice.io/android" }
|
|
81
93
|
}
|
|
82
94
|
}
|
|
@@ -84,9 +96,8 @@ android {
|
|
|
84
96
|
|
|
85
97
|
dependencies {
|
|
86
98
|
implementation "com.facebook.react:react-android"
|
|
87
|
-
implementation("io.livevoice.sdk:android:2.0.
|
|
99
|
+
implementation("io.livevoice.sdk:android:2.0.2") {
|
|
88
100
|
exclude group: 'org.jspecify', module: 'jspecify'
|
|
89
101
|
}
|
|
90
|
-
implementation("com.jakewharton.timber:timber:5.0.1")
|
|
91
102
|
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
|
|
92
103
|
}
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
package io.livevoice.react
|
|
15
15
|
|
|
16
|
-
import android.
|
|
16
|
+
import android.util.Log
|
|
17
17
|
import androidx.activity.ComponentActivity
|
|
18
18
|
import androidx.appcompat.app.AppCompatActivity
|
|
19
19
|
import androidx.lifecycle.lifecycleScope
|
|
@@ -22,37 +22,19 @@ import com.facebook.react.module.annotations.ReactModule
|
|
|
22
22
|
import com.facebook.react.modules.systeminfo.ReactNativeVersion
|
|
23
23
|
import io.livevoice.sdk.android.publicApi.core.LiveVoice
|
|
24
24
|
import io.livevoice.sdk.android.publicApi.core.model.ForegroundServiceConfig
|
|
25
|
-
import io.livevoice.sdk.android.publicApi.core.model.LiveVoiceOutput
|
|
26
25
|
import io.livevoice.sdk.android.publicApi.core.model.channel.LiveVoicePlayingState.Connecting
|
|
27
26
|
import io.livevoice.sdk.android.publicApi.core.model.channel.LiveVoicePlayingState.Playing
|
|
28
27
|
import io.livevoice.sdk.android.publicApi.core.model.NotificationText
|
|
29
28
|
import io.livevoice.sdk.android.publicApi.core.model.SdkPlatform
|
|
30
|
-
import io.livevoice.sdk.android.publicApi.core.model.subtitle.SdkSubtitleLanguage
|
|
31
|
-
import io.livevoice.sdk.android.publicApi.core.model.subtitle.SdkSubtitleState
|
|
32
|
-
import io.livevoice.sdk.android.publicApi.core.model.SdkUiState
|
|
33
29
|
import io.livevoice.sdk.android.publicApi.core.model.SdkUiState.Ready
|
|
34
|
-
import io.livevoice.sdk.android.publicApi.core.model.exceptions.
|
|
35
|
-
import
|
|
36
|
-
import kotlinx.coroutines.flow.collectLatest
|
|
30
|
+
import io.livevoice.sdk.android.publicApi.core.model.exceptions.SdkNotConnectedException
|
|
31
|
+
import io.livevoice.sdk.android.publicApi.serialization.LiveVoiceSerialization
|
|
37
32
|
import kotlinx.coroutines.launch
|
|
38
|
-
import kotlinx.serialization.ExperimentalSerializationApi
|
|
39
|
-
import kotlinx.serialization.json.ClassDiscriminatorMode
|
|
40
|
-
import kotlinx.serialization.json.Json
|
|
41
|
-
import timber.log.Timber
|
|
42
33
|
|
|
43
|
-
@SuppressLint("LogNotTimber")
|
|
44
34
|
@ReactModule(name = LiveVoiceModule.NAME)
|
|
45
35
|
class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
46
36
|
NativeLiveVoiceSdkSpec(reactContext) {
|
|
47
37
|
|
|
48
|
-
private val timber = Timber.tag("[SDK]")
|
|
49
|
-
|
|
50
|
-
@OptIn(ExperimentalSerializationApi::class)
|
|
51
|
-
private val json = Json {
|
|
52
|
-
classDiscriminator = "type"
|
|
53
|
-
classDiscriminatorMode = ClassDiscriminatorMode.ALL_JSON_OBJECTS
|
|
54
|
-
}
|
|
55
|
-
|
|
56
38
|
override fun getName(): String {
|
|
57
39
|
return NAME
|
|
58
40
|
}
|
|
@@ -60,15 +42,14 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
60
42
|
override fun initialize(androidServiceConfig: String?) {
|
|
61
43
|
val parsedServiceConfig = when (androidServiceConfig) {
|
|
62
44
|
null -> ForegroundServiceConfig.Disabled
|
|
63
|
-
|
|
45
|
+
DEFAULT_MESSAGE_SENTINEL -> ForegroundServiceConfig.enabledWithDefaultMessage
|
|
64
46
|
else -> ForegroundServiceConfig.Enabled(NotificationText.RawValue(androidServiceConfig))
|
|
65
47
|
}
|
|
66
48
|
|
|
67
|
-
Timber.plant(Timber.DebugTree())
|
|
68
49
|
try {
|
|
69
50
|
val activity: AppCompatActivity =
|
|
70
51
|
currentActivity as? AppCompatActivity ?: run {
|
|
71
|
-
|
|
52
|
+
logError(EVENT_BRIDGE_ERROR, "action" to "initialize", "reason" to "missingActivity")
|
|
72
53
|
return
|
|
73
54
|
}
|
|
74
55
|
|
|
@@ -85,139 +66,91 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
85
66
|
)
|
|
86
67
|
)
|
|
87
68
|
|
|
88
|
-
|
|
69
|
+
logInfo(EVENT_INIT, "platformVersion" to reactVersion)
|
|
89
70
|
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
launchOutputModeObservation(activity)
|
|
93
|
-
launchAvailableSubtitleObservation(activity)
|
|
71
|
+
//forward serialized state and events from the SDK
|
|
72
|
+
launchObservations(activity)
|
|
94
73
|
|
|
95
74
|
} catch (ex: Exception) {
|
|
96
|
-
|
|
75
|
+
logError(EVENT_BRIDGE_ERROR, ex, "action" to "initialize")
|
|
97
76
|
}
|
|
98
77
|
}
|
|
99
78
|
|
|
100
|
-
|
|
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) {
|
|
101
84
|
activity.lifecycleScope.launch {
|
|
102
|
-
|
|
103
|
-
val uiStateString = json.encodeToString(newState.mapToTransferable())
|
|
104
|
-
timber.d("New state %s", uiStateString)
|
|
105
|
-
|
|
106
|
-
emitOnUiStateChanged(uiStateString) //it's there, even if intelliJ doesn't highlight it!
|
|
107
|
-
}
|
|
85
|
+
LiveVoiceSerialization.viewState.collect { emitOnUiStateChanged(it) }
|
|
108
86
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
private fun launchOutputModeObservation(activity: AppCompatActivity) {
|
|
112
87
|
activity.lifecycleScope.launch {
|
|
113
|
-
|
|
114
|
-
emitOnAudioOutputChanged(newOutputMode == LiveVoiceOutput.SPEAKER)
|
|
115
|
-
}
|
|
88
|
+
LiveVoiceSerialization.audioOutputIsSpeaker.collect { emitOnAudioOutputChanged(it) }
|
|
116
89
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
private fun launchAvailableSubtitleObservation(activity: AppCompatActivity) {
|
|
120
90
|
activity.lifecycleScope.launch {
|
|
121
|
-
|
|
122
|
-
val encodedSubtitles = json.encodeToString(subtitles.map { it.mapToNative() })
|
|
123
|
-
emitOnAvailableSubtitleConfigsChanged(encodedSubtitles)
|
|
124
|
-
}
|
|
91
|
+
LiveVoiceSerialization.availableSubtitles.collect { emitOnAvailableSubtitleConfigsChanged(it) }
|
|
125
92
|
}
|
|
126
93
|
activity.lifecycleScope.launch {
|
|
127
|
-
emitOnSubtitlesChanged(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
//forward/emit all subtitle fragments that arrive!
|
|
132
|
-
state.fragments.collect { fragments: List<String> ->
|
|
133
|
-
emitOnSubtitlesChanged(json.encodeToString(fragments))
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
94
|
+
LiveVoiceSerialization.subtitles.collect { emitOnSubtitlesChanged(it) }
|
|
95
|
+
}
|
|
96
|
+
activity.lifecycleScope.launch {
|
|
97
|
+
LiveVoiceSerialization.subtitleState.collect { emitOnSubtitleStateChanged(it) }
|
|
137
98
|
}
|
|
138
99
|
}
|
|
139
100
|
|
|
140
|
-
override fun startChannel(id: Double)
|
|
141
|
-
|
|
142
|
-
val longId = id.toLong()
|
|
143
|
-
|
|
144
|
-
timber.d("calling startChannel($longId)")
|
|
145
|
-
state.onStartChannel(longId)
|
|
146
|
-
}
|
|
101
|
+
override fun startChannel(id: Double) =
|
|
102
|
+
whenConnected("startChannel") { LiveVoice.startChannel(id.toLong()) }
|
|
147
103
|
|
|
148
104
|
override fun stopChannel() {
|
|
149
|
-
val
|
|
150
|
-
|
|
105
|
+
val ready = LiveVoice.uiState.value as? Ready ?: run {
|
|
106
|
+
logWarn(EVENT_ACTION_IGNORED, "action" to "stopChannel", "reason" to "wrongState")
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
val channel = ready.channels.firstOrNull { it.playingState in listOf(Connecting, Playing) }
|
|
151
110
|
?: run {
|
|
152
|
-
|
|
111
|
+
logWarn(EVENT_ACTION_IGNORED, "action" to "stopChannel", "reason" to "noActiveChannel")
|
|
153
112
|
return
|
|
154
113
|
}
|
|
155
114
|
|
|
156
|
-
|
|
157
|
-
state.onStopChannel(channel.id)
|
|
115
|
+
whenConnected("stopChannel") { LiveVoice.stopChannel(channel.id) }
|
|
158
116
|
}
|
|
159
117
|
|
|
160
|
-
override fun getCurrentUiState(): String
|
|
161
|
-
return try {
|
|
162
|
-
timber.d("Getting current ui-state")
|
|
163
|
-
val currentState: SdkUiState = LiveVoice.uiState.value
|
|
164
|
-
json.encodeToString(currentState.mapToTransferable())
|
|
165
|
-
} catch (ex: Exception) {
|
|
166
|
-
timber.w(ex, "Tried accessing state without prior initialization, returning default!")
|
|
167
|
-
json.encodeToString(NativeLoading)
|
|
168
|
-
}
|
|
169
|
-
}
|
|
118
|
+
override fun getCurrentUiState(): String = LiveVoiceSerialization.currentViewState()
|
|
170
119
|
|
|
171
|
-
override fun getCurrentAudioState(): Boolean
|
|
172
|
-
return try {
|
|
173
|
-
LiveVoice.outputMode.value == LiveVoiceOutput.SPEAKER
|
|
174
|
-
} catch (ex: Exception) {
|
|
175
|
-
timber.w(ex, "Tried accessing audio state without prior initialization, returning default!")
|
|
176
|
-
false
|
|
177
|
-
}
|
|
178
|
-
}
|
|
120
|
+
override fun getCurrentAudioState(): Boolean = LiveVoiceSerialization.currentAudioOutputIsSpeaker()
|
|
179
121
|
|
|
180
|
-
override fun getCurrentSubtitles(): String
|
|
181
|
-
val value = LiveVoice.subtitleState.value
|
|
182
|
-
if (value !is SdkSubtitleState.Enabled) return "[]"
|
|
122
|
+
override fun getCurrentSubtitles(): String = LiveVoiceSerialization.currentSubtitles()
|
|
183
123
|
|
|
184
|
-
|
|
185
|
-
}
|
|
124
|
+
override fun getCurrentSubtitleState(): String = LiveVoiceSerialization.currentSubtitleState()
|
|
186
125
|
|
|
187
|
-
override fun getCurrentAvailableSubtitleConfigs(): String
|
|
188
|
-
|
|
189
|
-
return json.encodeToString(value.map { it.mapToNative() })
|
|
190
|
-
}
|
|
126
|
+
override fun getCurrentAvailableSubtitleConfigs(): String =
|
|
127
|
+
LiveVoiceSerialization.currentAvailableSubtitles()
|
|
191
128
|
|
|
192
|
-
override fun getCurrentClaims(): String?
|
|
193
|
-
val claims = LiveVoice.claims.value
|
|
194
|
-
return json.encodeToString(claims ?: return null)
|
|
195
|
-
}
|
|
129
|
+
override fun getCurrentClaims(): String? = LiveVoiceSerialization.currentClaims()
|
|
196
130
|
|
|
197
131
|
override fun setLiveVoiceUseSpeaker(value: Boolean) {
|
|
198
132
|
LiveVoice.changeOutput(value)
|
|
199
133
|
}
|
|
200
134
|
|
|
201
|
-
override fun startSubtitles(channelId: Double) {
|
|
202
|
-
val state = getStateOrNull<Ready>("startSubtitles") ?: return
|
|
203
|
-
val sdkSubtitleLanguage = SdkSubtitleLanguage.Transcript
|
|
204
|
-
|
|
135
|
+
override fun startSubtitles(channelId: Double) = whenConnected("startSubtitles") {
|
|
205
136
|
val nullableChannelId = if (channelId.toLong() == -1L) null else channelId.toLong()
|
|
206
|
-
|
|
137
|
+
LiveVoice.startSubtitles(nullableChannelId)
|
|
207
138
|
}
|
|
208
139
|
|
|
209
|
-
override fun stopSubtitles() {
|
|
210
|
-
val state = getStateOrNull<Ready>("stopSubtitles") ?: return
|
|
211
|
-
state.onStopSubtitles()
|
|
212
|
-
}
|
|
140
|
+
override fun stopSubtitles() = whenConnected("stopSubtitles") { LiveVoice.stopSubtitles() }
|
|
213
141
|
|
|
214
142
|
override fun openLiveVoiceWebsite() {
|
|
215
143
|
LiveVoice.openLiveVoiceWebsite()
|
|
216
144
|
}
|
|
217
145
|
|
|
146
|
+
override fun getSdkVersion(): String = Version.SDK_VERSION
|
|
147
|
+
|
|
218
148
|
override fun joinEvent(joinCode: String, password: String?, apiKey: String) {
|
|
219
149
|
val scope = (reactApplicationContext.currentActivity as? ComponentActivity)?.lifecycleScope
|
|
220
|
-
?:
|
|
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
|
+
}
|
|
221
154
|
|
|
222
155
|
scope.launch {
|
|
223
156
|
LiveVoice.joinEvent(joinCode, password, apiKey)
|
|
@@ -286,22 +219,55 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
286
219
|
LiveVoice.translations.accessibilityChannelStop()
|
|
287
220
|
|
|
288
221
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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")
|
|
295
228
|
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private fun logInfo(event: String, vararg fields: Pair<String, Any?>) {
|
|
232
|
+
Log.i(NAME, formatMessage(event, *fields))
|
|
233
|
+
}
|
|
296
234
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
235
|
+
private fun logWarn(event: String, vararg fields: Pair<String, Any?>) {
|
|
236
|
+
Log.w(NAME, formatMessage(event, *fields))
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
private fun logError(event: String, vararg fields: Pair<String, Any?>) {
|
|
240
|
+
Log.e(NAME, formatMessage(event, *fields))
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private fun logError(event: String, throwable: Throwable, vararg fields: Pair<String, Any?>) {
|
|
244
|
+
Log.e(NAME, formatMessage(event, *fields), throwable)
|
|
245
|
+
}
|
|
246
|
+
|
|
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" }
|
|
252
|
+
|
|
253
|
+
return if (fieldText.isEmpty()) {
|
|
254
|
+
event
|
|
255
|
+
} else {
|
|
256
|
+
"$event $fieldText"
|
|
300
257
|
}
|
|
301
|
-
return state
|
|
302
258
|
}
|
|
303
259
|
|
|
304
260
|
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"
|
|
305
264
|
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"
|
|
306
272
|
}
|
|
307
273
|
}
|
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
14
|
+
// GENERATED CODE - DO NOT MODIFY BY HAND.
|
|
15
|
+
// Generated by tool/generate-native-versions.mjs from package.json.
|
|
2
16
|
package io.livevoice.react
|
|
3
17
|
|
|
4
18
|
object Version {
|
|
5
|
-
const val SDK_VERSION = "2.0.
|
|
19
|
+
const val SDK_VERSION = "2.0.1"
|
|
6
20
|
}
|