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