@zezosoft/zezo-ott-react-native-video-player 1.0.3 → 1.0.5

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.
Files changed (67) hide show
  1. package/lib/module/AdsPlayer/MediaControls/AdBottomControls.js +2 -2
  2. package/lib/module/AdsPlayer/MediaControls/AdBottomControls.js.map +1 -1
  3. package/package.json +1 -2
  4. package/src/AdsPlayer/AdsPlayer.tsx +0 -311
  5. package/src/AdsPlayer/MediaControls/AdBottomControls.tsx +0 -191
  6. package/src/AdsPlayer/MediaControls/AdMediaControls.tsx +0 -104
  7. package/src/AdsPlayer/MediaControls/AdMediaControlsProvider.tsx +0 -62
  8. package/src/AdsPlayer/MediaControls/AdMiddleControls.tsx +0 -63
  9. package/src/AdsPlayer/MediaControls/AdTopControls.tsx +0 -191
  10. package/src/AdsPlayer/MediaControls/index.ts +0 -5
  11. package/src/AdsPlayer/components/RotatingLoader.tsx +0 -79
  12. package/src/AdsPlayer/index.ts +0 -4
  13. package/src/AdsPlayer/store/adsPlayer.type.ts +0 -29
  14. package/src/AdsPlayer/store/adsPlayerStore.ts +0 -59
  15. package/src/AdsPlayer/store/index.ts +0 -2
  16. package/src/AdsPlayer/utils/adStateReset.ts +0 -29
  17. package/src/AdsPlayer/utils/controls.ts +0 -69
  18. package/src/AdsPlayer/utils/useAdControlsAutoHide.ts +0 -32
  19. package/src/AdsPlayer/utils/useAdInitialization.ts +0 -86
  20. package/src/AdsPlayer/utils/useAdTracking.ts +0 -89
  21. package/src/AdsPlayer/utils/useAdsManager.ts +0 -215
  22. package/src/VideoPlayer/MediaControls/BottomControls.tsx +0 -210
  23. package/src/VideoPlayer/MediaControls/MediaControls.tsx +0 -30
  24. package/src/VideoPlayer/MediaControls/MediaControlsProvider.tsx +0 -104
  25. package/src/VideoPlayer/MediaControls/MiddleControls.tsx +0 -259
  26. package/src/VideoPlayer/MediaControls/TopControls.tsx +0 -100
  27. package/src/VideoPlayer/Settings/AudioAndSubtitles.tsx +0 -295
  28. package/src/VideoPlayer/Settings/Episodes.tsx +0 -297
  29. package/src/VideoPlayer/Settings/SettingModal.tsx +0 -127
  30. package/src/VideoPlayer/Settings/SpeedControls.tsx +0 -130
  31. package/src/VideoPlayer/Settings/VideoPlayerSettings.tsx +0 -141
  32. package/src/VideoPlayer/VideoPlayerCore.tsx +0 -356
  33. package/src/VideoPlayer/components/ProgressBar.tsx +0 -211
  34. package/src/VideoPlayer/components/SkipAndNextControls.tsx +0 -192
  35. package/src/VideoPlayer/components/SubtitleView.tsx +0 -53
  36. package/src/VideoPlayer/components/Toast.tsx +0 -61
  37. package/src/VideoPlayer/context/VideoPlayerConfig.tsx +0 -65
  38. package/src/VideoPlayer/context/index.ts +0 -5
  39. package/src/VideoPlayer/index.ts +0 -4
  40. package/src/VideoPlayer/store/index.ts +0 -2
  41. package/src/VideoPlayer/store/videoPlayer.type.ts +0 -214
  42. package/src/VideoPlayer/store/videoPlayerStore.ts +0 -97
  43. package/src/VideoPlayer/styles/globalStyles.ts +0 -73
  44. package/src/VideoPlayer/utils/display/Display.ts +0 -10
  45. package/src/VideoPlayer/utils/display/index.ts +0 -1
  46. package/src/VideoPlayer/utils/format/index.ts +0 -1
  47. package/src/VideoPlayer/utils/format/timeFormatter.ts +0 -44
  48. package/src/VideoPlayer/utils/hooks/index.ts +0 -5
  49. package/src/VideoPlayer/utils/hooks/useAdEventHandler.ts +0 -95
  50. package/src/VideoPlayer/utils/hooks/useOrientationLock.ts +0 -29
  51. package/src/VideoPlayer/utils/hooks/usePauseVideoOnAd.ts +0 -46
  52. package/src/VideoPlayer/utils/hooks/useVideoPlayerBack.ts +0 -66
  53. package/src/VideoPlayer/utils/hooks/useVideoResolutions.ts +0 -125
  54. package/src/VideoPlayer/utils/index.ts +0 -6
  55. package/src/VideoPlayer/utils/platform/PlatformSelector.ts +0 -13
  56. package/src/VideoPlayer/utils/platform/index.ts +0 -2
  57. package/src/VideoPlayer/utils/platform/lockOrientation.ts +0 -40
  58. package/src/VideoPlayer/utils/player/index.ts +0 -2
  59. package/src/VideoPlayer/utils/player/playerEvents.ts +0 -97
  60. package/src/VideoPlayer/utils/player/useWatchReporter.ts +0 -105
  61. package/src/VideoPlayer/utils/video/index.ts +0 -5
  62. package/src/VideoPlayer/utils/video/videoControl.ts +0 -185
  63. package/src/VideoPlayer/utils/video/videoRef.ts +0 -21
  64. package/src/VideoPlayer/utils/video/videoResume.ts +0 -23
  65. package/src/VideoPlayer/utils/video/videoSource.ts +0 -23
  66. package/src/VideoPlayer.tsx +0 -181
  67. package/src/index.tsx +0 -3
@@ -1,62 +0,0 @@
1
- import React, { createContext, useContext } from 'react';
2
- import type { EdgeInsets } from 'react-native-safe-area-context';
3
-
4
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
5
- import type { VideoAd } from '../../VideoPlayer/store/videoPlayer.type';
6
- import AdMediaControls from './AdMediaControls';
7
-
8
- interface AdControlsContextType {
9
- onAdSkip?: (ad: VideoAd) => void;
10
- onAdTracking?: ({
11
- ad,
12
- trackingUrl,
13
- event,
14
- }: {
15
- ad: VideoAd;
16
- trackingUrl: string;
17
- event: string;
18
- }) => void;
19
- }
20
-
21
- const AdControlsContext = createContext<AdControlsContextType>({});
22
-
23
- export const useAdControls = () => useContext(AdControlsContext);
24
-
25
- interface AdMediaControlsProviderProps {
26
- children: React.ReactNode;
27
- onAdSkip?: (ad: VideoAd) => void;
28
- onAdTracking?: ({
29
- ad,
30
- trackingUrl,
31
- event,
32
- }: {
33
- ad: VideoAd;
34
- trackingUrl: string;
35
- event: string;
36
- }) => void;
37
- onClose?: () => void;
38
- insets: EdgeInsets;
39
- }
40
-
41
- const AdMediaControlsProvider: React.FC<AdMediaControlsProviderProps> = ({
42
- children,
43
- onAdSkip,
44
- onAdTracking,
45
- onClose,
46
- insets,
47
- }) => {
48
- const isAdPlaying = useAdsPlayerStore((state) => state.isAdPlaying);
49
-
50
- if (!isAdPlaying) {
51
- return <>{children}</>;
52
- }
53
-
54
- return (
55
- <AdControlsContext.Provider value={{ onAdSkip, onAdTracking }}>
56
- {children}
57
- <AdMediaControls onClose={onClose} insets={insets} />
58
- </AdControlsContext.Provider>
59
- );
60
- };
61
-
62
- export default AdMediaControlsProvider;
@@ -1,63 +0,0 @@
1
- import React, { memo, useCallback, useMemo } from 'react';
2
- import { Animated, StyleSheet, TouchableOpacity, View } from 'react-native';
3
- import { scale } from 'react-native-size-matters';
4
- import { Play, Pause } from 'lucide-react-native';
5
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
6
- import { useAdControlsAutoHide } from '../utils/useAdControlsAutoHide';
7
- import RotatingLoader from '../components/RotatingLoader';
8
- import globalStyles from '../../VideoPlayer/styles/globalStyles';
9
-
10
- const AdMiddleControls: React.FC = () => {
11
- const { isAdPaused, isAdBuffering, setIsAdPaused } = useAdsPlayerStore();
12
- const fadeAnim = useAdControlsAutoHide();
13
-
14
- const handlePlayPause = useCallback(() => {
15
- setIsAdPaused(!isAdPaused);
16
- }, [isAdPaused, setIsAdPaused]);
17
-
18
- // Memoize container style
19
- const containerStyle = useMemo(
20
- () => [styles.container, { opacity: fadeAnim }],
21
- [fadeAnim]
22
- );
23
-
24
- return (
25
- <Animated.View style={containerStyle} pointerEvents="box-none">
26
- {isAdBuffering ? (
27
- <RotatingLoader
28
- color="#fff"
29
- autoRotate={isAdBuffering}
30
- size={scale(50)}
31
- />
32
- ) : (
33
- <View pointerEvents="auto">
34
- <TouchableOpacity
35
- onPress={handlePlayPause}
36
- style={styles.button}
37
- activeOpacity={0.7}
38
- >
39
- {isAdPaused ? (
40
- <Play size={scale(40)} color="#fff" fill="#fff" />
41
- ) : (
42
- <Pause size={scale(40)} color="#fff" fill="#fff" />
43
- )}
44
- </TouchableOpacity>
45
- </View>
46
- )}
47
- </Animated.View>
48
- );
49
- };
50
-
51
- const styles = StyleSheet.create({
52
- container: {
53
- ...globalStyles.absoluteFill,
54
- justifyContent: 'center',
55
- alignItems: 'center',
56
- },
57
- button: {
58
- justifyContent: 'center',
59
- alignItems: 'center',
60
- },
61
- });
62
-
63
- export default memo(AdMiddleControls);
@@ -1,191 +0,0 @@
1
- import React, { memo, useMemo } from 'react';
2
- import {
3
- Animated,
4
- StyleSheet,
5
- Text,
6
- TouchableOpacity,
7
- View,
8
- Platform,
9
- } from 'react-native';
10
- import { moderateScale } from 'react-native-size-matters';
11
- import { RFValue } from 'react-native-responsive-fontsize';
12
- import { X } from 'lucide-react-native';
13
- import { useVideoPlayerStore } from '../../VideoPlayer/store/videoPlayerStore';
14
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
15
- import { useAdControlsAutoHide } from '../utils/useAdControlsAutoHide';
16
- import { formatTime } from '../../VideoPlayer/utils';
17
-
18
- interface AdTopControlsProps {
19
- onClose?: () => void;
20
- }
21
-
22
- const AdTopControls: React.FC<AdTopControlsProps> = ({ onClose }) => {
23
- const controlsVisible = useVideoPlayerStore((state) => state.controlsVisible);
24
- const currentAd = useAdsPlayerStore((state) => state.currentAd);
25
- const adCurrentTime = useAdsPlayerStore((state) => state.adCurrentTime);
26
- const adDuration = useAdsPlayerStore((state) => state.adDuration);
27
- const fadeAnim = useAdControlsAutoHide();
28
-
29
- const adTimeRemaining = useMemo(
30
- () => Math.max(0, (currentAd?.duration ?? adDuration) - adCurrentTime),
31
- [currentAd?.duration, adDuration, adCurrentTime]
32
- );
33
-
34
- // Memoize styles to avoid recalculation
35
- const adLabelContainerStyle = useMemo(
36
- () => [
37
- styles.adLabelContainer,
38
- controlsVisible
39
- ? styles.adLabelContainerVisible
40
- : styles.adLabelContainerHidden,
41
- ],
42
- [controlsVisible]
43
- );
44
-
45
- const adBadgeStyle = useMemo(
46
- () => [
47
- styles.adBadge,
48
- controlsVisible ? styles.adBadgeVisible : styles.adBadgeHidden,
49
- ],
50
- [controlsVisible]
51
- );
52
-
53
- const closeButtonStyle = useMemo(
54
- () => [styles.closeButtonContainer, { opacity: fadeAnim }],
55
- [fadeAnim]
56
- );
57
-
58
- return (
59
- <View style={styles.container}>
60
- {currentAd && (
61
- <Animated.View style={adLabelContainerStyle}>
62
- <View style={adBadgeStyle}>
63
- <View style={styles.adLabelWrapper}>
64
- <Text style={styles.adLabelText}>Ad</Text>
65
- </View>
66
- <View style={styles.separator} />
67
- <Text style={styles.adTimeText}>{formatTime(adTimeRemaining)}</Text>
68
- </View>
69
- </Animated.View>
70
- )}
71
- <Animated.View style={closeButtonStyle}>
72
- <TouchableOpacity
73
- onPress={onClose}
74
- style={styles.closeButton}
75
- activeOpacity={0.7}
76
- >
77
- <View style={styles.closeButtonBackground}>
78
- <X size={moderateScale(22)} color="#fff" strokeWidth={2.5} />
79
- </View>
80
- </TouchableOpacity>
81
- </Animated.View>
82
- </View>
83
- );
84
- };
85
-
86
- const styles = StyleSheet.create({
87
- container: {
88
- flexDirection: 'row',
89
- justifyContent: 'space-between',
90
- alignItems: 'center',
91
- marginTop: moderateScale(8),
92
- paddingHorizontal: moderateScale(10),
93
- paddingBottom: 0,
94
- },
95
- adLabelContainer: {
96
- flex: 1,
97
- alignItems: 'flex-start',
98
- },
99
- adLabelContainerVisible: {
100
- opacity: 1,
101
- },
102
- adLabelContainerHidden: {
103
- opacity: 0.95,
104
- },
105
- adBadge: {
106
- flexDirection: 'row',
107
- alignItems: 'center',
108
- borderRadius: moderateScale(8),
109
- paddingHorizontal: moderateScale(5),
110
- paddingVertical: moderateScale(3),
111
- borderWidth: 1,
112
- },
113
- adBadgeVisible: {
114
- backgroundColor: 'rgba(0, 0, 0, 0.85)',
115
- borderColor: 'rgba(255, 255, 255, 0.2)',
116
- ...Platform.select({
117
- ios: {
118
- shadowColor: '#000',
119
- shadowOffset: { width: 0, height: 2 },
120
- shadowOpacity: 0.4,
121
- shadowRadius: 5,
122
- },
123
- android: {
124
- elevation: 5,
125
- },
126
- }),
127
- },
128
- adBadgeHidden: {
129
- backgroundColor: 'rgba(0, 0, 0, 0.9)',
130
- borderColor: 'rgba(255, 255, 255, 0.15)',
131
- ...Platform.select({
132
- ios: {
133
- shadowColor: '#000',
134
- shadowOffset: { width: 0, height: 2 },
135
- shadowOpacity: 0.3,
136
- shadowRadius: 4,
137
- },
138
- android: {
139
- elevation: 4,
140
- },
141
- }),
142
- },
143
- adLabelWrapper: {
144
- backgroundColor: 'rgb(255, 255, 255)',
145
- borderRadius: moderateScale(3),
146
- paddingHorizontal: moderateScale(5),
147
- paddingVertical: moderateScale(1),
148
- },
149
- adLabelText: {
150
- color: 'red',
151
- fontSize: RFValue(10),
152
- fontWeight: '700',
153
- letterSpacing: 0.1,
154
- textTransform: 'uppercase',
155
- },
156
- separator: {
157
- width: 1,
158
- height: moderateScale(12),
159
- backgroundColor: 'rgba(255, 255, 255, 0.3)',
160
- marginHorizontal: moderateScale(5),
161
- },
162
- adTimeText: {
163
- color: '#fff',
164
- fontSize: RFValue(13),
165
- fontWeight: '700',
166
- fontVariant: ['tabular-nums'],
167
- letterSpacing: 0.3,
168
- minWidth: moderateScale(40),
169
- },
170
- closeButtonContainer: {
171
- justifyContent: 'flex-end',
172
- alignItems: 'flex-end',
173
- },
174
- closeButton: {
175
- justifyContent: 'center',
176
- alignItems: 'center',
177
- padding: moderateScale(2),
178
- },
179
- closeButtonBackground: {
180
- width: moderateScale(32),
181
- height: moderateScale(32),
182
- borderRadius: moderateScale(16),
183
- backgroundColor: 'rgba(0, 0, 0, 0.6)',
184
- justifyContent: 'center',
185
- alignItems: 'center',
186
- borderWidth: 1,
187
- borderColor: 'rgba(255, 255, 255, 0.2)',
188
- },
189
- });
190
-
191
- export default memo(AdTopControls);
@@ -1,5 +0,0 @@
1
- export { default as AdMediaControls } from './AdMediaControls';
2
- export { default as AdMediaControlsProvider } from './AdMediaControlsProvider';
3
- export { default as AdTopControls } from './AdTopControls';
4
- export { default as AdMiddleControls } from './AdMiddleControls';
5
- export { default as AdBottomControls } from './AdBottomControls';
@@ -1,79 +0,0 @@
1
- import React, { useEffect, useRef } from 'react';
2
- import {
3
- StyleSheet,
4
- Animated,
5
- Easing,
6
- type StyleProp,
7
- type ViewStyle,
8
- } from 'react-native';
9
- import { Loader } from 'lucide-react-native';
10
- import { moderateScale } from 'react-native-size-matters';
11
-
12
- interface RotatingLoaderProps {
13
- size?: number;
14
- color?: string;
15
- containerStyle?: StyleProp<ViewStyle>;
16
- rotationDuration?: number;
17
- autoRotate?: boolean; // Whether to auto-rotate (default: true)
18
- }
19
-
20
- const RotatingLoader: React.FC<RotatingLoaderProps> = ({
21
- size = moderateScale(35),
22
- color = '#fff',
23
- containerStyle,
24
- rotationDuration = 1300,
25
- autoRotate = true,
26
- }) => {
27
- const rotateAnim = useRef(new Animated.Value(0)).current;
28
-
29
- useEffect(() => {
30
- if (autoRotate) {
31
- rotateAnim.setValue(0);
32
- const animation = Animated.loop(
33
- Animated.timing(rotateAnim, {
34
- toValue: 1,
35
- duration: rotationDuration,
36
- easing: Easing.linear,
37
- useNativeDriver: true,
38
- })
39
- );
40
- animation.start();
41
-
42
- return () => {
43
- animation.stop();
44
- rotateAnim.stopAnimation();
45
- };
46
- }
47
- return undefined;
48
- }, [autoRotate, rotationDuration, rotateAnim]);
49
-
50
- return (
51
- <Animated.View
52
- style={[
53
- styles.container,
54
- containerStyle,
55
- {
56
- transform: [
57
- {
58
- rotate: rotateAnim.interpolate({
59
- inputRange: [0, 1],
60
- outputRange: ['0deg', '360deg'],
61
- }),
62
- },
63
- ],
64
- },
65
- ]}
66
- >
67
- <Loader size={size} color={color} />
68
- </Animated.View>
69
- );
70
- };
71
-
72
- export default RotatingLoader;
73
-
74
- const styles = StyleSheet.create({
75
- container: {
76
- justifyContent: 'center',
77
- alignItems: 'center',
78
- },
79
- });
@@ -1,4 +0,0 @@
1
- export { default as AdsPlayer } from './AdsPlayer';
2
- export type { AdsPlayerProps, AdsPlayerRef } from './AdsPlayer';
3
- export { useAdsManager } from './utils/useAdsManager';
4
- export * from './store';
@@ -1,29 +0,0 @@
1
- import type { VideoAd } from '../../VideoPlayer/store/videoPlayer.type';
2
-
3
- export interface AdState {
4
- currentAd: VideoAd | null;
5
- isAdPlaying: boolean;
6
- isAdPaused: boolean;
7
- isAdMuted: boolean;
8
- isAdBuffering: boolean;
9
- adCurrentTime: number;
10
- adDuration: number;
11
- pendingMidRollAds: VideoAd[];
12
- showSkipButton: boolean;
13
- resumeTime: number | null;
14
- }
15
-
16
- export interface AdsPlayerStore extends AdState {
17
- setCurrentAd: (ad: VideoAd | null) => void;
18
- setIsAdPlaying: (isPlaying: boolean) => void;
19
- setIsAdPaused: (isPaused: boolean) => void;
20
- setIsAdMuted: (isMuted: boolean) => void;
21
- setIsAdBuffering: (isBuffering: boolean) => void;
22
- setAdCurrentTime: (time: number) => void;
23
- setAdDuration: (duration: number) => void;
24
- setShowSkipButton: (show: boolean) => void;
25
- addPendingMidRollAd: (ad: VideoAd) => void;
26
- clearPendingMidRollAds: () => void;
27
- setResumeTime: (time: number | null) => void;
28
- resetAdsStore: () => void;
29
- }
@@ -1,59 +0,0 @@
1
- import { create } from 'zustand';
2
- import { createJSONStorage, persist } from 'zustand/middleware';
3
- import { MMKV } from 'react-native-mmkv';
4
- import type { AdsPlayerStore, AdState } from './adsPlayer.type';
5
-
6
- export const adsStorage = new MMKV({
7
- id: 'adsPlayerStorage',
8
- encryptionKey: 'adsPlayerKey',
9
- });
10
-
11
- export const adsMmkvStorage = {
12
- setItem: (key: string, value: string) => adsStorage.set(key, value),
13
- getItem: (key: string) => adsStorage.getString(key) ?? null,
14
- removeItem: (key: string) => adsStorage.delete(key),
15
- };
16
-
17
- const adsStoreDataDefaults: AdState = {
18
- currentAd: null,
19
- isAdPlaying: false,
20
- isAdPaused: false,
21
- isAdMuted: false,
22
- isAdBuffering: false,
23
- adCurrentTime: 0,
24
- adDuration: 0,
25
- pendingMidRollAds: [],
26
- showSkipButton: false,
27
- resumeTime: null,
28
- };
29
-
30
- export const useAdsPlayerStore = create<AdsPlayerStore>()(
31
- persist(
32
- (set) => ({
33
- ...adsStoreDataDefaults,
34
-
35
- setCurrentAd: (currentAd) => set({ currentAd }),
36
- setIsAdPlaying: (isAdPlaying) => set({ isAdPlaying }),
37
- setIsAdPaused: (isAdPaused) => set({ isAdPaused }),
38
- setIsAdMuted: (isAdMuted) => set({ isAdMuted }),
39
- setIsAdBuffering: (isAdBuffering) => set({ isAdBuffering }),
40
- setAdCurrentTime: (adCurrentTime) => set({ adCurrentTime }),
41
- setAdDuration: (adDuration) => set({ adDuration }),
42
- setShowSkipButton: (showSkipButton) => set({ showSkipButton }),
43
- setResumeTime: (resumeTime) => set({ resumeTime }),
44
- addPendingMidRollAd: (ad) =>
45
- set((state) => ({
46
- pendingMidRollAds: [...state.pendingMidRollAds, ad],
47
- })),
48
- clearPendingMidRollAds: () => set({ pendingMidRollAds: [] }),
49
- resetAdsStore: () => {
50
- set(adsStoreDataDefaults);
51
- adsStorage.clearAll();
52
- },
53
- }),
54
- {
55
- name: 'AdsPlayerStorage',
56
- storage: createJSONStorage(() => adsMmkvStorage),
57
- }
58
- )
59
- );
@@ -1,2 +0,0 @@
1
- export * from './adsPlayerStore';
2
- export * from './adsPlayer.type';
@@ -1,29 +0,0 @@
1
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
2
-
3
- /**
4
- * Reusable function to reset ad state
5
- * Consolidates duplicate logic for resetting ad state across components
6
- */
7
- export const resetAdState = () => {
8
- try {
9
- const {
10
- setIsAdPlaying,
11
- setCurrentAd,
12
- setAdCurrentTime,
13
- setAdDuration,
14
- setShowSkipButton,
15
- setIsAdPaused,
16
- setIsAdBuffering,
17
- } = useAdsPlayerStore.getState();
18
-
19
- setIsAdPlaying(false);
20
- setCurrentAd(null);
21
- setAdCurrentTime(0);
22
- setAdDuration(0);
23
- setShowSkipButton(false);
24
- setIsAdPaused(false);
25
- setIsAdBuffering(false);
26
- } catch (error) {
27
- console.error('Error resetting ad state:', error);
28
- }
29
- };
@@ -1,69 +0,0 @@
1
- import { Linking } from 'react-native';
2
- import type { VideoAd } from '../../VideoPlayer/store/videoPlayer.type';
3
- import { useVideoPlayerStore } from '../../VideoPlayer/store/videoPlayerStore';
4
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
5
- import { createRef } from 'react';
6
- import type { AdsPlayerRef } from '../AdsPlayer';
7
- export const adVideoRef = createRef<AdsPlayerRef>();
8
-
9
- export const getDomainFromUrl = (url: string | undefined): string => {
10
- if (!url) return '';
11
- const domain = url.replace(/^https?:\/\//, '').split('/')[0];
12
- return domain || '';
13
- };
14
-
15
- export const handleAdClickThrough = async (
16
- ad: VideoAd,
17
- onAdTracking?: ({
18
- ad,
19
- trackingUrl,
20
- event,
21
- }: {
22
- ad: VideoAd;
23
- trackingUrl: string;
24
- event: string;
25
- }) => void
26
- ): Promise<void> => {
27
- if (!ad.clickThroughUrl) return;
28
-
29
- try {
30
- const canOpen = await Linking.canOpenURL(ad.clickThroughUrl);
31
- if (canOpen) {
32
- await Linking.openURL(ad.clickThroughUrl);
33
- if (ad.tracking?.click && onAdTracking) {
34
- onAdTracking({
35
- ad,
36
- trackingUrl: ad.tracking.click,
37
- event: 'click',
38
- });
39
- }
40
- }
41
- } catch (error) {
42
- console.error('Error opening ad URL:', error);
43
- }
44
- };
45
-
46
- export const hideAdControls = (): void => {
47
- const { setControlsVisible } = useVideoPlayerStore.getState();
48
- const { isAdPaused } = useAdsPlayerStore.getState();
49
- if (isAdPaused) {
50
- return;
51
- }
52
- setControlsVisible(false);
53
- };
54
-
55
- export const showAdControls = (): void => {
56
- const { setControlsVisible } = useVideoPlayerStore.getState();
57
- setControlsVisible(true);
58
- };
59
-
60
- export const toggleAdControls = (): void => {
61
- const { controlsVisible, setControlsVisible } =
62
- useVideoPlayerStore.getState();
63
- const { isAdPaused } = useAdsPlayerStore.getState();
64
- if (isAdPaused) {
65
- setControlsVisible(true);
66
- } else {
67
- setControlsVisible(!controlsVisible);
68
- }
69
- };
@@ -1,32 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
- import { Animated } from 'react-native';
3
- import { useVideoPlayerStore } from '../../VideoPlayer/store/videoPlayerStore';
4
- import { useAdsPlayerStore } from '../store/adsPlayerStore';
5
- import { hideAdControls } from './controls';
6
-
7
- export const useAdControlsAutoHide = (): Animated.Value => {
8
- const { controlsVisible, controlsTimer } = useVideoPlayerStore();
9
- const { isAdPaused } = useAdsPlayerStore();
10
- const timeoutId = useRef<NodeJS.Timeout | null>(null);
11
- const fadeAnim = useRef(new Animated.Value(0)).current;
12
-
13
- useEffect(() => {
14
- Animated.timing(fadeAnim, {
15
- toValue: controlsVisible ? 1 : 0,
16
- duration: 200,
17
- useNativeDriver: true,
18
- }).start();
19
-
20
- if (controlsVisible && !isAdPaused) {
21
- timeoutId.current = setTimeout(() => {
22
- hideAdControls();
23
- }, controlsTimer * 1000);
24
- }
25
-
26
- return () => {
27
- if (timeoutId.current) clearTimeout(timeoutId.current);
28
- };
29
- }, [controlsVisible, controlsTimer, fadeAnim, isAdPaused]);
30
-
31
- return fadeAnim;
32
- };