@applicaster/zapp-react-native-ui-components 14.0.14 → 14.0.15-alpha.3578310293

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.
@@ -60,6 +60,7 @@ import {
60
60
  PlayerNativeCommandTypes,
61
61
  PlayerNativeSendCommand,
62
62
  } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand";
63
+ import { useRestrictMobilePlayback } from "./useRestrictMobilePlayback";
63
64
 
64
65
  type Props = {
65
66
  Player: React.ComponentType<any>;
@@ -462,6 +463,12 @@ const PlayerContainerComponent = (props: Props) => {
462
463
  );
463
464
  }, [playerManager.isRegistered()]);
464
465
 
466
+ const { isRestricted } = useRestrictMobilePlayback({
467
+ player,
468
+ entry: item,
469
+ close,
470
+ });
471
+
465
472
  const disableMiniPlayer = React.useMemo(() => {
466
473
  return pluginConfiguration?.disable_mini_player_when_inline;
467
474
  }, [pluginConfiguration]);
@@ -661,7 +668,7 @@ const PlayerContainerComponent = (props: Props) => {
661
668
  <PlayerFocusableWrapperView
662
669
  nextFocusDown={context.bottomFocusableId}
663
670
  >
664
- {Player ? (
671
+ {Player && !isRestricted ? (
665
672
  <Player
666
673
  source={{
667
674
  uri,
@@ -0,0 +1,131 @@
1
+ import { Player } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/player";
2
+ import NetInfo from "@react-native-community/netinfo";
3
+
4
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
5
+ import { showAlertDialog } from "@applicaster/zapp-react-native-utils/alertUtils";
6
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
7
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
8
+ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
9
+ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
10
+ import { getLocalizations } from "@applicaster/zapp-react-native-utils/localizationUtils";
11
+ import { log_info } from "./logger";
12
+ import { isTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
13
+
14
+ type RestrictMobilePlaybackProps = {
15
+ player?: Player;
16
+ entry?: ZappEntry;
17
+ close: () => void;
18
+ };
19
+
20
+ export const useRestrictMobilePlayback = ({
21
+ player,
22
+ entry,
23
+ close,
24
+ }: RestrictMobilePlaybackProps): { isRestricted: boolean } => {
25
+ const dialogVisibleRef = useRef<boolean>(false);
26
+ const theme = useTheme();
27
+ const plugins = usePlugins();
28
+
29
+ const restrictMobilePlugin = useMemo(
30
+ () =>
31
+ plugins.find((p) => p.identifier === "quick-brick-hook-restrict-mobile"),
32
+ [plugins]
33
+ );
34
+
35
+ const localizations = useMemo(
36
+ () => restrictMobilePlugin?.configuration?.localizations,
37
+ [restrictMobilePlugin]
38
+ );
39
+
40
+ const localize = useCallback(
41
+ (key: string) => {
42
+ const l = localizations && getLocalizations({ localizations });
43
+
44
+ return (l && l[key]) || "";
45
+ },
46
+ [localizations]
47
+ );
48
+
49
+ useEffect(() => {
50
+ return () => {
51
+ if (isTV()) {
52
+ return;
53
+ }
54
+
55
+ dialogVisibleRef.current = false;
56
+ };
57
+ }, []);
58
+
59
+ const isConnectionRestricted = useMemo(() => {
60
+ if (isTV()) {
61
+ return false;
62
+ }
63
+
64
+ // Only restrict if the plugin exists
65
+ if (!restrictMobilePlugin) {
66
+ return false;
67
+ }
68
+
69
+ return player && isTrue(entry?.extensions?.connection_restricted);
70
+ }, [player, entry, restrictMobilePlugin]);
71
+
72
+ const [isRestricted, setIsRestricted] = useState<boolean>(
73
+ isConnectionRestricted
74
+ );
75
+
76
+ useEffect(() => {
77
+ if (!isConnectionRestricted) {
78
+ return;
79
+ }
80
+
81
+ const stopPlayer = () => {
82
+ log_info(
83
+ "Stopping player due to mobile restriction, connection_restricted: true"
84
+ );
85
+
86
+ player?.closeNativePlayer();
87
+ playerManager?.invokeHandler("close");
88
+
89
+ dialogVisibleRef.current = true;
90
+
91
+ showAlertDialog({
92
+ title:
93
+ localize("restrict_mobile_playback_error_title") ||
94
+ "Restricted Connection Type",
95
+ message:
96
+ localize("restrict_mobile_playback_error_message") ||
97
+ "This content can only be viewed over a Wi-Fi or LAN network.",
98
+ okButtonText: theme.ok_button || "OK",
99
+ completion: () => {
100
+ dialogVisibleRef.current = false;
101
+
102
+ close();
103
+ },
104
+ });
105
+ };
106
+
107
+ return NetInfo.addEventListener((state) => {
108
+ if (state.type === "cellular") {
109
+ setIsRestricted(true);
110
+
111
+ if (dialogVisibleRef.current) {
112
+ return;
113
+ }
114
+
115
+ stopPlayer();
116
+ } else {
117
+ setIsRestricted(false);
118
+ }
119
+ });
120
+ }, [
121
+ close,
122
+ entry?.extensions?.connection_restricted,
123
+ localizations,
124
+ localize,
125
+ player,
126
+ theme.ok_button,
127
+ isConnectionRestricted,
128
+ ]);
129
+
130
+ return { isRestricted };
131
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "14.0.14",
3
+ "version": "14.0.15-alpha.3578310293",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "14.0.14",
32
- "@applicaster/zapp-react-native-bridge": "14.0.14",
33
- "@applicaster/zapp-react-native-redux": "14.0.14",
34
- "@applicaster/zapp-react-native-utils": "14.0.14",
31
+ "@applicaster/applicaster-types": "14.0.15-alpha.3578310293",
32
+ "@applicaster/zapp-react-native-bridge": "14.0.15-alpha.3578310293",
33
+ "@applicaster/zapp-react-native-redux": "14.0.15-alpha.3578310293",
34
+ "@applicaster/zapp-react-native-utils": "14.0.15-alpha.3578310293",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",