@applicaster/zapp-react-native-utils 13.0.0-alpha.2635505531 → 13.0.0-alpha.3244448100
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/appUtils/keyCodes/keysByPlatform.js +4 -3
- package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
- package/appUtils/playerManager/index.ts +6 -2
- package/appUtils/playerManager/player.ts +12 -8
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -15
- package/package.json +2 -2
- package/reactHooks/player/TVSeekControlller/ISeekController.ts +28 -3
- package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +42 -91
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +205 -97
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +35 -55
- package/reactHooks/player/const.ts +1 -5
- package/reactHooks/player/index.ts +0 -6
- package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +0 -180
- package/reactHooks/player/__tests__/useAutoSeek.test.tsx +0 -123
- package/reactHooks/player/__tests__/useTapSeek.test.ts +0 -94
- package/reactHooks/player/useAutoSeek.tsx +0 -106
- package/reactHooks/player/useSeek.tsx +0 -17
- package/reactHooks/player/useTapSeek.tsx +0 -85
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { act, renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
-
|
|
4
|
-
import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
5
|
-
|
|
6
|
-
import { useAutoSeek } from "../useAutoSeek";
|
|
7
|
-
|
|
8
|
-
jest.useFakeTimers();
|
|
9
|
-
|
|
10
|
-
const rewind = jest.fn();
|
|
11
|
-
const forward = jest.fn();
|
|
12
|
-
const exitDelayedSeek = jest.fn();
|
|
13
|
-
const enterDelayedSeek = jest.fn();
|
|
14
|
-
|
|
15
|
-
jest
|
|
16
|
-
.spyOn(playerManager, "getInstanceController")
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
.mockImplementation(() => ({
|
|
19
|
-
rewind,
|
|
20
|
-
forward,
|
|
21
|
-
exitDelayedSeek,
|
|
22
|
-
enterDelayedSeek,
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
describe("useAutoSeek", () => {
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
rewind.mockReset();
|
|
28
|
-
forward.mockReset();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
describe("autoSeekStart", () => {
|
|
32
|
-
it("should call forward method on playerInstance", () => {
|
|
33
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
34
|
-
|
|
35
|
-
act(() => {
|
|
36
|
-
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
expect(forward).toBeCalled();
|
|
40
|
-
result.current.autoSeekStop();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("should call rewind method on playerManager", () => {
|
|
44
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
45
|
-
|
|
46
|
-
act(() => {
|
|
47
|
-
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
expect(rewind).toBeCalled();
|
|
51
|
-
result.current.autoSeekStop();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("should call rewind with default skip time", () => {
|
|
55
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
56
|
-
|
|
57
|
-
act(() => {
|
|
58
|
-
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
62
|
-
result.current.autoSeekStop();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("should call forward with default skip time", () => {
|
|
66
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
67
|
-
|
|
68
|
-
act(() => {
|
|
69
|
-
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
73
|
-
result.current.autoSeekStop();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it("should call rewind in intervals set in configuration", () => {
|
|
77
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
78
|
-
|
|
79
|
-
act(() => {
|
|
80
|
-
result.current.autoSeekStart(SEEK_TYPE.REWIND);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
expect(rewind).toBeCalled();
|
|
84
|
-
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
85
|
-
expect(rewind).toBeCalledTimes(4);
|
|
86
|
-
result.current.autoSeekStop();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("should call forward in intervals set in configuration", () => {
|
|
90
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
91
|
-
|
|
92
|
-
act(() => {
|
|
93
|
-
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(forward).toBeCalled();
|
|
97
|
-
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
98
|
-
expect(forward).toBeCalledTimes(4);
|
|
99
|
-
result.current.autoSeekStop();
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe("autoSeekStop", () => {
|
|
104
|
-
it("should stop calling playerManager method after autoSeekStop is called", () => {
|
|
105
|
-
const { result } = renderHook(() => useAutoSeek());
|
|
106
|
-
|
|
107
|
-
act(() => {
|
|
108
|
-
result.current.autoSeekStart(SEEK_TYPE.FORWARD);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
expect(forward).toBeCalled();
|
|
112
|
-
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
113
|
-
expect(forward).toBeCalledTimes(4);
|
|
114
|
-
|
|
115
|
-
act(() => {
|
|
116
|
-
result.current.autoSeekStop();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
|
|
120
|
-
expect(forward).toBeCalledTimes(4);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
3
|
-
import { useTapSeek } from "../useTapSeek";
|
|
4
|
-
|
|
5
|
-
import { ON_PRESS_RESET_DURATION, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
6
|
-
|
|
7
|
-
const rewind = jest.fn();
|
|
8
|
-
const forward = jest.fn();
|
|
9
|
-
|
|
10
|
-
jest
|
|
11
|
-
.spyOn(playerManager, "getInstanceController")
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
.mockImplementation(() => ({ rewind, forward }));
|
|
14
|
-
|
|
15
|
-
describe("useTapSeek", () => {
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
rewind.mockReset();
|
|
18
|
-
forward.mockReset();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
describe("forward", () => {
|
|
22
|
-
it("should call forward method on playerManager", () => {
|
|
23
|
-
const { result } = renderHook(() => useTapSeek());
|
|
24
|
-
|
|
25
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
26
|
-
expect(forward).toBeCalled();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should call forward with default skip time", () => {
|
|
30
|
-
const { result } = renderHook(() => useTapSeek());
|
|
31
|
-
|
|
32
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
33
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("should multiply skip time for every call", async () => {
|
|
37
|
-
const { result } = renderHook(() => useTapSeek());
|
|
38
|
-
|
|
39
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
40
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
41
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
42
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should reset multiplier if waiting more then resetDuration between press actions", () => {
|
|
46
|
-
const { result, waitFor } = renderHook(() => useTapSeek());
|
|
47
|
-
|
|
48
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
49
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
50
|
-
waitFor(jest.fn(), { timeout: ON_PRESS_RESET_DURATION });
|
|
51
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
52
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("rewind", () => {
|
|
57
|
-
it("should call rewind method on playerManager", () => {
|
|
58
|
-
const { result } = renderHook(() => useTapSeek());
|
|
59
|
-
|
|
60
|
-
result.current(SEEK_TYPE.REWIND);
|
|
61
|
-
expect(rewind).toBeCalled();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("should call rewind with default skip time", () => {
|
|
65
|
-
const { result } = renderHook(() => useTapSeek());
|
|
66
|
-
|
|
67
|
-
result.current(SEEK_TYPE.REWIND);
|
|
68
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("should multiply skip time for every call", async () => {
|
|
72
|
-
const { result } = renderHook(() => useTapSeek());
|
|
73
|
-
|
|
74
|
-
result.current(SEEK_TYPE.REWIND);
|
|
75
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
76
|
-
result.current(SEEK_TYPE.REWIND);
|
|
77
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe("mixed usage", () => {
|
|
82
|
-
it("should reset timer if different type of event is emitted", () => {
|
|
83
|
-
const { result } = renderHook(() => useTapSeek());
|
|
84
|
-
result.current(SEEK_TYPE.REWIND);
|
|
85
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
|
|
86
|
-
|
|
87
|
-
result.current(SEEK_TYPE.REWIND);
|
|
88
|
-
expect(rewind).toBeCalledWith(SKIP_TIME_BASE * 2);
|
|
89
|
-
|
|
90
|
-
result.current(SEEK_TYPE.FORWARD);
|
|
91
|
-
expect(forward).toBeCalledWith(SKIP_TIME_BASE);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
|
|
3
|
-
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
|
|
4
|
-
import {
|
|
5
|
-
MAX_SEEK_TIME,
|
|
6
|
-
ON_HOLD_INTERVAL,
|
|
7
|
-
SEEK_TYPE,
|
|
8
|
-
SKIP_TIME_BASE,
|
|
9
|
-
} from "./const";
|
|
10
|
-
import { noop } from "../../functionUtils";
|
|
11
|
-
|
|
12
|
-
export const useAutoSeek = (resetHUDTimer = noop) => {
|
|
13
|
-
const [isRunning, setIsRunning] = useState<boolean>(false);
|
|
14
|
-
const [direction, setDirection] = useState<Nullable<SEEK_TYPE>>(null);
|
|
15
|
-
const [multiplier, setMultiplier] = useState(1);
|
|
16
|
-
|
|
17
|
-
const intervalTimer = React.useRef(null);
|
|
18
|
-
const prevRunning = usePrevious(isRunning);
|
|
19
|
-
|
|
20
|
-
const setIntervalTimer = (cb) => {
|
|
21
|
-
if (intervalTimer.current) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
intervalTimer.current = setInterval(() => {
|
|
26
|
-
intervalTimer.current = null;
|
|
27
|
-
cb();
|
|
28
|
-
}, ON_HOLD_INTERVAL);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const clearIntervalTimer = () => {
|
|
32
|
-
clearInterval(intervalTimer.current);
|
|
33
|
-
intervalTimer.current = null;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const resetState = () => {
|
|
37
|
-
setIsRunning(false);
|
|
38
|
-
setDirection(null);
|
|
39
|
-
setMultiplier(1);
|
|
40
|
-
clearIntervalTimer();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
const player = playerManager.getInstanceController();
|
|
45
|
-
if (!player) return;
|
|
46
|
-
|
|
47
|
-
if (isRunning) {
|
|
48
|
-
player?.enterDelayedSeek();
|
|
49
|
-
} else if (!isRunning) {
|
|
50
|
-
player.exitDelayedSeek();
|
|
51
|
-
}
|
|
52
|
-
}, [isRunning]);
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
if (!isRunning) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const player = playerManager.getInstanceController();
|
|
60
|
-
|
|
61
|
-
if (!player) return;
|
|
62
|
-
|
|
63
|
-
if (direction) {
|
|
64
|
-
player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
|
|
65
|
-
resetHUDTimer();
|
|
66
|
-
}
|
|
67
|
-
}, [multiplier, direction, isRunning]);
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
if (isRunning && isRunning !== prevRunning) {
|
|
71
|
-
setIntervalTimer(() => {
|
|
72
|
-
setMultiplier((prev) => {
|
|
73
|
-
return prev + 1;
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
} else if (!isRunning && isRunning !== prevRunning) {
|
|
77
|
-
resetState();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return () => {
|
|
81
|
-
clearIntervalTimer();
|
|
82
|
-
};
|
|
83
|
-
}, [isRunning, direction]);
|
|
84
|
-
|
|
85
|
-
const autoSeekStop = React.useCallback(() => {
|
|
86
|
-
resetState();
|
|
87
|
-
}, []);
|
|
88
|
-
|
|
89
|
-
const autoSeekStart = React.useCallback(
|
|
90
|
-
(eventType: SEEK_TYPE) => {
|
|
91
|
-
// Check if there is another session running
|
|
92
|
-
if (isRunning) {
|
|
93
|
-
autoSeekStop();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
setDirection(eventType);
|
|
97
|
-
setIsRunning(true);
|
|
98
|
-
},
|
|
99
|
-
[isRunning, autoSeekStop]
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
return React.useMemo(
|
|
103
|
-
() => ({ autoSeekStart, autoSeekStop }),
|
|
104
|
-
[autoSeekStart, autoSeekStop]
|
|
105
|
-
);
|
|
106
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
2
|
-
import { noop } from "../../functionUtils";
|
|
3
|
-
import { TVSeekController } from "./TVSeekControlller/TVSeekController";
|
|
4
|
-
|
|
5
|
-
export const useSeek = (resetHUDTimer = noop) => {
|
|
6
|
-
return useMemo(() => TVSeekController.getInstance().getSeekMethods(), []);
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export const withUseSeek = (Component) =>
|
|
10
|
-
Object.assign(
|
|
11
|
-
(props) => {
|
|
12
|
-
const seekMethods = useSeek(props?.resetHUDTimer);
|
|
13
|
-
|
|
14
|
-
return <Component {...props} seekMethods={seekMethods} />;
|
|
15
|
-
},
|
|
16
|
-
{ displayName: "WithUseSeek" }
|
|
17
|
-
);
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { useCallback, useRef, useState } from "react";
|
|
2
|
-
import * as R from "ramda";
|
|
3
|
-
import {
|
|
4
|
-
MAX_SEEK_TIME,
|
|
5
|
-
ON_PRESS_RESET_DURATION,
|
|
6
|
-
SEEK_TYPE,
|
|
7
|
-
SKIP_TIME_BASE,
|
|
8
|
-
} from "./const";
|
|
9
|
-
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
10
|
-
|
|
11
|
-
type SeekType = SEEK_TYPE | null;
|
|
12
|
-
|
|
13
|
-
const getSkipTime = (multiplier) =>
|
|
14
|
-
R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
|
|
15
|
-
|
|
16
|
-
export const useTapSeek = () => {
|
|
17
|
-
const [resumeTimer, setResumeTimer] = useState<NodeJS.Timeout>(null);
|
|
18
|
-
const onPressMultiplier = useRef(1);
|
|
19
|
-
const lastPressTime = useRef(0);
|
|
20
|
-
const currentOnPressEventType = useRef<SeekType>(null);
|
|
21
|
-
|
|
22
|
-
const resetMultiplier = useCallback(() => {
|
|
23
|
-
onPressMultiplier.current = 1;
|
|
24
|
-
}, []);
|
|
25
|
-
|
|
26
|
-
const handlePressEvent = useCallback(
|
|
27
|
-
(eventType) => {
|
|
28
|
-
const player = playerManager.getInstanceController();
|
|
29
|
-
if (!player) return;
|
|
30
|
-
|
|
31
|
-
const now = Date.now();
|
|
32
|
-
const timeSinceLastPress = now - lastPressTime.current;
|
|
33
|
-
const isSameEventType = eventType === currentOnPressEventType.current;
|
|
34
|
-
|
|
35
|
-
const isWithinResetDuration =
|
|
36
|
-
timeSinceLastPress <= ON_PRESS_RESET_DURATION;
|
|
37
|
-
|
|
38
|
-
const shouldIncreaseMultiplier = isSameEventType && isWithinResetDuration;
|
|
39
|
-
|
|
40
|
-
if (shouldIncreaseMultiplier) {
|
|
41
|
-
onPressMultiplier.current += 1;
|
|
42
|
-
} else {
|
|
43
|
-
resetMultiplier();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const seekTime = getSkipTime(onPressMultiplier.current);
|
|
47
|
-
|
|
48
|
-
player[eventType](seekTime);
|
|
49
|
-
|
|
50
|
-
if (resumeTimer) {
|
|
51
|
-
clearTimeout(resumeTimer);
|
|
52
|
-
|
|
53
|
-
const timer = setTimeout(() => {
|
|
54
|
-
player.exitDelayedSeek();
|
|
55
|
-
setResumeTimer(null);
|
|
56
|
-
}, 2000);
|
|
57
|
-
|
|
58
|
-
setResumeTimer(timer);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const clicksBeforePause = 3;
|
|
62
|
-
|
|
63
|
-
// Only pause player if user starts to seek on large increments
|
|
64
|
-
if (onPressMultiplier.current > clicksBeforePause) {
|
|
65
|
-
if (!player.isPaused()) {
|
|
66
|
-
player.enterDelayedSeek();
|
|
67
|
-
|
|
68
|
-
const timer = setTimeout(() => {
|
|
69
|
-
player.exitDelayedSeek();
|
|
70
|
-
setResumeTimer(null);
|
|
71
|
-
}, 2000);
|
|
72
|
-
|
|
73
|
-
clearTimeout(resumeTimer);
|
|
74
|
-
setResumeTimer(timer);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
lastPressTime.current = now;
|
|
79
|
-
currentOnPressEventType.current = eventType;
|
|
80
|
-
},
|
|
81
|
-
[resetMultiplier, resumeTimer]
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
return handlePressEvent;
|
|
85
|
-
};
|