livevoice-sdk-react-native 1.0.3 → 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/LICENSE +1 -1
- package/README.md +119 -7
- package/android/build.gradle +52 -84
- package/android/gradle.properties +10 -6
- package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +93 -126
- package/android/src/main/java/io/livevoice/react/LiveVoiceSdkReactNativePackage.kt +12 -13
- package/android/src/main/java/io/livevoice/react/__SDK.kt +16 -2
- package/ios/LiveVoiceSdkReactNative.h +5 -5
- package/ios/LiveVoiceSdkReactNative.mm +308 -0
- 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 +27 -48
- 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 +153 -61
- package/lib/module/components/LiveVoiceView.js.map +1 -1
- package/lib/module/components/PlayButtonView.js +255 -94
- 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/icons/captions@1x.png +0 -0
- package/lib/module/icons/captions@2x.png +0 -0
- package/lib/module/icons/pause@1x.png +0 -0
- package/lib/module/icons/pause@2x.png +0 -0
- package/lib/module/icons/play@1x.png +0 -0
- package/lib/module/icons/play@2x.png +0 -0
- package/lib/module/index.js +14 -222
- 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 +16 -10
- package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
- package/lib/module/util/Colors.js +14 -11
- 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/package.json +1 -0
- package/lib/typescript/src/components/AudioOutputSwitchView.d.ts.map +1 -0
- package/lib/typescript/src/components/BrandingView.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src → src}/components/ChannelView.d.ts +4 -2
- package/lib/typescript/src/components/ChannelView.d.ts.map +1 -0
- package/lib/typescript/src/components/ErrorView.d.ts.map +1 -0
- package/lib/typescript/src/components/LiveVoiceView.d.ts +28 -0
- package/lib/typescript/src/components/LiveVoiceView.d.ts.map +1 -0
- package/lib/typescript/src/components/PlayButtonView.d.ts +341 -0
- package/lib/typescript/src/components/PlayButtonView.d.ts.map +1 -0
- package/lib/typescript/src/components/ReconnectingView.d.ts.map +1 -0
- package/lib/typescript/src/components/WarningView.d.ts.map +1 -0
- package/lib/typescript/src/components/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- 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/{module/src → src}/specs/NativeLiveVoiceSdk.d.ts +6 -3
- package/lib/typescript/src/specs/NativeLiveVoiceSdk.d.ts.map +1 -0
- package/lib/typescript/{commonjs/src → src}/util/Colors.d.ts +2 -1
- package/lib/typescript/src/util/Colors.d.ts.map +1 -0
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts +19 -0
- package/lib/typescript/src/util/ForegroundServiceConfig.d.ts.map +1 -0
- package/lib/typescript/src/util/PlayingState.d.ts.map +1 -0
- package/lib/typescript/src/util/Translations.d.ts.map +1 -0
- package/lib/typescript/src/util/UIState.d.ts +86 -0
- package/lib/typescript/src/util/UIState.d.ts.map +1 -0
- 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 +20 -41
- package/package.json +41 -122
- package/src/components/AudioOutputSwitchView.tsx +13 -13
- package/src/components/BrandingView.tsx +13 -11
- package/src/components/ChannelView.tsx +32 -36
- package/src/components/ErrorView.tsx +12 -10
- package/src/components/LiveVoiceView.tsx +231 -89
- package/src/components/PlayButtonView.tsx +293 -98
- package/src/components/ReconnectingView.tsx +20 -13
- package/src/components/WarningView.tsx +12 -10
- package/src/components/index.tsx +12 -10
- package/src/icons/captions@1x.png +0 -0
- package/src/icons/captions@2x.png +0 -0
- package/src/icons/pause@1x.png +0 -0
- package/src/icons/pause@2x.png +0 -0
- package/src/icons/play@1x.png +0 -0
- package/src/icons/play@2x.png +0 -0
- package/src/index.tsx +19 -236
- package/src/sdk/LiveVoiceSdk.ts +408 -0
- package/src/sdk/LiveVoiceState.ts +89 -0
- package/src/specs/NativeLiveVoiceSdk.ts +24 -16
- package/src/util/Colors.ts +15 -11
- 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 +54 -13
- package/src/util/logger.ts +92 -0
- package/android/generated/java/io/livevoice/react/NativeLiveVoiceSdkSpec.java +0 -186
- package/android/generated/jni/CMakeLists.txt +0 -36
- package/android/generated/jni/RNLiveVoiceSpec-generated.cpp +0 -235
- package/android/generated/jni/RNLiveVoiceSpec.h +0 -31
- package/android/generated/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI-generated.cpp +0 -245
- package/android/generated/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +0 -398
- package/android/src/main/AndroidManifest.xml +0 -3
- package/android/src/main/java/io/livevoice/react/Mappings.kt +0 -54
- package/android/src/main/java/io/livevoice/react/NativeModels.kt +0 -77
- package/ios/LivevoiceSdkReactNative.mm +0 -250
- package/ios/generated/RNLiveVoiceSpec/RNLiveVoiceSpec-generated.mm +0 -292
- package/ios/generated/RNLiveVoiceSpec/RNLiveVoiceSpec.h +0 -101
- package/ios/generated/RNLiveVoiceSpecJSI-generated.cpp +0 -245
- package/ios/generated/RNLiveVoiceSpecJSI.h +0 -398
- package/lib/commonjs/components/AudioOutputSwitchView.js +0 -144
- package/lib/commonjs/components/AudioOutputSwitchView.js.map +0 -1
- package/lib/commonjs/components/BrandingView.js +0 -78
- package/lib/commonjs/components/BrandingView.js.map +0 -1
- package/lib/commonjs/components/ChannelView.js +0 -117
- package/lib/commonjs/components/ChannelView.js.map +0 -1
- package/lib/commonjs/components/ErrorView.js +0 -88
- package/lib/commonjs/components/ErrorView.js.map +0 -1
- package/lib/commonjs/components/LiveVoiceView.js +0 -107
- package/lib/commonjs/components/LiveVoiceView.js.map +0 -1
- package/lib/commonjs/components/PlayButtonView.js +0 -161
- package/lib/commonjs/components/PlayButtonView.js.map +0 -1
- package/lib/commonjs/components/ReconnectingView.js +0 -109
- package/lib/commonjs/components/ReconnectingView.js.map +0 -1
- package/lib/commonjs/components/WarningView.js +0 -58
- package/lib/commonjs/components/WarningView.js.map +0 -1
- package/lib/commonjs/components/index.js +0 -94
- package/lib/commonjs/components/index.js.map +0 -1
- 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 +0 -327
- package/lib/commonjs/index.js.map +0 -1
- package/lib/commonjs/specs/NativeLiveVoiceSdk.js +0 -19
- package/lib/commonjs/specs/NativeLiveVoiceSdk.js.map +0 -1
- package/lib/commonjs/util/Colors.js +0 -30
- package/lib/commonjs/util/Colors.js.map +0 -1
- package/lib/commonjs/util/ForegroundServiceConfig.js +0 -33
- package/lib/commonjs/util/ForegroundServiceConfig.js.map +0 -1
- package/lib/commonjs/util/PlayingState.js +0 -24
- package/lib/commonjs/util/PlayingState.js.map +0 -1
- package/lib/commonjs/util/Translations.js +0 -47
- package/lib/commonjs/util/Translations.js.map +0 -1
- package/lib/commonjs/util/UIState.js +0 -6
- package/lib/commonjs/util/UIState.js.map +0 -1
- package/lib/module/icons/pause.png +0 -0
- package/lib/module/icons/play.png +0 -0
- package/lib/typescript/commonjs/package.json +0 -1
- package/lib/typescript/commonjs/src/components/AudioOutputSwitchView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/BrandingView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/ChannelView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/ErrorView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/LiveVoiceView.d.ts +0 -6
- package/lib/typescript/commonjs/src/components/LiveVoiceView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/PlayButtonView.d.ts +0 -146
- package/lib/typescript/commonjs/src/components/PlayButtonView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/ReconnectingView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/WarningView.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/components/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/index.d.ts +0 -149
- package/lib/typescript/commonjs/src/index.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/specs/NativeLiveVoiceSdk.d.ts +0 -48
- package/lib/typescript/commonjs/src/specs/NativeLiveVoiceSdk.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/util/Colors.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/util/ForegroundServiceConfig.d.ts +0 -12
- package/lib/typescript/commonjs/src/util/ForegroundServiceConfig.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/util/PlayingState.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/util/Translations.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/util/UIState.d.ts +0 -45
- package/lib/typescript/commonjs/src/util/UIState.d.ts.map +0 -1
- package/lib/typescript/module/src/components/AudioOutputSwitchView.d.ts +0 -6
- package/lib/typescript/module/src/components/AudioOutputSwitchView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/BrandingView.d.ts +0 -6
- package/lib/typescript/module/src/components/BrandingView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/ChannelView.d.ts +0 -13
- package/lib/typescript/module/src/components/ChannelView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/ErrorView.d.ts +0 -9
- package/lib/typescript/module/src/components/ErrorView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/LiveVoiceView.d.ts +0 -6
- package/lib/typescript/module/src/components/LiveVoiceView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/PlayButtonView.d.ts +0 -146
- package/lib/typescript/module/src/components/PlayButtonView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/ReconnectingView.d.ts +0 -9
- package/lib/typescript/module/src/components/ReconnectingView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/WarningView.d.ts +0 -8
- package/lib/typescript/module/src/components/WarningView.d.ts.map +0 -1
- package/lib/typescript/module/src/components/index.d.ts +0 -9
- package/lib/typescript/module/src/components/index.d.ts.map +0 -1
- package/lib/typescript/module/src/index.d.ts +0 -149
- package/lib/typescript/module/src/index.d.ts.map +0 -1
- package/lib/typescript/module/src/specs/NativeLiveVoiceSdk.d.ts.map +0 -1
- package/lib/typescript/module/src/util/Colors.d.ts +0 -13
- package/lib/typescript/module/src/util/Colors.d.ts.map +0 -1
- package/lib/typescript/module/src/util/ForegroundServiceConfig.d.ts +0 -12
- package/lib/typescript/module/src/util/ForegroundServiceConfig.d.ts.map +0 -1
- package/lib/typescript/module/src/util/PlayingState.d.ts +0 -7
- package/lib/typescript/module/src/util/PlayingState.d.ts.map +0 -1
- package/lib/typescript/module/src/util/Translations.d.ts +0 -22
- package/lib/typescript/module/src/util/Translations.d.ts.map +0 -1
- package/lib/typescript/module/src/util/UIState.d.ts +0 -45
- package/lib/typescript/module/src/util/UIState.d.ts.map +0 -1
- package/react-native.config.js +0 -12
- package/src/icons/pause.png +0 -0
- package/src/icons/play.png +0 -0
- /package/lib/{typescript/module → module}/package.json +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/AudioOutputSwitchView.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/BrandingView.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/ErrorView.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/ReconnectingView.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/WarningView.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/components/index.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/util/PlayingState.d.ts +0 -0
- /package/lib/typescript/{commonjs/src → src}/util/Translations.d.ts +0 -0
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2026 LiveVoice GmbH
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
|
6
6
|
in the Software without restriction, including without limitation the rights
|
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,6 +1,30 @@
|
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
1
14
|
buildscript {
|
|
2
|
-
ext.
|
|
3
|
-
|
|
15
|
+
ext.LiveVoiceSdkReactNative = [
|
|
16
|
+
kotlinVersion: "2.0.21",
|
|
17
|
+
minSdkVersion: 24,
|
|
18
|
+
compileSdkVersion: 36,
|
|
19
|
+
targetSdkVersion: 36
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
ext.getExtOrDefault = { prop ->
|
|
23
|
+
if (rootProject.ext.has(prop)) {
|
|
24
|
+
return rootProject.ext.get(prop)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return LiveVoiceSdkReactNative[prop]
|
|
4
28
|
}
|
|
5
29
|
|
|
6
30
|
repositories {
|
|
@@ -10,55 +34,26 @@ buildscript {
|
|
|
10
34
|
|
|
11
35
|
dependencies {
|
|
12
36
|
classpath "com.android.tools.build:gradle:8.7.2"
|
|
37
|
+
classpath "org.jetbrains.kotlin:kotlin-serialization:${getExtOrDefault('kotlinVersion')}"
|
|
13
38
|
// noinspection DifferentKotlinGradleVersion
|
|
14
39
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
-
classpath "org.jetbrains.kotlin:kotlin-serialization:${getExtOrDefault('kotlinVersion')}"
|
|
16
40
|
}
|
|
17
41
|
}
|
|
18
42
|
|
|
19
43
|
|
|
20
|
-
def isNewArchitectureEnabled() {
|
|
21
|
-
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
|
|
22
|
-
}
|
|
23
|
-
|
|
24
44
|
apply plugin: "com.android.library"
|
|
25
45
|
apply plugin: "kotlin-android"
|
|
26
46
|
apply plugin: "kotlinx-serialization"
|
|
27
|
-
|
|
28
|
-
if (isNewArchitectureEnabled()) {
|
|
29
|
-
apply plugin: "com.facebook.react"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
def getExtOrIntegerDefault(name) {
|
|
33
|
-
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["LiveVoiceSdkReactNative_" + name]).toInteger()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
def supportsNamespace() {
|
|
37
|
-
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
38
|
-
def major = parsed[0].toInteger()
|
|
39
|
-
def minor = parsed[1].toInteger()
|
|
40
|
-
|
|
41
|
-
// Namespace support was added in 7.3.0
|
|
42
|
-
return (major == 7 && minor >= 3) || major >= 8
|
|
43
|
-
}
|
|
47
|
+
apply plugin: "com.facebook.react"
|
|
44
48
|
|
|
45
49
|
android {
|
|
46
|
-
|
|
47
|
-
namespace "com.livevoicesdkreactnative"
|
|
50
|
+
namespace "io.livevoice.react"
|
|
48
51
|
|
|
49
|
-
|
|
50
|
-
main {
|
|
51
|
-
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
52
|
+
compileSdkVersion getExtOrDefault("compileSdkVersion")
|
|
57
53
|
|
|
58
54
|
defaultConfig {
|
|
59
|
-
minSdkVersion
|
|
60
|
-
targetSdkVersion
|
|
61
|
-
buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
|
|
55
|
+
minSdkVersion getExtOrDefault("minSdkVersion")
|
|
56
|
+
targetSdkVersion getExtOrDefault("targetSdkVersion")
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
buildFeatures {
|
|
@@ -71,7 +66,7 @@ android {
|
|
|
71
66
|
}
|
|
72
67
|
}
|
|
73
68
|
|
|
74
|
-
|
|
69
|
+
lint {
|
|
75
70
|
disable "GradleCompatible"
|
|
76
71
|
}
|
|
77
72
|
|
|
@@ -80,56 +75,29 @@ android {
|
|
|
80
75
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
81
76
|
}
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Add the needed repositories to all gradle projects.
|
|
80
|
+
*
|
|
81
|
+
* This is needed, because react somehow doesn't honor/use the sources
|
|
82
|
+
* configured in the sdk "build.gradle"'s "repositories" block.
|
|
83
|
+
*
|
|
84
|
+
* By applying it recursively, starting from the "root" project, we circumvent this!
|
|
85
|
+
* see: https://github.com/facebook/react-native/issues/39114
|
|
86
|
+
*/
|
|
87
|
+
rootProject.allprojects { Project project ->
|
|
88
|
+
println "Adding LiveVoice repository to project \"$project.name\""
|
|
89
|
+
project.repositories {
|
|
90
|
+
google()
|
|
91
|
+
mavenCentral()
|
|
92
|
+
maven { url "https://sdks.livevoice.io/android" }
|
|
91
93
|
}
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
|
|
95
|
-
/**
|
|
96
|
-
* Add the needed repositories to all gradle projects.
|
|
97
|
-
*
|
|
98
|
-
* This is needed, because react somehow doesn't honor/use the sources
|
|
99
|
-
* configured in the sdk "build.gradle"'s "repositories" block.
|
|
100
|
-
*
|
|
101
|
-
* By applying it recursively, starting from the "root" project, we circumvent this!
|
|
102
|
-
* see: https://github.com/facebook/react-native/issues/39114
|
|
103
|
-
*/
|
|
104
|
-
rootProject.allprojects { Project project ->
|
|
105
|
-
println "Adding livevoice repository to project \"$project.name\""
|
|
106
|
-
project.repositories {
|
|
107
|
-
maven { url "https://jitpack.io" }
|
|
108
|
-
maven { url "https://sdks.livevoice.io/android" }
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
repositories {
|
|
113
|
-
mavenCentral()
|
|
114
|
-
google()
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
118
|
-
|
|
119
97
|
dependencies {
|
|
120
|
-
implementation "com.facebook.react:react-android
|
|
121
|
-
implementation
|
|
122
|
-
|
|
123
|
-
implementation("io.livevoice.sdk:android:1.0.1")
|
|
124
|
-
|
|
125
|
-
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
|
|
126
|
-
implementation("com.jakewharton.timber:timber:5.0.1")
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (isNewArchitectureEnabled()) {
|
|
130
|
-
react {
|
|
131
|
-
jsRootDir = file("../src/")
|
|
132
|
-
libraryName = "LiveVoiceSdkReactNative"
|
|
133
|
-
codegenJavaPackageName = "com.livevoicesdkreactnative"
|
|
98
|
+
implementation "com.facebook.react:react-android"
|
|
99
|
+
implementation("io.livevoice.sdk:android:2.0.2") {
|
|
100
|
+
exclude group: 'org.jspecify', module: 'jspecify'
|
|
134
101
|
}
|
|
102
|
+
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0")
|
|
135
103
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
LiveVoiceSdkReactNative_targetSdkVersion=34
|
|
4
|
-
LiveVoiceSdkReactNative_compileSdkVersion=35
|
|
5
|
-
LiveVoiceSdkReactNative_ndkVersion=27.1.12297006
|
|
1
|
+
# JVM options
|
|
2
|
+
org.gradle.jvmargs=-Xms128m -Xmx4096m -XX:ReservedCodeCacheSize=200m -XX:+UseCompressedOops
|
|
6
3
|
|
|
7
|
-
|
|
4
|
+
# Performance options
|
|
5
|
+
org.gradle.parallel=true
|
|
6
|
+
org.gradle.daemon=true
|
|
7
|
+
org.gradle.configureondemand=true
|
|
8
|
+
org.gradle.caching=true
|
|
9
|
+
org.gradle.workers.max=4
|
|
10
|
+
org.gradle.vfs.watch=true
|
|
11
|
+
org.gradle.incremental=true
|
|
@@ -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,36 +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.
|
|
26
|
-
import io.livevoice.sdk.android.publicApi.core.model.LiveVoicePlayingState.
|
|
27
|
-
import io.livevoice.sdk.android.publicApi.core.model.LiveVoicePlayingState.PLAYING
|
|
25
|
+
import io.livevoice.sdk.android.publicApi.core.model.channel.LiveVoicePlayingState.Connecting
|
|
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.SdkSubtitleLanguage
|
|
31
|
-
import io.livevoice.sdk.android.publicApi.core.model.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
|
|
30
|
+
import io.livevoice.sdk.android.publicApi.core.model.exceptions.SdkNotConnectedException
|
|
31
|
+
import io.livevoice.sdk.android.publicApi.serialization.LiveVoiceSerialization
|
|
36
32
|
import kotlinx.coroutines.launch
|
|
37
|
-
import kotlinx.serialization.ExperimentalSerializationApi
|
|
38
|
-
import kotlinx.serialization.json.ClassDiscriminatorMode
|
|
39
|
-
import kotlinx.serialization.json.Json
|
|
40
|
-
import timber.log.Timber
|
|
41
33
|
|
|
42
|
-
@SuppressLint("LogNotTimber")
|
|
43
34
|
@ReactModule(name = LiveVoiceModule.NAME)
|
|
44
35
|
class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
45
36
|
NativeLiveVoiceSdkSpec(reactContext) {
|
|
46
37
|
|
|
47
|
-
private val timber = Timber.tag("[SDK]")
|
|
48
|
-
|
|
49
|
-
@OptIn(ExperimentalSerializationApi::class)
|
|
50
|
-
private val json = Json {
|
|
51
|
-
classDiscriminator = "type"
|
|
52
|
-
classDiscriminatorMode = ClassDiscriminatorMode.ALL_JSON_OBJECTS
|
|
53
|
-
}
|
|
54
|
-
|
|
55
38
|
override fun getName(): String {
|
|
56
39
|
return NAME
|
|
57
40
|
}
|
|
@@ -59,15 +42,14 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
59
42
|
override fun initialize(androidServiceConfig: String?) {
|
|
60
43
|
val parsedServiceConfig = when (androidServiceConfig) {
|
|
61
44
|
null -> ForegroundServiceConfig.Disabled
|
|
62
|
-
|
|
45
|
+
DEFAULT_MESSAGE_SENTINEL -> ForegroundServiceConfig.enabledWithDefaultMessage
|
|
63
46
|
else -> ForegroundServiceConfig.Enabled(NotificationText.RawValue(androidServiceConfig))
|
|
64
47
|
}
|
|
65
48
|
|
|
66
|
-
Timber.plant(Timber.DebugTree())
|
|
67
49
|
try {
|
|
68
50
|
val activity: AppCompatActivity =
|
|
69
51
|
currentActivity as? AppCompatActivity ?: run {
|
|
70
|
-
|
|
52
|
+
logError(EVENT_BRIDGE_ERROR, "action" to "initialize", "reason" to "missingActivity")
|
|
71
53
|
return
|
|
72
54
|
}
|
|
73
55
|
|
|
@@ -84,139 +66,91 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
84
66
|
)
|
|
85
67
|
)
|
|
86
68
|
|
|
87
|
-
|
|
69
|
+
logInfo(EVENT_INIT, "platformVersion" to reactVersion)
|
|
88
70
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
launchOutputModeObservation(activity)
|
|
92
|
-
launchAvailableSubtitleObservation(activity)
|
|
71
|
+
//forward serialized state and events from the SDK
|
|
72
|
+
launchObservations(activity)
|
|
93
73
|
|
|
94
74
|
} catch (ex: Exception) {
|
|
95
|
-
|
|
75
|
+
logError(EVENT_BRIDGE_ERROR, ex, "action" to "initialize")
|
|
96
76
|
}
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
|
|
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) {
|
|
100
84
|
activity.lifecycleScope.launch {
|
|
101
|
-
|
|
102
|
-
val uiStateString = json.encodeToString(newState.mapToTransferable())
|
|
103
|
-
timber.d("New state %s", uiStateString)
|
|
104
|
-
|
|
105
|
-
emitOnUiStateChanged(uiStateString) //it's there, even if intelliJ doesn't highlight it!
|
|
106
|
-
}
|
|
85
|
+
LiveVoiceSerialization.viewState.collect { emitOnUiStateChanged(it) }
|
|
107
86
|
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
private fun launchOutputModeObservation(activity: AppCompatActivity) {
|
|
111
87
|
activity.lifecycleScope.launch {
|
|
112
|
-
|
|
113
|
-
emitOnAudioOutputChanged(newOutputMode == LiveVoiceOutput.SPEAKER)
|
|
114
|
-
}
|
|
88
|
+
LiveVoiceSerialization.audioOutputIsSpeaker.collect { emitOnAudioOutputChanged(it) }
|
|
115
89
|
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
private fun launchAvailableSubtitleObservation(activity: AppCompatActivity) {
|
|
119
90
|
activity.lifecycleScope.launch {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
//forward/emit all subtitle fragments that arrive!
|
|
128
|
-
state.fragments.collect { fragments: List<String> ->
|
|
129
|
-
emitOnSubtitlesChanged(json.encodeToString(fragments))
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
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) }
|
|
133
98
|
}
|
|
134
99
|
}
|
|
135
100
|
|
|
136
|
-
override fun startChannel(id: Double)
|
|
137
|
-
|
|
138
|
-
val longId = id.toLong()
|
|
139
|
-
|
|
140
|
-
timber.d("calling startChannel($longId)")
|
|
141
|
-
state.onStartChannel(longId)
|
|
142
|
-
}
|
|
101
|
+
override fun startChannel(id: Double) =
|
|
102
|
+
whenConnected("startChannel") { LiveVoice.startChannel(id.toLong()) }
|
|
143
103
|
|
|
144
104
|
override fun stopChannel() {
|
|
145
|
-
val
|
|
146
|
-
|
|
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) }
|
|
147
110
|
?: run {
|
|
148
|
-
|
|
111
|
+
logWarn(EVENT_ACTION_IGNORED, "action" to "stopChannel", "reason" to "noActiveChannel")
|
|
149
112
|
return
|
|
150
113
|
}
|
|
151
114
|
|
|
152
|
-
|
|
153
|
-
state.onStopChannel(channel.id)
|
|
115
|
+
whenConnected("stopChannel") { LiveVoice.stopChannel(channel.id) }
|
|
154
116
|
}
|
|
155
117
|
|
|
156
|
-
override fun getCurrentUiState(): String
|
|
157
|
-
return try {
|
|
158
|
-
timber.d("Getting current ui-state")
|
|
159
|
-
val currentState: SdkUiState = LiveVoice.uiState.value
|
|
160
|
-
json.encodeToString(currentState.mapToTransferable())
|
|
161
|
-
} catch (ex: Exception) {
|
|
162
|
-
timber.w(ex, "Tried accessing state without prior initialization, returning default!")
|
|
163
|
-
json.encodeToString(NativeLoading)
|
|
164
|
-
}
|
|
165
|
-
}
|
|
118
|
+
override fun getCurrentUiState(): String = LiveVoiceSerialization.currentViewState()
|
|
166
119
|
|
|
167
|
-
override fun getCurrentAudioState(): Boolean
|
|
168
|
-
return try {
|
|
169
|
-
LiveVoice.outputMode.value == LiveVoiceOutput.SPEAKER
|
|
170
|
-
} catch (ex: Exception) {
|
|
171
|
-
timber.w(ex, "Tried accessing audio state without prior initialization, returning default!")
|
|
172
|
-
false
|
|
173
|
-
}
|
|
174
|
-
}
|
|
120
|
+
override fun getCurrentAudioState(): Boolean = LiveVoiceSerialization.currentAudioOutputIsSpeaker()
|
|
175
121
|
|
|
176
|
-
override fun getCurrentSubtitles(): String
|
|
177
|
-
val value = LiveVoice.subtitleState.value
|
|
178
|
-
if (value !is SdkSubtitleState.Enabled) return "[]"
|
|
122
|
+
override fun getCurrentSubtitles(): String = LiveVoiceSerialization.currentSubtitles()
|
|
179
123
|
|
|
180
|
-
|
|
181
|
-
}
|
|
124
|
+
override fun getCurrentSubtitleState(): String = LiveVoiceSerialization.currentSubtitleState()
|
|
182
125
|
|
|
183
|
-
override fun getCurrentAvailableSubtitleConfigs(): String
|
|
184
|
-
|
|
185
|
-
return json.encodeToString(value.availableSubtitles)
|
|
186
|
-
}
|
|
126
|
+
override fun getCurrentAvailableSubtitleConfigs(): String =
|
|
127
|
+
LiveVoiceSerialization.currentAvailableSubtitles()
|
|
187
128
|
|
|
188
|
-
override fun getCurrentClaims(): String?
|
|
189
|
-
val claims = LiveVoice.claims.value
|
|
190
|
-
return json.encodeToString(claims ?: return null)
|
|
191
|
-
}
|
|
129
|
+
override fun getCurrentClaims(): String? = LiveVoiceSerialization.currentClaims()
|
|
192
130
|
|
|
193
131
|
override fun setLiveVoiceUseSpeaker(value: Boolean) {
|
|
194
132
|
LiveVoice.changeOutput(value)
|
|
195
133
|
}
|
|
196
134
|
|
|
197
|
-
override fun startSubtitles(channelId: Double
|
|
198
|
-
val state = getStateOrNull<Ready>("startSubtitles") ?: return
|
|
199
|
-
val sdkSubtitleLanguage = when (languageCode) {
|
|
200
|
-
null -> SdkSubtitleLanguage.Transcript
|
|
201
|
-
else -> SdkSubtitleLanguage.Translated(languageCode)
|
|
202
|
-
}
|
|
203
|
-
|
|
135
|
+
override fun startSubtitles(channelId: Double) = whenConnected("startSubtitles") {
|
|
204
136
|
val nullableChannelId = if (channelId.toLong() == -1L) null else channelId.toLong()
|
|
205
|
-
|
|
137
|
+
LiveVoice.startSubtitles(nullableChannelId)
|
|
206
138
|
}
|
|
207
139
|
|
|
208
|
-
override fun stopSubtitles() {
|
|
209
|
-
val state = getStateOrNull<Ready>("stopSubtitles") ?: return
|
|
210
|
-
state.onStopSubtitles()
|
|
211
|
-
}
|
|
140
|
+
override fun stopSubtitles() = whenConnected("stopSubtitles") { LiveVoice.stopSubtitles() }
|
|
212
141
|
|
|
213
142
|
override fun openLiveVoiceWebsite() {
|
|
214
143
|
LiveVoice.openLiveVoiceWebsite()
|
|
215
144
|
}
|
|
216
145
|
|
|
146
|
+
override fun getSdkVersion(): String = Version.SDK_VERSION
|
|
147
|
+
|
|
217
148
|
override fun joinEvent(joinCode: String, password: String?, apiKey: String) {
|
|
218
149
|
val scope = (reactApplicationContext.currentActivity as? ComponentActivity)?.lifecycleScope
|
|
219
|
-
?:
|
|
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
|
+
}
|
|
220
154
|
|
|
221
155
|
scope.launch {
|
|
222
156
|
LiveVoice.joinEvent(joinCode, password, apiKey)
|
|
@@ -285,22 +219,55 @@ class LiveVoiceModule(reactContext: ReactApplicationContext) :
|
|
|
285
219
|
LiveVoice.translations.accessibilityChannelStop()
|
|
286
220
|
|
|
287
221
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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")
|
|
294
228
|
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
private fun logInfo(event: String, vararg fields: Pair<String, Any?>) {
|
|
232
|
+
Log.i(NAME, formatMessage(event, *fields))
|
|
233
|
+
}
|
|
295
234
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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"
|
|
299
257
|
}
|
|
300
|
-
return state
|
|
301
258
|
}
|
|
302
259
|
|
|
303
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"
|
|
304
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"
|
|
305
272
|
}
|
|
306
273
|
}
|