livevoice-sdk-react-native 1.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/LICENSE +20 -0
- package/README.md +13 -0
- package/android/build.gradle +135 -0
- package/android/generated/java/io/livevoice/react/NativeLiveVoiceSdkSpec.java +182 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNLiveVoiceSpec-generated.cpp +229 -0
- package/android/generated/jni/RNLiveVoiceSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI-generated.cpp +238 -0
- package/android/generated/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +389 -0
- package/android/gradle.properties +7 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +293 -0
- package/android/src/main/java/io/livevoice/react/LiveVoiceSdkReactNativePackage.kt +45 -0
- package/android/src/main/java/io/livevoice/react/Mappings.kt +54 -0
- package/android/src/main/java/io/livevoice/react/NativeModels.kt +77 -0
- package/ios/LiveVoiceSdkReactNative.h +21 -0
- package/ios/LivevoiceSdkReactNative.mm +234 -0
- package/ios/generated/RNLiveVoiceSpec/RNLiveVoiceSpec-generated.mm +285 -0
- package/ios/generated/RNLiveVoiceSpec/RNLiveVoiceSpec.h +100 -0
- package/ios/generated/RNLiveVoiceSpecJSI-generated.cpp +238 -0
- package/ios/generated/RNLiveVoiceSpecJSI.h +389 -0
- package/lib/commonjs/components/AudioOutputSwitchView.js +140 -0
- package/lib/commonjs/components/AudioOutputSwitchView.js.map +1 -0
- package/lib/commonjs/components/BrandingView.js +78 -0
- package/lib/commonjs/components/BrandingView.js.map +1 -0
- package/lib/commonjs/components/ChannelView.js +117 -0
- package/lib/commonjs/components/ChannelView.js.map +1 -0
- package/lib/commonjs/components/ErrorView.js +88 -0
- package/lib/commonjs/components/ErrorView.js.map +1 -0
- package/lib/commonjs/components/LiveVoiceView.js +95 -0
- package/lib/commonjs/components/LiveVoiceView.js.map +1 -0
- package/lib/commonjs/components/PlayButtonView.js +161 -0
- package/lib/commonjs/components/PlayButtonView.js.map +1 -0
- package/lib/commonjs/components/ReconnectingView.js +109 -0
- package/lib/commonjs/components/ReconnectingView.js.map +1 -0
- package/lib/commonjs/components/WarningView.js +58 -0
- package/lib/commonjs/components/WarningView.js.map +1 -0
- package/lib/commonjs/components/index.js +94 -0
- package/lib/commonjs/components/index.js.map +1 -0
- package/lib/commonjs/icons/branding.png +0 -0
- package/lib/commonjs/icons/cpu.png +0 -0
- package/lib/commonjs/icons/headphones.png +0 -0
- package/lib/commonjs/icons/mic.png +0 -0
- package/lib/commonjs/icons/pause.png +0 -0
- package/lib/commonjs/icons/play.png +0 -0
- package/lib/commonjs/icons/speaker.png +0 -0
- package/lib/commonjs/index.js +310 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/specs/NativeLiveVoiceSdk.js +19 -0
- package/lib/commonjs/specs/NativeLiveVoiceSdk.js.map +1 -0
- package/lib/commonjs/util/Colors.js +30 -0
- package/lib/commonjs/util/Colors.js.map +1 -0
- package/lib/commonjs/util/ForegroundServiceConfig.js +33 -0
- package/lib/commonjs/util/ForegroundServiceConfig.js.map +1 -0
- package/lib/commonjs/util/PlayingState.js +24 -0
- package/lib/commonjs/util/PlayingState.js.map +1 -0
- package/lib/commonjs/util/Translations.js +47 -0
- package/lib/commonjs/util/Translations.js.map +1 -0
- package/lib/commonjs/util/UIState.js +6 -0
- package/lib/commonjs/util/UIState.js.map +1 -0
- package/lib/module/components/AudioOutputSwitchView.js +134 -0
- package/lib/module/components/AudioOutputSwitchView.js.map +1 -0
- package/lib/module/components/BrandingView.js +72 -0
- package/lib/module/components/BrandingView.js.map +1 -0
- package/lib/module/components/ChannelView.js +110 -0
- package/lib/module/components/ChannelView.js.map +1 -0
- package/lib/module/components/ErrorView.js +82 -0
- package/lib/module/components/ErrorView.js.map +1 -0
- package/lib/module/components/LiveVoiceView.js +90 -0
- package/lib/module/components/LiveVoiceView.js.map +1 -0
- package/lib/module/components/PlayButtonView.js +156 -0
- package/lib/module/components/PlayButtonView.js.map +1 -0
- package/lib/module/components/ReconnectingView.js +103 -0
- package/lib/module/components/ReconnectingView.js.map +1 -0
- package/lib/module/components/WarningView.js +52 -0
- package/lib/module/components/WarningView.js.map +1 -0
- package/lib/module/components/index.js +22 -0
- package/lib/module/components/index.js.map +1 -0
- package/lib/module/icons/branding.png +0 -0
- package/lib/module/icons/cpu.png +0 -0
- package/lib/module/icons/headphones.png +0 -0
- package/lib/module/icons/mic.png +0 -0
- package/lib/module/icons/pause.png +0 -0
- package/lib/module/icons/play.png +0 -0
- package/lib/module/icons/speaker.png +0 -0
- package/lib/module/index.js +215 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/NativeLiveVoiceSdk.js +16 -0
- package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -0
- package/lib/module/util/Colors.js +26 -0
- package/lib/module/util/Colors.js.map +1 -0
- package/lib/module/util/ForegroundServiceConfig.js +28 -0
- package/lib/module/util/ForegroundServiceConfig.js.map +1 -0
- package/lib/module/util/PlayingState.js +21 -0
- package/lib/module/util/PlayingState.js.map +1 -0
- package/lib/module/util/Translations.js +41 -0
- package/lib/module/util/Translations.js.map +1 -0
- package/lib/module/util/UIState.js +4 -0
- package/lib/module/util/UIState.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/components/AudioOutputSwitchView.d.ts +6 -0
- package/lib/typescript/commonjs/src/components/AudioOutputSwitchView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/BrandingView.d.ts +6 -0
- package/lib/typescript/commonjs/src/components/BrandingView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/ChannelView.d.ts +13 -0
- package/lib/typescript/commonjs/src/components/ChannelView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/ErrorView.d.ts +9 -0
- package/lib/typescript/commonjs/src/components/ErrorView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/LiveVoiceView.d.ts +6 -0
- package/lib/typescript/commonjs/src/components/LiveVoiceView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/PlayButtonView.d.ts +146 -0
- package/lib/typescript/commonjs/src/components/PlayButtonView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/ReconnectingView.d.ts +9 -0
- package/lib/typescript/commonjs/src/components/ReconnectingView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/WarningView.d.ts +8 -0
- package/lib/typescript/commonjs/src/components/WarningView.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/components/index.d.ts +9 -0
- package/lib/typescript/commonjs/src/components/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +129 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/specs/NativeLiveVoiceSdk.d.ts +47 -0
- package/lib/typescript/commonjs/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util/Colors.d.ts +13 -0
- package/lib/typescript/commonjs/src/util/Colors.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util/ForegroundServiceConfig.d.ts +12 -0
- package/lib/typescript/commonjs/src/util/ForegroundServiceConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util/PlayingState.d.ts +7 -0
- package/lib/typescript/commonjs/src/util/PlayingState.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util/Translations.d.ts +22 -0
- package/lib/typescript/commonjs/src/util/Translations.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/util/UIState.d.ts +45 -0
- package/lib/typescript/commonjs/src/util/UIState.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/components/AudioOutputSwitchView.d.ts +6 -0
- package/lib/typescript/module/src/components/AudioOutputSwitchView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/BrandingView.d.ts +6 -0
- package/lib/typescript/module/src/components/BrandingView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/ChannelView.d.ts +13 -0
- package/lib/typescript/module/src/components/ChannelView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/ErrorView.d.ts +9 -0
- package/lib/typescript/module/src/components/ErrorView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/LiveVoiceView.d.ts +6 -0
- package/lib/typescript/module/src/components/LiveVoiceView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/PlayButtonView.d.ts +146 -0
- package/lib/typescript/module/src/components/PlayButtonView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/ReconnectingView.d.ts +9 -0
- package/lib/typescript/module/src/components/ReconnectingView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/WarningView.d.ts +8 -0
- package/lib/typescript/module/src/components/WarningView.d.ts.map +1 -0
- package/lib/typescript/module/src/components/index.d.ts +9 -0
- package/lib/typescript/module/src/components/index.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +129 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/specs/NativeLiveVoiceSdk.d.ts +47 -0
- package/lib/typescript/module/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -0
- package/lib/typescript/module/src/util/Colors.d.ts +13 -0
- package/lib/typescript/module/src/util/Colors.d.ts.map +1 -0
- package/lib/typescript/module/src/util/ForegroundServiceConfig.d.ts +12 -0
- package/lib/typescript/module/src/util/ForegroundServiceConfig.d.ts.map +1 -0
- package/lib/typescript/module/src/util/PlayingState.d.ts +7 -0
- package/lib/typescript/module/src/util/PlayingState.d.ts.map +1 -0
- package/lib/typescript/module/src/util/Translations.d.ts +22 -0
- package/lib/typescript/module/src/util/Translations.d.ts.map +1 -0
- package/lib/typescript/module/src/util/UIState.d.ts +45 -0
- package/lib/typescript/module/src/util/UIState.d.ts.map +1 -0
- package/livevoice-sdk-react-native.podspec +58 -0
- package/package.json +207 -0
- package/react-native.config.js +12 -0
- package/src/components/AudioOutputSwitchView.tsx +145 -0
- package/src/components/BrandingView.tsx +66 -0
- package/src/components/ChannelView.tsx +99 -0
- package/src/components/ErrorView.tsx +89 -0
- package/src/components/LiveVoiceView.tsx +120 -0
- package/src/components/PlayButtonView.tsx +181 -0
- package/src/components/ReconnectingView.tsx +133 -0
- package/src/components/WarningView.tsx +60 -0
- package/src/components/index.tsx +19 -0
- package/src/icons/branding.png +0 -0
- package/src/icons/cpu.png +0 -0
- package/src/icons/headphones.png +0 -0
- package/src/icons/mic.png +0 -0
- package/src/icons/pause.png +0 -0
- package/src/icons/play.png +0 -0
- package/src/icons/speaker.png +0 -0
- package/src/index.tsx +221 -0
- package/src/specs/NativeLiveVoiceSdk.ts +75 -0
- package/src/util/Colors.ts +27 -0
- package/src/util/ForegroundServiceConfig.tsx +32 -0
- package/src/util/PlayingState.ts +18 -0
- package/src/util/Translations.ts +39 -0
- package/src/util/UIState.ts +65 -0
|
@@ -0,0 +1,293 @@
|
|
|
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
|
+
package io.livevoice.react
|
|
15
|
+
|
|
16
|
+
import android.annotation.SuppressLint
|
|
17
|
+
import androidx.activity.ComponentActivity
|
|
18
|
+
import androidx.appcompat.app.AppCompatActivity
|
|
19
|
+
import androidx.lifecycle.lifecycleScope
|
|
20
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
21
|
+
import com.facebook.react.module.annotations.ReactModule
|
|
22
|
+
import io.livevoice.sdk.android.publicApi.core.LiveVoice
|
|
23
|
+
import io.livevoice.sdk.android.publicApi.core.model.ForegroundServiceConfig
|
|
24
|
+
import io.livevoice.sdk.android.publicApi.core.model.LiveVoiceOutput
|
|
25
|
+
import io.livevoice.sdk.android.publicApi.core.model.LiveVoicePlayingState.CONNECTING
|
|
26
|
+
import io.livevoice.sdk.android.publicApi.core.model.LiveVoicePlayingState.PLAYING
|
|
27
|
+
import io.livevoice.sdk.android.publicApi.core.model.NotificationText
|
|
28
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkSubtitleLanguage
|
|
29
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkSubtitleState
|
|
30
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkUiState
|
|
31
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkUiState.Ready
|
|
32
|
+
import io.livevoice.sdk.android.publicApi.core.model.exceptions.SdkUninitializedException
|
|
33
|
+
import kotlinx.coroutines.flow.collectLatest
|
|
34
|
+
import kotlinx.coroutines.launch
|
|
35
|
+
import kotlinx.serialization.ExperimentalSerializationApi
|
|
36
|
+
import kotlinx.serialization.json.ClassDiscriminatorMode
|
|
37
|
+
import kotlinx.serialization.json.Json
|
|
38
|
+
import timber.log.Timber
|
|
39
|
+
|
|
40
|
+
@SuppressLint("LogNotTimber")
|
|
41
|
+
@ReactModule(name = LiveVoiceModule.NAME)
|
|
42
|
+
class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
43
|
+
NativeLiveVoiceSdkSpec(reactContext) {
|
|
44
|
+
|
|
45
|
+
private val timber = Timber.tag("[SDK]")
|
|
46
|
+
|
|
47
|
+
@OptIn(ExperimentalSerializationApi::class)
|
|
48
|
+
private val json = Json {
|
|
49
|
+
classDiscriminator = "type"
|
|
50
|
+
classDiscriminatorMode = ClassDiscriminatorMode.ALL_JSON_OBJECTS
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun getName(): String {
|
|
54
|
+
return NAME
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
override fun initialize(androidServiceConfig: String?) {
|
|
58
|
+
val parsedServiceConfig = when (androidServiceConfig) {
|
|
59
|
+
null -> ForegroundServiceConfig.Disabled
|
|
60
|
+
"DEFAULT_MESSAGE" -> ForegroundServiceConfig.enabledWithDefaultMessage
|
|
61
|
+
else -> ForegroundServiceConfig.Enabled(NotificationText.RawValue(androidServiceConfig))
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Timber.plant(Timber.DebugTree())
|
|
65
|
+
try {
|
|
66
|
+
val activity: AppCompatActivity =
|
|
67
|
+
currentActivity as? AppCompatActivity ?: run {
|
|
68
|
+
timber.e("initialize failed: currentActivity null or not an AppCompatActivity")
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//initialize SDK
|
|
73
|
+
LiveVoice.initializeLiveVoice(
|
|
74
|
+
applicationContext = activity,
|
|
75
|
+
foregroundServiceConfig = parsedServiceConfig
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
timber.d("finished initializing")
|
|
79
|
+
|
|
80
|
+
//observe ui-state changes
|
|
81
|
+
launchUiStateObservation(activity)
|
|
82
|
+
launchOutputModeObservation(activity)
|
|
83
|
+
launchAvailableSubtitleObservation(activity)
|
|
84
|
+
|
|
85
|
+
} catch (ex: Exception) {
|
|
86
|
+
timber.e(ex, "initialize failed")
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
private fun launchUiStateObservation(activity: AppCompatActivity) {
|
|
91
|
+
activity.lifecycleScope.launch {
|
|
92
|
+
LiveVoice.uiState.collect { newState: SdkUiState ->
|
|
93
|
+
val uiStateString = json.encodeToString(newState.mapToTransferable())
|
|
94
|
+
timber.d("New state %s", uiStateString)
|
|
95
|
+
|
|
96
|
+
emitOnUiStateChanged(uiStateString) //it's there, even if intelliJ doesn't highlight it!
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private fun launchOutputModeObservation(activity: AppCompatActivity) {
|
|
102
|
+
activity.lifecycleScope.launch {
|
|
103
|
+
LiveVoice.outputMode.collect { newOutputMode: LiveVoiceOutput ->
|
|
104
|
+
emitOnAudioOutputChanged(newOutputMode == LiveVoiceOutput.SPEAKER)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private fun launchAvailableSubtitleObservation(activity: AppCompatActivity) {
|
|
110
|
+
activity.lifecycleScope.launch {
|
|
111
|
+
emitOnSubtitlesChanged("[]")
|
|
112
|
+
//collectLatest will cancel previous lambda when new subtitleState arrives
|
|
113
|
+
LiveVoice.subtitleState.collectLatest { state: SdkSubtitleState ->
|
|
114
|
+
val encodedSubtitles = json.encodeToString(state.availableSubtitles)
|
|
115
|
+
emitOnAvailableSubtitleConfigsChanged(encodedSubtitles)
|
|
116
|
+
|
|
117
|
+
if (state is SdkSubtitleState.Enabled) {
|
|
118
|
+
//forward/emit all subtitle fragments that arrive!
|
|
119
|
+
state.fragments.collect { fragments: List<String> ->
|
|
120
|
+
emitOnSubtitlesChanged(json.encodeToString(fragments))
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
override fun startChannel(id: Double) {
|
|
128
|
+
val state = getStateOrNull<Ready>("startChannel") ?: return
|
|
129
|
+
val longId = id.toLong()
|
|
130
|
+
|
|
131
|
+
timber.d("calling startChannel($longId)")
|
|
132
|
+
state.onStartChannel(longId)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
override fun stopChannel() {
|
|
136
|
+
val state = getStateOrNull<Ready>("stopChannel") ?: return
|
|
137
|
+
val channel = state.channels.firstOrNull { it.playingState in listOf(CONNECTING, PLAYING) }
|
|
138
|
+
?: run {
|
|
139
|
+
timber.w("No channel in connecting or playing state to stop!")
|
|
140
|
+
return
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
timber.d("calling stopChannel(${channel.id})")
|
|
144
|
+
state.onStopChannel(channel.id)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
override fun getCurrentUiState(): String {
|
|
148
|
+
return try {
|
|
149
|
+
timber.d("Getting current ui-state")
|
|
150
|
+
val currentState: SdkUiState = LiveVoice.uiState.value
|
|
151
|
+
json.encodeToString(currentState.mapToTransferable())
|
|
152
|
+
} catch (ex: Exception) {
|
|
153
|
+
timber.w(ex, "Tried accessing state without prior initialization, returning default!")
|
|
154
|
+
json.encodeToString(NativeLoading)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
override fun getCurrentAudioState(): Boolean {
|
|
159
|
+
return try {
|
|
160
|
+
LiveVoice.outputMode.value == LiveVoiceOutput.SPEAKER
|
|
161
|
+
} catch (ex: Exception) {
|
|
162
|
+
timber.w(ex, "Tried accessing audio state without prior initialization, returning default!")
|
|
163
|
+
false
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
override fun getCurrentSubtitles(): String {
|
|
168
|
+
val value = LiveVoice.subtitleState.value
|
|
169
|
+
if (value !is SdkSubtitleState.Enabled) return "[]"
|
|
170
|
+
|
|
171
|
+
return json.encodeToString(value.fragments.value)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
override fun getCurrentAvailableSubtitleConfigs(): String {
|
|
175
|
+
val value: SdkSubtitleState = LiveVoice.subtitleState.value
|
|
176
|
+
return json.encodeToString(value.availableSubtitles)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
override fun getCurrentClaims(): String? {
|
|
180
|
+
val claims = LiveVoice.claims.value
|
|
181
|
+
return json.encodeToString(claims ?: return null)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
override fun setLiveVoiceUseSpeaker(value: Boolean) {
|
|
185
|
+
LiveVoice.changeOutput(value)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
override fun startSubtitles(channelId: Double, languageCode: String?) {
|
|
189
|
+
val state = getStateOrNull<Ready>("startSubtitles") ?: return
|
|
190
|
+
val sdkSubtitleLanguage = when (languageCode) {
|
|
191
|
+
null -> SdkSubtitleLanguage.Transcript
|
|
192
|
+
else -> SdkSubtitleLanguage.Translated(languageCode)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
val nullableChannelId = if (channelId.toLong() == -1L) null else channelId.toLong()
|
|
196
|
+
state.onStartSubtitles(nullableChannelId, sdkSubtitleLanguage)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
override fun stopSubtitles() {
|
|
200
|
+
val state = getStateOrNull<Ready>("stopSubtitles") ?: return
|
|
201
|
+
state.onStopSubtitles()
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
override fun joinEvent(joinCode: String, password: String?, apiKey: String) {
|
|
205
|
+
val scope = (reactApplicationContext.currentActivity as? ComponentActivity)?.lifecycleScope
|
|
206
|
+
?: error("Could not create scope to connect! activity: ${reactApplicationContext.currentActivity}")
|
|
207
|
+
|
|
208
|
+
scope.launch {
|
|
209
|
+
LiveVoice.joinEvent(joinCode, password, apiKey)
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
override fun leaveEvent() {
|
|
214
|
+
LiveVoice.leaveEvent()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
override fun reconnect() = LiveVoice.reconnect()
|
|
218
|
+
|
|
219
|
+
override fun channelStatusOffline(): String = LiveVoice.translations.channelStatusOffline()
|
|
220
|
+
|
|
221
|
+
override fun noChannels(): String = LiveVoice.translations.noChannels()
|
|
222
|
+
|
|
223
|
+
override fun isAiChannelStatusMessage(): String =
|
|
224
|
+
LiveVoice.translations.isAiChannelStatusMessage()
|
|
225
|
+
|
|
226
|
+
override fun errorScreenRetrying(): String =
|
|
227
|
+
LiveVoice.translations.errorScreenRetrying()
|
|
228
|
+
|
|
229
|
+
override fun errorScreenRetryingIn(seconds: Double): String =
|
|
230
|
+
LiveVoice.translations.errorScreenRetryingIn(seconds.toLong())
|
|
231
|
+
|
|
232
|
+
override fun sdkErrorGeneric(): String =
|
|
233
|
+
LiveVoice.translations.sdkErrorGeneric()
|
|
234
|
+
|
|
235
|
+
override fun sdkErrorInactive(): String =
|
|
236
|
+
LiveVoice.translations.sdkErrorInactive()
|
|
237
|
+
|
|
238
|
+
override fun sdkErrorInvalidApiKey(): String =
|
|
239
|
+
LiveVoice.translations.sdkErrorInvalidApiKey()
|
|
240
|
+
|
|
241
|
+
override fun sdkErrorListenerLimitReached(): String =
|
|
242
|
+
LiveVoice.translations.sdkErrorListenerLimitReached()
|
|
243
|
+
|
|
244
|
+
override fun sdkErrorNoNetwork(): String =
|
|
245
|
+
LiveVoice.translations.sdkErrorNoNetwork()
|
|
246
|
+
|
|
247
|
+
override fun sdkErrorNotFound(): String =
|
|
248
|
+
LiveVoice.translations.sdkErrorNotFound()
|
|
249
|
+
|
|
250
|
+
override fun sdkErrorRequestFailed(errorCode: Double): String =
|
|
251
|
+
LiveVoice.translations.sdkErrorRequestFailed(errorCode.toInt())
|
|
252
|
+
|
|
253
|
+
override fun sdkErrorWrongPassword(): String =
|
|
254
|
+
LiveVoice.translations.sdkErrorWrongPassword()
|
|
255
|
+
|
|
256
|
+
override fun sdkNoMatchingChannels(): String =
|
|
257
|
+
LiveVoice.translations.sdkNoMatchingChannels()
|
|
258
|
+
|
|
259
|
+
override fun streamingByTitle(): String =
|
|
260
|
+
LiveVoice.translations.streamingByTitle()
|
|
261
|
+
|
|
262
|
+
override fun errorRetryNowButton(): String =
|
|
263
|
+
LiveVoice.translations.errorRetryNowButton()
|
|
264
|
+
|
|
265
|
+
override fun accessibilityChannelPlay(): String =
|
|
266
|
+
LiveVoice.translations.accessibilityChannelPlay()
|
|
267
|
+
|
|
268
|
+
override fun accessibilityChannelStatusMuted(): String =
|
|
269
|
+
LiveVoice.translations.accessibilityChannelStatusMuted()
|
|
270
|
+
|
|
271
|
+
override fun accessibilityChannelStop(): String =
|
|
272
|
+
LiveVoice.translations.accessibilityChannelStop()
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
private inline fun <reified T : SdkUiState> getStateOrNull(methodName: String): T? {
|
|
276
|
+
val currentState = try {
|
|
277
|
+
LiveVoice.uiState.value
|
|
278
|
+
} catch (ex: SdkUninitializedException) {
|
|
279
|
+
timber.e(ex, "Tried accessing state without prior initialization")
|
|
280
|
+
null
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
val state = currentState as? T
|
|
284
|
+
if (state == null) {
|
|
285
|
+
timber.e("$methodName called in wrong state $currentState")
|
|
286
|
+
}
|
|
287
|
+
return state
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
companion object {
|
|
291
|
+
const val NAME = "LiveVoiceModule"
|
|
292
|
+
}
|
|
293
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
package io.livevoice.react
|
|
15
|
+
|
|
16
|
+
import com.facebook.react.BaseReactPackage
|
|
17
|
+
import com.facebook.react.bridge.NativeModule
|
|
18
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
19
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
20
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
21
|
+
|
|
22
|
+
class LiveVoiceSdkReactNativePackage : BaseReactPackage() {
|
|
23
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
24
|
+
return if (name == LiveVoiceModule.NAME) {
|
|
25
|
+
LiveVoiceModule(reactContext)
|
|
26
|
+
} else {
|
|
27
|
+
null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
32
|
+
return ReactModuleInfoProvider {
|
|
33
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
34
|
+
moduleInfos[LiveVoiceModule.NAME] = ReactModuleInfo(
|
|
35
|
+
LiveVoiceModule.NAME,
|
|
36
|
+
LiveVoiceModule.NAME,
|
|
37
|
+
false, // canOverrideExistingModule
|
|
38
|
+
false, // needsEagerInit
|
|
39
|
+
false, // isCxxModule
|
|
40
|
+
true // isTurboModule
|
|
41
|
+
)
|
|
42
|
+
moduleInfos
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
package io.livevoice.react
|
|
15
|
+
|
|
16
|
+
import io.livevoice.sdk.android.publicApi.core.model.LiveVoicePlayingState
|
|
17
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkRetryState
|
|
18
|
+
import io.livevoice.sdk.android.publicApi.core.model.SdkUiState
|
|
19
|
+
|
|
20
|
+
fun SdkUiState.mapToTransferable(): NativeUiState = when (this) {
|
|
21
|
+
SdkUiState.Loading -> NativeLoading
|
|
22
|
+
is SdkUiState.Ready -> NativeReady(
|
|
23
|
+
channels = channels.map {
|
|
24
|
+
NativeChannel(
|
|
25
|
+
id = it.id,
|
|
26
|
+
name = it.name,
|
|
27
|
+
isOnline = it.isOnline,
|
|
28
|
+
isAudioMuted = it.isAudioMuted,
|
|
29
|
+
isAiSpeaker = it.isAiSpeaker,
|
|
30
|
+
playingState = it.playingState.mapToNative()
|
|
31
|
+
)
|
|
32
|
+
},
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
is SdkUiState.Error -> NativeError(
|
|
36
|
+
message = message,
|
|
37
|
+
canBeRetried = onRetry != null
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
is SdkUiState.Reconnecting -> {
|
|
41
|
+
val retryState = when (val state = this.retryState) {
|
|
42
|
+
is SdkRetryState.AwaitingNextReconnectAttempt -> NativeRetryState.AwaitRetry(state.retryTimestampSeconds)
|
|
43
|
+
SdkRetryState.RetryInProgress -> NativeRetryState.InProgress
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
NativeReconnecting(state = retryState)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private fun LiveVoicePlayingState.mapToNative() = when (this) {
|
|
51
|
+
LiveVoicePlayingState.STOPPED -> NativePlayingState.STOPPED
|
|
52
|
+
LiveVoicePlayingState.PLAYING -> NativePlayingState.PLAYING
|
|
53
|
+
LiveVoicePlayingState.CONNECTING, LiveVoicePlayingState.STOPPING -> NativePlayingState.TRANSITIONING
|
|
54
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
package io.livevoice.react
|
|
15
|
+
|
|
16
|
+
import kotlinx.serialization.SerialName
|
|
17
|
+
import kotlinx.serialization.Serializable
|
|
18
|
+
|
|
19
|
+
@Serializable
|
|
20
|
+
@SerialName("channel")
|
|
21
|
+
data class NativeChannel(
|
|
22
|
+
val id: Long,
|
|
23
|
+
val name: String,
|
|
24
|
+
val isOnline: Boolean,
|
|
25
|
+
val isAudioMuted: Boolean,
|
|
26
|
+
val isAiSpeaker: Boolean,
|
|
27
|
+
/** State of the channel reflecting the local playback */
|
|
28
|
+
val playingState: NativePlayingState,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
@Serializable
|
|
32
|
+
data class NativeClaims(
|
|
33
|
+
val hideBranding: Boolean,
|
|
34
|
+
val allowCustomUi: Boolean,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
@Serializable
|
|
38
|
+
@SerialName("playingState")
|
|
39
|
+
enum class NativePlayingState {
|
|
40
|
+
STOPPED, TRANSITIONING, PLAYING;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Serializable
|
|
44
|
+
@SerialName("ready")
|
|
45
|
+
data class NativeReady(
|
|
46
|
+
val channels: List<NativeChannel>,
|
|
47
|
+
) : NativeUiState
|
|
48
|
+
|
|
49
|
+
@Serializable
|
|
50
|
+
@SerialName("nativeUiState")
|
|
51
|
+
sealed interface NativeUiState
|
|
52
|
+
|
|
53
|
+
@Serializable
|
|
54
|
+
@SerialName("loading")
|
|
55
|
+
data object NativeLoading : NativeUiState
|
|
56
|
+
|
|
57
|
+
@Serializable
|
|
58
|
+
@SerialName("error")
|
|
59
|
+
data class NativeError(
|
|
60
|
+
val message: String,
|
|
61
|
+
val canBeRetried: Boolean,
|
|
62
|
+
) : NativeUiState
|
|
63
|
+
|
|
64
|
+
@Serializable
|
|
65
|
+
@SerialName("reconnecting")
|
|
66
|
+
data class NativeReconnecting(val state: NativeRetryState) : NativeUiState
|
|
67
|
+
|
|
68
|
+
@Serializable
|
|
69
|
+
sealed interface NativeRetryState {
|
|
70
|
+
@Serializable
|
|
71
|
+
@SerialName("inProgress")
|
|
72
|
+
data object InProgress : NativeRetryState
|
|
73
|
+
|
|
74
|
+
@Serializable
|
|
75
|
+
@SerialName("awaitingRetry")
|
|
76
|
+
data class AwaitRetry(val atTimestamp: Long) : NativeRetryState
|
|
77
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
14
|
+
#import "generated/RNLiveVoiceSpec/RNLiveVoiceSpec.h"
|
|
15
|
+
//
|
|
16
|
+
//// See https://reactnative.dev/docs/next/legacy/native-modules-ios
|
|
17
|
+
//#import <React/RCTEventEmitter.h>
|
|
18
|
+
|
|
19
|
+
@interface LiveVoiceSdkReactNative : NativeLiveVoiceSdkSpecBase <NativeLiveVoiceSdkSpec>
|
|
20
|
+
|
|
21
|
+
@end
|