livevoice-sdk-react-native 2.0.0 → 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 +158 -7
- package/android/build.gradle +18 -6
- package/android/src/main/java/io/livevoice/react/LiveVoiceModule.kt +121 -221
- package/android/src/main/java/io/livevoice/react/__SDK.kt +17 -3
- package/ios/LiveVoiceRNBridge.swift +362 -0
- package/ios/LiveVoiceSdkReactNative.mm +247 -145
- package/ios/__SDK.h +16 -2
- package/ios/livevoice_spm_backport.rb +202 -0
- package/lib/module/components/BrandingView.js +71 -50
- package/lib/module/components/BrandingView.js.map +1 -1
- package/lib/module/components/ChannelView.js +368 -54
- package/lib/module/components/ChannelView.js.map +1 -1
- package/lib/module/components/ErrorView.js +17 -16
- 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 +351 -104
- 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 +192 -254
- package/lib/module/components/PlayButtonView.js.map +1 -1
- package/lib/module/components/ReconnectingView.js +43 -62
- package/lib/module/components/ReconnectingView.js.map +1 -1
- package/lib/module/components/WarningView.js +12 -10
- package/lib/module/components/WarningView.js.map +1 -1
- package/lib/module/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 +24 -225
- 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 +365 -0
- package/lib/module/sdk/LiveVoiceSdk.js.map +1 -0
- package/lib/module/sdk/LiveVoiceState.js +234 -0
- package/lib/module/sdk/LiveVoiceState.js.map +1 -0
- 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/sdk/NativeSdkVersions.js +24 -0
- 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 +12 -10
- package/lib/module/specs/NativeLiveVoiceSdk.js.map +1 -1
- package/lib/module/util/Colors.js +14 -11
- package/lib/module/util/Colors.js.map +1 -1
- package/lib/module/util/Translations.js +46 -21
- 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 +114 -0
- package/lib/module/util/logger.js.map +1 -0
- 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 +85 -3
- 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/components/WarningView.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +15 -144
- 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 +215 -0
- package/lib/typescript/src/sdk/LiveVoiceSdk.d.ts.map +1 -0
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts +80 -0
- package/lib/typescript/src/sdk/LiveVoiceState.d.ts.map +1 -0
- 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 +35 -29
- 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 +33 -0
- package/lib/typescript/src/util/logger.d.ts.map +1 -0
- package/livevoice-sdk-react-native.podspec +41 -16
- package/package.json +26 -14
- package/src/components/BrandingView.tsx +55 -66
- package/src/components/ChannelView.tsx +342 -48
- package/src/components/ErrorView.tsx +21 -22
- package/src/components/LiveVoiceSpinner.tsx +87 -0
- package/src/components/LiveVoiceView.tsx +360 -151
- package/src/components/PasswordPrompt.tsx +144 -0
- package/src/components/PlayButtonView.tsx +177 -279
- package/src/components/ReconnectingView.tsx +40 -86
- package/src/components/WarningView.tsx +12 -10
- 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 +105 -252
- 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 +384 -0
- package/src/sdk/LiveVoiceState.ts +259 -0
- package/src/sdk/LogEntries.ts +88 -0
- package/src/sdk/Models.ts +129 -0
- package/src/sdk/NativeSdkVersions.ts +21 -0
- 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 +56 -46
- package/src/util/Colors.ts +14 -11
- package/src/util/Translations.ts +46 -22
- package/src/util/freeze.ts +23 -0
- package/src/util/logger.ts +119 -0
- package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeLiveVoiceSdkSpec.java +0 -186
- package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +0 -28
- package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec-generated.cpp +0 -235
- package/android/app/build/generated/source/codegen/jni/RNLiveVoiceSpec.h +0 -31
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/RNLiveVoiceSpec/RNLiveVoiceSpecJSI.h +0 -341
- package/android/src/main/java/io/livevoice/react/Mappings.kt +0 -85
- package/android/src/main/java/io/livevoice/react/NativeModels.kt +0 -79
- package/lib/module/components/AudioOutputSwitchView.js +0 -138
- package/lib/module/components/AudioOutputSwitchView.js.map +0 -1
- package/lib/module/components/index.js +0 -22
- package/lib/module/components/index.js.map +0 -1
- package/lib/module/icons/mic.png +0 -0
- package/lib/module/util/ForegroundServiceConfig.js +0 -28
- package/lib/module/util/ForegroundServiceConfig.js.map +0 -1
- package/lib/module/util/PlayingState.js +0 -21
- 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 -12
- 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 -66
- package/lib/typescript/src/util/UIState.d.ts.map +0 -1
- package/src/components/AudioOutputSwitchView.tsx +0 -146
- package/src/components/index.tsx +0 -19
- package/src/icons/mic.png +0 -0
- package/src/util/ForegroundServiceConfig.tsx +0 -32
- package/src/util/PlayingState.ts +0 -18
- package/src/util/UIState.ts +0 -89
|
@@ -1,180 +1,389 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
|
2
|
+
//
|
|
3
|
+
// This source file is part of the LiveVoice SDK project
|
|
4
|
+
//
|
|
5
|
+
// Copyright (c) LiveVoice GmbH
|
|
6
|
+
// Licensed under the MIT license
|
|
7
|
+
//
|
|
8
|
+
// See LICENSE for license information
|
|
9
|
+
//
|
|
10
|
+
// SPDX-License-Identifier: MIT
|
|
11
|
+
//
|
|
12
|
+
//===----------------------------------------------------------------------===//
|
|
13
|
+
|
|
14
|
+
import { Fragment, useEffect, useState } from 'react';
|
|
15
|
+
import { Platform, StyleSheet, Text, View, useColorScheme } from 'react-native';
|
|
11
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';
|
|
12
22
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
} from
|
|
28
|
-
|
|
29
|
-
import {
|
|
30
|
-
|
|
31
|
-
import { useEffect, useState } from "react";
|
|
32
|
-
import { View, ActivityIndicator } from "react-native";
|
|
33
|
-
|
|
34
|
-
import { COLORS } from "../util/Colors";
|
|
35
|
-
import { type Channel } from "../util/UIState";
|
|
36
|
-
import { ChannelView } from "./ChannelView";
|
|
37
|
-
|
|
38
|
-
export interface LiveVoiceViewProps {
|
|
39
|
-
isDarkMode?: boolean;
|
|
40
|
-
}
|
|
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';
|
|
35
|
+
import { BrandingView } from './BrandingView';
|
|
36
|
+
import { ChannelView } from './ChannelView';
|
|
37
|
+
import { ErrorView } from './ErrorView';
|
|
38
|
+
import { LiveVoiceSpinner } from './LiveVoiceSpinner';
|
|
39
|
+
import { PasswordPrompt } from './PasswordPrompt';
|
|
40
|
+
import { ReconnectingView } from './ReconnectingView';
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
};
|
|
44
79
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
80
|
+
/** Why the list is empty: the event has no channels, or `filter` removed them all. */
|
|
81
|
+
export type LiveVoiceEmptyReason = 'noChannels' | 'noMatches';
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The props of {@link LiveVoiceView}. All are optional; without any, the view shows the default
|
|
85
|
+
* UI.
|
|
86
|
+
*/
|
|
87
|
+
export type LiveVoiceViewProps = {
|
|
88
|
+
/**
|
|
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.
|
|
93
|
+
*/
|
|
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;
|
|
99
|
+
/**
|
|
100
|
+
* Draws a channel instead of the default cell.
|
|
101
|
+
*
|
|
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.
|
|
104
|
+
*/
|
|
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
|
+
};
|
|
56
122
|
|
|
123
|
+
function useViewModel(): ViewModel {
|
|
124
|
+
const [model, setModel] = useState<ViewModel>(() => getCurrentViewModel());
|
|
57
125
|
useEffect(() => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
return () => {
|
|
65
|
-
subscription?.remove();
|
|
66
|
-
subscription = undefined;
|
|
67
|
-
};
|
|
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();
|
|
68
131
|
}, []);
|
|
132
|
+
return model;
|
|
133
|
+
}
|
|
69
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);
|
|
70
142
|
useEffect(() => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
);
|
|
143
|
+
const id = registerPresenter();
|
|
144
|
+
setPresenter(id);
|
|
145
|
+
const update = () => setRequest(promptFor(id));
|
|
146
|
+
const stop = observePrompt(update);
|
|
147
|
+
update();
|
|
78
148
|
return () => {
|
|
79
|
-
|
|
80
|
-
|
|
149
|
+
stop();
|
|
150
|
+
// A prompt this view showed gives up with the password error.
|
|
151
|
+
unregisterPresenter(id);
|
|
81
152
|
};
|
|
82
153
|
}, []);
|
|
154
|
+
return { request, presenter };
|
|
155
|
+
}
|
|
83
156
|
|
|
84
|
-
|
|
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
|
+
};
|
|
85
179
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
180
|
+
const LiveVoiceParts: React.FC<LiveVoiceViewProps> = ({
|
|
181
|
+
isDarkMode,
|
|
182
|
+
onCommandError,
|
|
183
|
+
filter,
|
|
184
|
+
renderChannelCell,
|
|
185
|
+
renderLoading,
|
|
186
|
+
renderReconnecting,
|
|
187
|
+
renderError,
|
|
188
|
+
renderEmpty,
|
|
189
|
+
}) => {
|
|
190
|
+
const systemDarkMode = useColorScheme() === 'dark';
|
|
191
|
+
const dark = isDarkMode ?? systemDarkMode;
|
|
192
|
+
const { part, features } = useViewModel();
|
|
90
193
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
hasAudio={channel.hasAudio}
|
|
108
|
-
hasSubtitles={channel.hasSubtitles}
|
|
109
|
-
channelName={channel.name}
|
|
110
|
-
onAudioPress={() =>
|
|
111
|
-
channel.playingState === PlayingState.PLAYING
|
|
112
|
-
? stopChannel()
|
|
113
|
-
: startChannel(channel.id)
|
|
114
|
-
}
|
|
115
|
-
onSubtitlesPress={() => startSubtitles(channel.id)}
|
|
116
|
-
/>
|
|
117
|
-
{index < uiState.channels.length - 1 && (
|
|
118
|
-
<View
|
|
119
|
-
style={{
|
|
120
|
-
height: 1,
|
|
121
|
-
backgroundColor: dividerColor,
|
|
122
|
-
marginHorizontal: 10,
|
|
123
|
-
}}
|
|
124
|
-
/>
|
|
125
|
-
)}
|
|
126
|
-
</View>
|
|
127
|
-
))}
|
|
128
|
-
</View>
|
|
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
|
+
});
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
};
|
|
129
210
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
}
|
|
135
231
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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} />;
|
|
140
237
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
width: "100%",
|
|
145
|
-
padding: 10,
|
|
146
|
-
borderRadius: 8,
|
|
147
|
-
justifyContent: "center",
|
|
148
|
-
alignItems: "center",
|
|
149
|
-
backgroundColor: loadingBackgroundColor,
|
|
150
|
-
}}
|
|
151
|
-
>
|
|
152
|
-
<ActivityIndicator size={40} color={COLORS.primary} />
|
|
153
|
-
</View>
|
|
154
|
-
);
|
|
238
|
+
case 'reconnecting':
|
|
239
|
+
if (typeof renderReconnecting === 'function') return <>{renderReconnecting(deepFreeze(publicRetry(part.retry)))}</>;
|
|
240
|
+
return <ReconnectingView retry={part.retry} isDarkMode={dark} />;
|
|
155
241
|
|
|
156
|
-
case
|
|
242
|
+
case 'error': {
|
|
243
|
+
const { error } = part;
|
|
244
|
+
if (typeof renderError === 'function') {
|
|
245
|
+
return <>{renderError(error, error.isRetryable ? () => reconnect() : null)}</>;
|
|
246
|
+
}
|
|
157
247
|
return (
|
|
158
248
|
<ErrorView
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}}
|
|
249
|
+
message={error.message}
|
|
250
|
+
onRetry={error.isRetryable ? () => perform(reconnect(), 'retry') : null}
|
|
251
|
+
isDarkMode={dark}
|
|
163
252
|
/>
|
|
164
253
|
);
|
|
254
|
+
}
|
|
255
|
+
|
|
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)}</>;
|
|
262
|
+
return (
|
|
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
|
+
}
|
|
165
271
|
|
|
166
|
-
|
|
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
|
+
))}
|
|
287
|
+
{showBranding && <BrandingView isDarkMode={dark} />}
|
|
288
|
+
</View>
|
|
289
|
+
);
|
|
290
|
+
}
|
|
291
|
+
|
|
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;
|
|
167
295
|
return (
|
|
168
|
-
<
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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 (
|
|
301
|
+
<View key={channel.id}>
|
|
302
|
+
<ChannelView
|
|
303
|
+
playingState={channel.playingState}
|
|
304
|
+
isDarkMode={dark}
|
|
305
|
+
isDimmed={part.inReconnectGrace}
|
|
306
|
+
brandColor={brandColor}
|
|
307
|
+
isOnline={channel.isOnline}
|
|
308
|
+
hasAudio={channel.hasAudio}
|
|
309
|
+
hasSubtitles={channel.hasSubtitles}
|
|
310
|
+
status={part.status.get(channel.id) ?? null}
|
|
311
|
+
muteMark={part.muteMark.get(channel.id) ?? null}
|
|
312
|
+
isPasswordProtected={channel.isPasswordProtected}
|
|
313
|
+
channelName={channel.name}
|
|
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
|
+
)}
|
|
321
|
+
/>
|
|
322
|
+
{index < visible.length - 1 && (
|
|
323
|
+
<View style={divider} />
|
|
324
|
+
)}
|
|
325
|
+
</View>
|
|
326
|
+
);
|
|
327
|
+
})}
|
|
328
|
+
{showBranding && <BrandingView isDarkMode={dark} />}
|
|
329
|
+
</View>
|
|
330
|
+
</View>
|
|
174
331
|
);
|
|
175
|
-
|
|
176
|
-
return <View />;
|
|
332
|
+
}
|
|
177
333
|
}
|
|
178
334
|
};
|
|
179
335
|
|
|
180
|
-
|
|
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
|
+
}
|
|
350
|
+
|
|
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
|
+
);
|
|
368
|
+
|
|
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
|
+
);
|
|
375
|
+
|
|
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
|
+
);
|