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