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
|
@@ -11,261 +11,379 @@
|
|
|
11
11
|
//
|
|
12
12
|
//===----------------------------------------------------------------------===//
|
|
13
13
|
|
|
14
|
+
import { Fragment, useEffect, useState } from 'react';
|
|
15
|
+
import { Platform, StyleSheet, Text, View, useColorScheme } from 'react-native';
|
|
16
|
+
|
|
17
|
+
import { LiveVoiceError, normalizeError, publicRetry, type LiveVoiceRetry } from '../sdk/Lifecycle';
|
|
18
|
+
import { reconnect, startSubtitles, stopSubtitles } from '../sdk/LiveVoiceSdk';
|
|
19
|
+
import { getCurrentViewModel, onViewModelChanged, type ViewModel } from '../sdk/LiveVoiceState';
|
|
20
|
+
import { type LiveVoiceChannel } from '../sdk/Models';
|
|
21
|
+
import { getCurrentConnection, getCurrentEvent } from '../sdk/Observables';
|
|
14
22
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
} from '../
|
|
23
|
+
answerPrompt,
|
|
24
|
+
observePrompt,
|
|
25
|
+
promptFor,
|
|
26
|
+
registerPresenter,
|
|
27
|
+
unregisterPresenter,
|
|
28
|
+
type PromptRequest,
|
|
29
|
+
} from '../sdk/Passwords';
|
|
30
|
+
import { togglePlayback } from '../sdk/Playback';
|
|
31
|
+
import { COLORS } from '../util/Colors';
|
|
32
|
+
import { deepFreeze } from '../util/freeze';
|
|
33
|
+
import { writeLogEntry } from '../util/logger';
|
|
34
|
+
import { Translations } from '../util/Translations';
|
|
26
35
|
import { BrandingView } from './BrandingView';
|
|
36
|
+
import { ChannelView } from './ChannelView';
|
|
27
37
|
import { ErrorView } from './ErrorView';
|
|
38
|
+
import { LiveVoiceSpinner } from './LiveVoiceSpinner';
|
|
39
|
+
import { PasswordPrompt } from './PasswordPrompt';
|
|
28
40
|
import { ReconnectingView } from './ReconnectingView';
|
|
29
41
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
/**
|
|
43
|
+
* One channel of the list, handed to {@link LiveVoiceViewProps.renderChannelCell}. Only the view
|
|
44
|
+
* creates cells.
|
|
45
|
+
*/
|
|
46
|
+
export type LiveVoiceChannelCell = {
|
|
47
|
+
/** The channel this cell shows. */
|
|
48
|
+
readonly channel: LiveVoiceChannel;
|
|
49
|
+
/** Whether this is the last channel in the (filtered) list, for example to omit a divider. */
|
|
50
|
+
readonly isLast: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Whether the default cell would let a tap start the channel: `false` while the channel is
|
|
53
|
+
* unavailable (offline, without audio) and during the first seconds of a reconnect.
|
|
54
|
+
*/
|
|
55
|
+
readonly isEnabled: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The cell's action, as a tap on the default cell: starts the channel if it is stopped, stops
|
|
58
|
+
* it if it is playing, decided by the SDK from the current playback state.
|
|
59
|
+
*
|
|
60
|
+
* A start resolves when local playback is confirmed, a stop when local playback has stopped;
|
|
61
|
+
* the `channel.playingState` handed to the cell follows shortly. A start needs a `ready`
|
|
62
|
+
* connection and an online channel with audio. A stop is allowed whenever an event is joined,
|
|
63
|
+
* joining, reconnecting or failed. Errors reach only the caller, never `onCommandError`.
|
|
64
|
+
*
|
|
65
|
+
* @throws {LiveVoiceError} `not_joined` when the connection does not allow the action;
|
|
66
|
+
* `api_key_invalid` without the custom-UI permission. For a start: `channel_offline` while the
|
|
67
|
+
* channel is offline; `channel_unavailable` for a channel without audio, while reconnecting, or
|
|
68
|
+
* one that is not part of the joined event; `channel_password_required`,
|
|
69
|
+
* `channel_wrong_password` and `channel_limit_reached`; `timed_out` after 10 seconds (entering
|
|
70
|
+
* a password does not count); `leave_incomplete` when an unfinished stop holds it up for more
|
|
71
|
+
* than 5 seconds; `cancelled` when another start, a stop, a second toggle, a leave or a new
|
|
72
|
+
* join ended it. A connection loss during a start can fail it with `cancelled` or
|
|
73
|
+
* `network_failed`; observe the connection to follow recovery, the rejection and the
|
|
74
|
+
* connection update need not arrive in a particular order. For a stop, the errors of
|
|
75
|
+
* {@link stopChannel}. See {@link LiveVoiceErrorCode}.
|
|
76
|
+
*/
|
|
77
|
+
togglePlayback(): Promise<void>;
|
|
78
|
+
};
|
|
47
79
|
|
|
48
|
-
/**
|
|
49
|
-
export type
|
|
50
|
-
channel: Channel,
|
|
51
|
-
helpers: ChannelCellHelpers,
|
|
52
|
-
) => React.ReactNode;
|
|
80
|
+
/** Why the list is empty: the event has no channels, or `filter` removed them all. */
|
|
81
|
+
export type LiveVoiceEmptyReason = 'noChannels' | 'noMatches';
|
|
53
82
|
|
|
54
|
-
|
|
55
|
-
|
|
83
|
+
/**
|
|
84
|
+
* The props of {@link LiveVoiceView}. All are optional; without any, the view shows the default
|
|
85
|
+
* UI.
|
|
86
|
+
*/
|
|
87
|
+
export type LiveVoiceViewProps = {
|
|
56
88
|
/**
|
|
57
|
-
*
|
|
89
|
+
* Receives the failures of the default parts' actions: a default cell's audio and subtitle
|
|
90
|
+
* taps and the default error part's retry. Never `cancelled` or `superseded`. Custom parts'
|
|
91
|
+
* actions report to their callers instead. Without it, the failures go to the SDK log as
|
|
92
|
+
* `LV_COMMAND_ERROR`, which `addLogListener` delivers.
|
|
58
93
|
*/
|
|
59
|
-
|
|
94
|
+
onCommandError?: (error: LiveVoiceError) => void;
|
|
95
|
+
/** Forces the light or dark appearance; the system's by default. */
|
|
96
|
+
isDarkMode?: boolean;
|
|
97
|
+
/** Return `true` for the channels to list. It only hides channels; it starts nothing. */
|
|
98
|
+
filter?: (channel: LiveVoiceChannel) => boolean;
|
|
60
99
|
/**
|
|
61
|
-
*
|
|
100
|
+
* Draws a channel instead of the default cell.
|
|
62
101
|
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* same gating the native SDKs apply. When omitted, the default cell is used.
|
|
102
|
+
* Every render prop except `renderLoading` needs an API key that permits custom UI. Without
|
|
103
|
+
* that permission the view shows the invalid-API-key error instead of your parts.
|
|
66
104
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
105
|
+
renderChannelCell?: (cell: LiveVoiceChannelCell) => React.ReactNode;
|
|
106
|
+
/**
|
|
107
|
+
* Draws the loading part, shown while the connection is `idle`, `joining` or `leaving`. Works
|
|
108
|
+
* for every API key.
|
|
109
|
+
*/
|
|
110
|
+
renderLoading?: () => React.ReactNode;
|
|
111
|
+
/** Draws the part shown while the connection recovers. The reconnect runs by itself. */
|
|
112
|
+
renderReconnecting?: (retry: LiveVoiceRetry) => React.ReactNode;
|
|
113
|
+
/**
|
|
114
|
+
* Draws the error part, also for a join that failed before it authenticated. `retry` is present
|
|
115
|
+
* exactly when the error is retryable; it reconnects, and fails with `not_joined` once the join
|
|
116
|
+
* has ended.
|
|
117
|
+
*/
|
|
118
|
+
renderError?: (error: LiveVoiceError, retry: (() => Promise<void>) | null) => React.ReactNode;
|
|
119
|
+
/** Draws the empty list. */
|
|
120
|
+
renderEmpty?: (reason: LiveVoiceEmptyReason) => React.ReactNode;
|
|
121
|
+
};
|
|
78
122
|
|
|
123
|
+
function useViewModel(): ViewModel {
|
|
124
|
+
const [model, setModel] = useState<ViewModel>(() => getCurrentViewModel());
|
|
79
125
|
useEffect(() => {
|
|
80
|
-
//
|
|
81
|
-
//
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const subscription = onUiStateChanged(apply);
|
|
90
|
-
|
|
91
|
-
apply(getCurrentUiState());
|
|
126
|
+
// The permission travels with the channels of the same join, so a previous key's permission
|
|
127
|
+
// never keeps the gate open for another join's channels.
|
|
128
|
+
const subscription = onViewModelChanged(setModel);
|
|
129
|
+
setModel(getCurrentViewModel());
|
|
130
|
+
return () => subscription.remove();
|
|
131
|
+
}, []);
|
|
132
|
+
return model;
|
|
133
|
+
}
|
|
92
134
|
|
|
135
|
+
/**
|
|
136
|
+
* The password request this view presents, if any. The most recently shown view that is still
|
|
137
|
+
* mounted presents the built-in prompt, also for requests that did not start from it.
|
|
138
|
+
*/
|
|
139
|
+
function usePasswordPrompt(): { request: PromptRequest | null; presenter: number | null } {
|
|
140
|
+
const [presenter, setPresenter] = useState<number | null>(null);
|
|
141
|
+
const [request, setRequest] = useState<PromptRequest | null>(null);
|
|
142
|
+
useEffect(() => {
|
|
143
|
+
const id = registerPresenter();
|
|
144
|
+
setPresenter(id);
|
|
145
|
+
const update = () => setRequest(promptFor(id));
|
|
146
|
+
const stop = observePrompt(update);
|
|
147
|
+
update();
|
|
93
148
|
return () => {
|
|
94
|
-
|
|
149
|
+
stop();
|
|
150
|
+
// A prompt this view showed gives up with the password error.
|
|
151
|
+
unregisterPresenter(id);
|
|
95
152
|
};
|
|
96
153
|
}, []);
|
|
97
|
-
|
|
98
|
-
return { uiState, claims };
|
|
154
|
+
return { request, presenter };
|
|
99
155
|
}
|
|
100
156
|
|
|
101
|
-
|
|
157
|
+
/**
|
|
158
|
+
* The LiveVoice channel list: the joined event's channels with their play and subtitle buttons,
|
|
159
|
+
* and loading, reconnecting, error and empty parts. Every part can be replaced; see
|
|
160
|
+
* {@link LiveVoiceViewProps}. It also presents the built-in password prompt when no
|
|
161
|
+
* password provider is set.
|
|
162
|
+
*/
|
|
163
|
+
export const LiveVoiceView: React.FC<LiveVoiceViewProps> = props => {
|
|
164
|
+
const systemDarkMode = useColorScheme() === 'dark';
|
|
165
|
+
const { request } = usePasswordPrompt();
|
|
166
|
+
return (
|
|
167
|
+
<>
|
|
168
|
+
<LiveVoiceParts {...props} />
|
|
169
|
+
{request !== null && (
|
|
170
|
+
<PasswordPrompt
|
|
171
|
+
request={request}
|
|
172
|
+
isDarkMode={props.isDarkMode ?? systemDarkMode}
|
|
173
|
+
onAnswer={password => answerPrompt(request.requestId, password)}
|
|
174
|
+
/>
|
|
175
|
+
)}
|
|
176
|
+
</>
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const LiveVoiceParts: React.FC<LiveVoiceViewProps> = ({
|
|
102
181
|
isDarkMode,
|
|
182
|
+
onCommandError,
|
|
103
183
|
filter,
|
|
104
|
-
|
|
184
|
+
renderChannelCell,
|
|
185
|
+
renderLoading,
|
|
186
|
+
renderReconnecting,
|
|
187
|
+
renderError,
|
|
188
|
+
renderEmpty,
|
|
105
189
|
}) => {
|
|
106
|
-
const systemDarkMode = useColorScheme() ===
|
|
190
|
+
const systemDarkMode = useColorScheme() === 'dark';
|
|
107
191
|
const dark = isDarkMode ?? systemDarkMode;
|
|
108
|
-
const {
|
|
192
|
+
const { part, features } = useViewModel();
|
|
109
193
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
state={{
|
|
124
|
-
type: "error",
|
|
125
|
-
message: Translations.sdkErrorInvalidApiKey(),
|
|
126
|
-
canBeRetried: false,
|
|
127
|
-
}}
|
|
128
|
-
isDarkMode={dark}
|
|
129
|
-
onPress={() => {}}
|
|
130
|
-
/>
|
|
131
|
-
);
|
|
194
|
+
const perform = (operation: Promise<void>, source: 'cell' | 'subtitles' | 'retry', channelId?: number) => {
|
|
195
|
+
void Promise.resolve(operation).catch(error => {
|
|
196
|
+
const failure = normalizeError(error);
|
|
197
|
+
if (failure.code === 'cancelled' || failure.code === 'superseded') return;
|
|
198
|
+
if (onCommandError) onCommandError(failure);
|
|
199
|
+
else {
|
|
200
|
+
writeLogEntry('LV_COMMAND_ERROR', 'error', {
|
|
201
|
+
source,
|
|
202
|
+
channelId: channelId?.toString(),
|
|
203
|
+
code: failure.code,
|
|
204
|
+
retryable: String(failure.isRetryable),
|
|
205
|
+
reason: failure.detail.reason,
|
|
206
|
+
});
|
|
132
207
|
}
|
|
208
|
+
});
|
|
209
|
+
};
|
|
133
210
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
211
|
+
// Only a provided function counts; `renderLoading` works for every key.
|
|
212
|
+
const customParts = Object.entries({
|
|
213
|
+
channelCell: renderChannelCell,
|
|
214
|
+
reconnecting: renderReconnecting,
|
|
215
|
+
error: renderError,
|
|
216
|
+
empty: renderEmpty,
|
|
217
|
+
}).filter(([, prop]) => typeof prop === 'function').map(([part]) => part);
|
|
218
|
+
const usesCustomParts = customParts.length > 0;
|
|
219
|
+
const denied = usesCustomParts && features !== null && !features.customUiAllowed;
|
|
220
|
+
const deniedParts = denied ? customParts.join(',') : null;
|
|
221
|
+
useEffect(() => {
|
|
222
|
+
// Once each time the view turns to the invalid-key error for its custom parts.
|
|
223
|
+
if (deniedParts === null) return;
|
|
224
|
+
const connection = getCurrentConnection();
|
|
225
|
+
const eventId = getCurrentEvent()?.eventId ?? ('eventId' in connection ? connection.eventId : undefined);
|
|
226
|
+
writeLogEntry('LV_CUSTOM_UI_DENIED', 'error', { parts: deniedParts, eventId: eventId?.toString() });
|
|
227
|
+
}, [deniedParts]);
|
|
228
|
+
if (denied) {
|
|
229
|
+
return <ErrorView message={new LiveVoiceError('api_key_invalid').message} onRetry={null} isDarkMode={dark} />;
|
|
230
|
+
}
|
|
139
231
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
232
|
+
switch (part.kind) {
|
|
233
|
+
case 'loading':
|
|
234
|
+
if (typeof renderLoading === 'function') return <>{renderLoading()}</>;
|
|
235
|
+
// Custom parts get a neutral spinner, never the default card.
|
|
236
|
+
return usesCustomParts ? <NeutralLoading dark={dark} /> : <DefaultLoading dark={dark} />;
|
|
237
|
+
|
|
238
|
+
case 'reconnecting':
|
|
239
|
+
if (typeof renderReconnecting === 'function') return <>{renderReconnecting(deepFreeze(publicRetry(part.retry)))}</>;
|
|
240
|
+
return <ReconnectingView retry={part.retry} isDarkMode={dark} />;
|
|
241
|
+
|
|
242
|
+
case 'error': {
|
|
243
|
+
const { error } = part;
|
|
244
|
+
if (typeof renderError === 'function') {
|
|
245
|
+
return <>{renderError(error, error.isRetryable ? () => reconnect() : null)}</>;
|
|
246
|
+
}
|
|
247
|
+
return (
|
|
248
|
+
<ErrorView
|
|
249
|
+
message={error.message}
|
|
250
|
+
onRetry={error.isRetryable ? () => perform(reconnect(), 'retry') : null}
|
|
251
|
+
isDarkMode={dark}
|
|
252
|
+
/>
|
|
153
253
|
);
|
|
254
|
+
}
|
|
154
255
|
|
|
155
|
-
|
|
156
|
-
|
|
256
|
+
case 'ready': {
|
|
257
|
+
const visible = filter == null ? part.channels : part.channels.filter(filter);
|
|
258
|
+
const showBranding = !(features?.hideBranding ?? false);
|
|
259
|
+
if (visible.length === 0) {
|
|
260
|
+
const reason: LiveVoiceEmptyReason = part.channels.length === 0 ? 'noChannels' : 'noMatches';
|
|
261
|
+
if (typeof renderEmpty === 'function') return <>{renderEmpty(reason)}</>;
|
|
157
262
|
return (
|
|
158
|
-
<View style={{ width:
|
|
159
|
-
{
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
263
|
+
<View style={{ width: '100%' }}>
|
|
264
|
+
<View style={{ backgroundColor: dark ? COLORS.cardBgDark : COLORS.cardBg, borderRadius: 8, overflow: 'hidden' }}>
|
|
265
|
+
<DefaultEmpty reason={reason} dark={dark} />
|
|
266
|
+
{showBranding && <BrandingView isDarkMode={dark} />}
|
|
267
|
+
</View>
|
|
268
|
+
</View>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Custom cells get full control (no card chrome or dividers), like the native SDKs.
|
|
273
|
+
if (typeof renderChannelCell === 'function') {
|
|
274
|
+
return (
|
|
275
|
+
<View style={{ width: '100%' }}>
|
|
276
|
+
{visible.map((channel, index) => (
|
|
277
|
+
<Fragment key={channel.id}>
|
|
278
|
+
{renderChannelCell(Object.freeze({
|
|
279
|
+
channel: deepFreeze({ ...channel, dependentChannels: channel.dependentChannels.map(d => ({ ...d })) }),
|
|
280
|
+
isLast: index === visible.length - 1,
|
|
281
|
+
isEnabled: part.isEnabled.get(channel.id) ?? false,
|
|
282
|
+
// Native checks the custom-UI permission again when this runs.
|
|
283
|
+
togglePlayback: () => togglePlayback(channel.id, 'custom'),
|
|
284
|
+
}))}
|
|
285
|
+
</Fragment>
|
|
286
|
+
))}
|
|
172
287
|
{showBranding && <BrandingView isDarkMode={dark} />}
|
|
173
288
|
</View>
|
|
174
289
|
);
|
|
175
290
|
}
|
|
176
291
|
|
|
177
|
-
|
|
292
|
+
const divider = rowDivider(dark);
|
|
293
|
+
// The event's colours, for every key; LiveVoice orange without branding.
|
|
294
|
+
const brandColor = part.brandColors === null ? null : dark ? part.brandColors.dark : part.brandColors.light;
|
|
178
295
|
return (
|
|
179
|
-
<View style={{ width:
|
|
180
|
-
<View
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
overflow: "hidden",
|
|
185
|
-
}}
|
|
186
|
-
>
|
|
187
|
-
{visibleChannels.length === 0 ? (
|
|
188
|
-
emptyView
|
|
189
|
-
) : (
|
|
190
|
-
visibleChannels.map((channel: Channel, index: number) => (
|
|
296
|
+
<View style={{ width: '100%' }}>
|
|
297
|
+
<View style={{ backgroundColor: dark ? COLORS.cardBgDark : COLORS.cardBg, borderRadius: 8, overflow: 'hidden' }}>
|
|
298
|
+
{visible.map((channel, index) => {
|
|
299
|
+
const subtitlesOpen = part.subtitlesOpen.get(channel.id) ?? false;
|
|
300
|
+
return (
|
|
191
301
|
<View key={channel.id}>
|
|
192
302
|
<ChannelView
|
|
193
303
|
playingState={channel.playingState}
|
|
194
304
|
isDarkMode={dark}
|
|
195
|
-
|
|
305
|
+
isDimmed={part.inReconnectGrace}
|
|
306
|
+
brandColor={brandColor}
|
|
196
307
|
isOnline={channel.isOnline}
|
|
197
308
|
hasAudio={channel.hasAudio}
|
|
198
309
|
hasSubtitles={channel.hasSubtitles}
|
|
310
|
+
status={part.status.get(channel.id) ?? null}
|
|
311
|
+
muteMark={part.muteMark.get(channel.id) ?? null}
|
|
312
|
+
isPasswordProtected={channel.isPasswordProtected}
|
|
199
313
|
channelName={channel.name}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
314
|
+
subtitlesOpen={subtitlesOpen}
|
|
315
|
+
accessibility={part.accessibility.get(channel.id) ?? null}
|
|
316
|
+
onAudioPress={() => perform(togglePlayback(channel.id, 'default'), 'cell', channel.id)}
|
|
317
|
+
// The subtitle half toggles this channel's subtitles; play never touches them.
|
|
318
|
+
onSubtitlesPress={() => perform(
|
|
319
|
+
subtitlesOpen ? stopSubtitles() : startSubtitles({ channelId: channel.id }), 'subtitles', channel.id,
|
|
320
|
+
)}
|
|
206
321
|
/>
|
|
207
|
-
{index <
|
|
208
|
-
<View
|
|
209
|
-
style={{
|
|
210
|
-
height: 1,
|
|
211
|
-
backgroundColor: dividerColor,
|
|
212
|
-
marginHorizontal: 10,
|
|
213
|
-
}}
|
|
214
|
-
/>
|
|
322
|
+
{index < visible.length - 1 && (
|
|
323
|
+
<View style={divider} />
|
|
215
324
|
)}
|
|
216
325
|
</View>
|
|
217
|
-
)
|
|
218
|
-
)}
|
|
326
|
+
);
|
|
327
|
+
})}
|
|
219
328
|
{showBranding && <BrandingView isDarkMode={dark} />}
|
|
220
329
|
</View>
|
|
221
330
|
</View>
|
|
222
331
|
);
|
|
223
332
|
}
|
|
333
|
+
}
|
|
334
|
+
};
|
|
224
335
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}}
|
|
240
|
-
>
|
|
241
|
-
<ActivityIndicator size={40} color={COLORS.primary} />
|
|
242
|
-
</View>
|
|
243
|
-
);
|
|
336
|
+
/**
|
|
337
|
+
* The line between default cells, inset 12 at both sides: iOS SwiftUI `Divider()`, a hairline in
|
|
338
|
+
* the system separator colour (`LiveVoiceView.swift`); Android `HorizontalDivider`, 1 dp in
|
|
339
|
+
* `onBackgroundInactiveLight` (`DefaultChannel.kt`).
|
|
340
|
+
*/
|
|
341
|
+
function rowDivider(dark: boolean) {
|
|
342
|
+
return Platform.OS === 'ios'
|
|
343
|
+
? {
|
|
344
|
+
height: StyleSheet.hairlineWidth,
|
|
345
|
+
backgroundColor: dark ? 'rgba(84, 84, 88, 0.6)' : 'rgba(60, 60, 67, 0.29)',
|
|
346
|
+
marginHorizontal: 12,
|
|
347
|
+
}
|
|
348
|
+
: { height: 1, backgroundColor: dark ? '#495057' : '#E7E7E7', marginHorizontal: 12 };
|
|
349
|
+
}
|
|
244
350
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
351
|
+
const DefaultLoading: React.FC<{ dark: boolean }> = ({ dark }) => (
|
|
352
|
+
<View
|
|
353
|
+
style={{
|
|
354
|
+
width: '100%',
|
|
355
|
+
padding: 10,
|
|
356
|
+
borderRadius: 8,
|
|
357
|
+
justifyContent: 'center',
|
|
358
|
+
alignItems: 'center',
|
|
359
|
+
backgroundColor: dark ? COLORS.cardBgDark : COLORS.cardBg,
|
|
360
|
+
}}
|
|
361
|
+
>
|
|
362
|
+
{/* Neutral, like the native SDKs: the brand colour is for the play buttons. */}
|
|
363
|
+
<View style={{ opacity: 0.5 }}>
|
|
364
|
+
<LiveVoiceSpinner size={36} color={dark ? COLORS.white : COLORS.black} />
|
|
365
|
+
</View>
|
|
366
|
+
</View>
|
|
367
|
+
);
|
|
255
368
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
reconnect();
|
|
263
|
-
}}
|
|
264
|
-
/>
|
|
265
|
-
);
|
|
266
|
-
default:
|
|
267
|
-
return <View />;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
369
|
+
/** The loading part next to a host's custom parts: a spinner without the default card. */
|
|
370
|
+
const NeutralLoading: React.FC<{ dark: boolean }> = ({ dark }) => (
|
|
371
|
+
<View style={{ width: '100%', padding: 10, alignItems: 'center', opacity: 0.5 }}>
|
|
372
|
+
<LiveVoiceSpinner size={36} color={dark ? COLORS.white : COLORS.black} />
|
|
373
|
+
</View>
|
|
374
|
+
);
|
|
270
375
|
|
|
271
|
-
|
|
376
|
+
const DefaultEmpty: React.FC<{ reason: LiveVoiceEmptyReason; dark: boolean }> = ({ reason, dark }) => (
|
|
377
|
+
<View style={{ paddingVertical: 30, paddingHorizontal: 16 }}>
|
|
378
|
+
<Text
|
|
379
|
+
style={{
|
|
380
|
+
fontSize: 14,
|
|
381
|
+
fontWeight: '500',
|
|
382
|
+
textAlign: 'center',
|
|
383
|
+
color: dark ? COLORS.white : COLORS.black,
|
|
384
|
+
}}
|
|
385
|
+
>
|
|
386
|
+
{reason === 'noChannels' ? Translations.noChannels() : Translations.sdkNoMatchingChannels()}
|
|
387
|
+
</Text>
|
|
388
|
+
</View>
|
|
389
|
+
);
|