@applicaster/zapp-react-native-utils 13.0.0-alpha.2635505531 → 13.0.0-alpha.2761483533
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/actionsExecutor/ActionExecutor.ts +16 -9
- package/actionsExecutor/ActionExecutorContext.tsx +74 -9
- package/alertUtils/alert.ts +148 -0
- package/alertUtils/index.ts +1 -148
- package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
- package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/{Hook.js → Hook.ts} +35 -23
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +10 -8
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +693 -0
- package/appUtils/HooksManager/__tests__/hook.test.js +196 -184
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +96 -99
- package/appUtils/HooksManager/{constants.js → constants.ts} +1 -1
- package/appUtils/HooksManager/{index.js → index.ts} +121 -112
- package/appUtils/HooksManager/types.ts +119 -0
- package/appUtils/RiverFocusManager/index.js +17 -12
- package/appUtils/accessibilityManager/index.ts +42 -1
- package/appUtils/contextKeysManager/contextResolver.ts +73 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +6 -6
- package/appUtils/focusManager/index.ts +92 -64
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +25 -3
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +1 -3
- package/appUtils/focusManager/utils/enums.ts +4 -0
- package/appUtils/focusManagerAux/utils/index.ts +4 -3
- package/appUtils/{index.js → index.ts} +1 -1
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +4 -4
- package/appUtils/keyCodes/{index.js → index.ts} +2 -0
- package/appUtils/keyCodes/keys/index.ts +3 -0
- package/appUtils/keyCodes/{keys.android.js → keys/keyEventMapper.ts} +0 -19
- package/appUtils/keyCodes/keys/keys.android.ts +18 -0
- package/appUtils/keyCodes/keys/keys.ios.ts +25 -0
- package/appUtils/keyCodes/keys/keys.ts +15 -0
- package/appUtils/keyCodes/{keysByPlatform.js → keys/keysByPlatform.ts} +4 -3
- package/appUtils/keyCodes/keysByPlatform.ts +8 -0
- package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/platform/const.ts +14 -0
- package/appUtils/platform/platformUtils.ts +17 -15
- package/appUtils/playerManager/index.ts +6 -2
- package/appUtils/playerManager/player.ts +12 -8
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -15
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/domUtils/{cookieManager.js → cookieManager.ts} +1 -2
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- package/functionUtils/index.ts +15 -11
- package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
- package/idleUtils/index.ts +1 -1
- package/idleUtils/withTimeout.ts +15 -2
- package/logger/const.ts +9 -67
- package/manifestUtils/__tests__/createConfig.test.js +18 -16
- package/modalState/index.ts +1 -5
- package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
- package/navigationUtils/__tests__/itemTypes.test.js +2 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
- package/navigationUtils/index.ts +14 -5
- package/package.json +3 -2
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -1
- package/reactHooks/cell-click/__tests__/index.test.js +10 -2
- package/reactHooks/cell-click/index.ts +7 -1
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
- package/reactHooks/feed/useFeedLoader.tsx +1 -1
- package/reactHooks/feed/usePipesCacheReset.ts +5 -5
- package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
- package/reactHooks/layout/__tests__/index.test.tsx +10 -10
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
- package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
- package/reactHooks/navigation/index.ts +29 -218
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useIsScreenActive.ts +17 -0
- package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
- package/reactHooks/navigation/useNavigationType.ts +15 -0
- package/reactHooks/navigation/usePathname.ts +4 -0
- package/reactHooks/navigation/useRoute.ts +100 -0
- package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
- package/reactHooks/player/TVSeekControlller/ISeekController.ts +28 -3
- package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +43 -96
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +203 -97
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +35 -55
- package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -10
- package/reactHooks/player/const.ts +1 -5
- package/reactHooks/player/index.ts +0 -6
- package/reactUtils/__tests__/reactUtils.test.js +10 -28
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +19 -19
- package/reactUtils/createContext/__tests__/__snapshots__/index.test.js.snap +2 -2
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +8 -8
- package/reactUtils/index.ts +0 -14
- package/theme/__mocks__/index.ts +4 -0
- package/time/Timer.ts +1 -1
- package/types.ts +1 -0
- package/appUtils/keyCodes/keys.ios.js +0 -46
- package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +0 -180
- package/reactHooks/player/useAutoSeek.tsx +0 -106
- package/reactHooks/player/useSeek.tsx +0 -17
- package/reactHooks/player/useTapSeek.tsx +0 -85
- /package/appUtils/HooksManager/{logger.js → logger.ts} +0 -0
- /package/appUtils/{directionHelper.js → directionHelper.ts} +0 -0
- /package/appUtils/keyCodes/{androidTVKeys.js → androidTVKeys.ts} +0 -0
- /package/appUtils/keyCodes/{keys.web.js → keys/keys.web.ts} +0 -0
- /package/appUtils/{localizationsHelper.js → localizationsHelper.ts} +0 -0
- /package/domUtils/{logger.js → logger.ts} +0 -0
- /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
|
@@ -1,7 +1,32 @@
|
|
|
1
|
-
import { SEEK_TYPE } from "../const";
|
|
1
|
+
import { MAX_SEEK_TIME, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
2
|
+
|
|
3
|
+
export interface ISeekControllerDelegate {
|
|
4
|
+
handleDelayedSeek(offset: number): void;
|
|
5
|
+
handleSeek(offset: number): void;
|
|
6
|
+
handleSeekComplete(): void;
|
|
7
|
+
handlePlayerPause(): void;
|
|
8
|
+
}
|
|
2
9
|
|
|
3
10
|
export interface ISeekController {
|
|
4
|
-
|
|
5
|
-
|
|
11
|
+
title: string;
|
|
12
|
+
onStartSeek(seekType: SEEK_TYPE): void;
|
|
13
|
+
onSeekEnd(): void;
|
|
6
14
|
reset(): void;
|
|
7
15
|
}
|
|
16
|
+
|
|
17
|
+
export class SeekIncrementalBaseStrategy {
|
|
18
|
+
private skipMultiplier = 1;
|
|
19
|
+
|
|
20
|
+
getSkipTime = () =>
|
|
21
|
+
Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * this.skipMultiplier);
|
|
22
|
+
|
|
23
|
+
increment = () => {
|
|
24
|
+
this.skipMultiplier++;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
getSkipMultiplier = () => this.skipMultiplier;
|
|
28
|
+
|
|
29
|
+
reset = () => {
|
|
30
|
+
this.skipMultiplier = 1;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -1,117 +1,64 @@
|
|
|
1
|
-
// LongPressSeekController.ts
|
|
2
|
-
import { ISeekController } from "./ISeekController";
|
|
3
|
-
import { SEEK_TYPE } from "../const";
|
|
4
1
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
2
|
+
ISeekController,
|
|
3
|
+
ISeekControllerDelegate,
|
|
4
|
+
SeekIncrementalBaseStrategy,
|
|
5
|
+
} from "./ISeekController";
|
|
6
|
+
import { SEEK_TYPE } from "../const";
|
|
7
|
+
import { log_debug, log_error, log_verbose } from "./TVSeekController";
|
|
8
|
+
import { interval, Subscription } from "rxjs";
|
|
9
|
+
import { tap } from "rxjs/operators";
|
|
12
10
|
|
|
13
|
-
/**
|
|
14
|
-
* Example interface for the configuration needed for long-press seeking.
|
|
15
|
-
*/
|
|
16
11
|
interface LongPressConfig {
|
|
17
|
-
|
|
18
|
-
TIMER_INTERVAL_MS: number; // ms
|
|
19
|
-
SKIP_INCREMENT_STEP: number; // seconds
|
|
20
|
-
MAX_SKIP_PER_TICK: number; // seconds
|
|
21
|
-
INITIAL_SKIP_AMOUNT: number; // e.g., 10s to start
|
|
12
|
+
TIMER_INTERVAL_MS: number;
|
|
22
13
|
}
|
|
23
14
|
|
|
24
15
|
export class LongPressSeekController implements ISeekController {
|
|
25
|
-
private pressStartTime = 0;
|
|
26
|
-
private isLongPressActive = false;
|
|
27
|
-
private currentSkipAmount = 0;
|
|
28
16
|
private subscription: Subscription | null = null;
|
|
29
|
-
|
|
17
|
+
readonly title = "LongPressSeek";
|
|
30
18
|
constructor(
|
|
31
|
-
private
|
|
19
|
+
private seekControllerDelegate: ISeekControllerDelegate,
|
|
20
|
+
private seekIncrementalStrategy: SeekIncrementalBaseStrategy,
|
|
32
21
|
private config: LongPressConfig
|
|
33
22
|
) {}
|
|
34
23
|
|
|
35
|
-
|
|
24
|
+
onStartSeek(seekType: SEEK_TYPE) {
|
|
36
25
|
this.cleanUpSubscription();
|
|
37
26
|
|
|
38
|
-
log_debug(
|
|
39
|
-
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
this.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
log_debug(
|
|
66
|
-
`LongPressSeekController: handle delayed seek type: ${seekType} - currentSkipAmount: ${this.currentSkipAmount}.`
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
this.currentSkipAmount = Math.min(
|
|
70
|
-
this.currentSkipAmount + this.config.SKIP_INCREMENT_STEP,
|
|
71
|
-
this.config.MAX_SKIP_PER_TICK
|
|
72
|
-
);
|
|
73
|
-
})
|
|
74
|
-
);
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
this.subscription = threshold$.subscribe({
|
|
79
|
-
complete: () =>
|
|
80
|
-
log_verbose(
|
|
81
|
-
"LongPressSeekController: Long press subscription complete"
|
|
82
|
-
),
|
|
83
|
-
error: (err) =>
|
|
84
|
-
log_error(
|
|
85
|
-
"LongPressSeekController: Long press subscription error",
|
|
86
|
-
err
|
|
87
|
-
),
|
|
88
|
-
});
|
|
27
|
+
log_debug(`${this.title}: start long press seek type: ${seekType}.`);
|
|
28
|
+
|
|
29
|
+
this.seekControllerDelegate.handlePlayerPause();
|
|
30
|
+
|
|
31
|
+
this.subscription = interval(this.config.TIMER_INTERVAL_MS)
|
|
32
|
+
.pipe(
|
|
33
|
+
tap(() => {
|
|
34
|
+
this.seekControllerDelegate.handleDelayedSeek(
|
|
35
|
+
this.seekIncrementalStrategy.getSkipTime()
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
log_debug(
|
|
39
|
+
`${
|
|
40
|
+
this.title
|
|
41
|
+
}: handle delayed seek type: ${seekType} - multiplier: ${this.seekIncrementalStrategy.getSkipMultiplier()}, currentSkipAmount: ${this.seekIncrementalStrategy.getSkipTime()}.`
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
this.seekIncrementalStrategy.increment();
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
.subscribe({
|
|
48
|
+
complete: () =>
|
|
49
|
+
log_verbose(`${this.title}: Long press subscription complete`),
|
|
50
|
+
error: (err) =>
|
|
51
|
+
log_error(`${this.title}: Long press subscription error`, err),
|
|
52
|
+
});
|
|
89
53
|
}
|
|
90
54
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
this.isLongPressActive &&
|
|
96
|
-
pressDuration > this.config.LONG_PRESS_THRESHOLD
|
|
97
|
-
) {
|
|
98
|
-
const offset = this.parent.delayedSeekOffset;
|
|
99
|
-
|
|
100
|
-
if (offset) {
|
|
101
|
-
log_debug(
|
|
102
|
-
`LongPressSeekController: onPressEnd for LongPressSeekController, seek offset: ${offset}`
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
this.parent.seekPlayer(offset);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.parent.resetAll();
|
|
55
|
+
onSeekEnd() {
|
|
56
|
+
this.cleanUpSubscription();
|
|
57
|
+
this.seekControllerDelegate.handleSeekComplete();
|
|
110
58
|
}
|
|
111
59
|
|
|
112
60
|
reset() {
|
|
113
|
-
this.
|
|
114
|
-
this.currentSkipAmount = 0;
|
|
61
|
+
this.seekIncrementalStrategy.reset();
|
|
115
62
|
this.cleanUpSubscription();
|
|
116
63
|
}
|
|
117
64
|
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { BehaviorSubject } from "rxjs";
|
|
2
2
|
import { TapSeekController } from "./TapSeekController";
|
|
3
3
|
import { LongPressSeekController } from "./LongPressSeekController";
|
|
4
|
-
import { playerManager } from "../../../appUtils";
|
|
5
4
|
import { SEEK_TYPE } from "../const";
|
|
6
5
|
import { createLogger } from "../../../logger";
|
|
6
|
+
import { Player } from "../../../appUtils/playerManager/player";
|
|
7
|
+
import { SeekKeyHandlerListener } from "../../../appUtils/keyInputHandler/KeyInputHandler";
|
|
8
|
+
import {
|
|
9
|
+
ISeekController,
|
|
10
|
+
ISeekControllerDelegate,
|
|
11
|
+
SeekIncrementalBaseStrategy,
|
|
12
|
+
} from "./ISeekController";
|
|
7
13
|
|
|
8
14
|
export const { log_warning, log_debug, log_info, log_error, log_verbose } =
|
|
9
15
|
createLogger({
|
|
@@ -11,142 +17,242 @@ export const { log_warning, log_debug, log_info, log_error, log_verbose } =
|
|
|
11
17
|
subsystem: "TVSeekController",
|
|
12
18
|
});
|
|
13
19
|
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
TVSeekController.instance = new TVSeekController();
|
|
19
|
-
}
|
|
20
|
+
export enum SEEK_STRATEGY {
|
|
21
|
+
TAP_SEEK = "TAP_SEEK",
|
|
22
|
+
AUTO_SEEK = "AUTO_SEEK",
|
|
23
|
+
}
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
const CONFIG_TAP_SEEK = {
|
|
26
|
+
CLICKS_BEFORE_PAUSE: 0,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const CONFIG_LONG_PRESS = {
|
|
30
|
+
TIMER_INTERVAL_MS: 200,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const LONG_PRESS_THRESHOLD = 500;
|
|
34
|
+
const SEEK_END_TIMEOUT_DURATION = 700;
|
|
35
|
+
// prettier-ignore
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
public
|
|
37
|
+
export class TVSeekController
|
|
38
|
+
implements SeekKeyHandlerListener, ISeekControllerDelegate {
|
|
39
|
+
public delayedSeekPosition: number | null = null;
|
|
40
|
+
private readonly playerController: Player;
|
|
27
41
|
private delayedSeekProgressSubject = new BehaviorSubject<number | null>(null);
|
|
42
|
+
isPlayerInitiallyPaused: null | boolean = null;
|
|
43
|
+
currentSeekType: SEEK_TYPE | null = null;
|
|
28
44
|
|
|
29
|
-
|
|
30
|
-
private tapSeekController: TapSeekController;
|
|
31
|
-
private longPressSeekController: LongPressSeekController;
|
|
45
|
+
private currentSeekController: ISeekController;
|
|
46
|
+
private readonly tapSeekController: TapSeekController;
|
|
47
|
+
private readonly longPressSeekController: LongPressSeekController;
|
|
48
|
+
private longPressThresholdTimeout: any | null = null;
|
|
49
|
+
private seekEndTimeout: any | null = null;
|
|
32
50
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
LONG_PRESS_THRESHOLD: 500,
|
|
36
|
-
TIMER_INTERVAL_MS: 300,
|
|
37
|
-
SKIP_INCREMENT_STEP: 5,
|
|
38
|
-
MAX_SKIP_PER_TICK: 300,
|
|
39
|
-
INITIAL_SKIP_AMOUNT: 10,
|
|
40
|
-
};
|
|
51
|
+
constructor(playerController: Player) {
|
|
52
|
+
this.playerController = playerController;
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
54
|
+
this.tapSeekController = new TapSeekController(
|
|
55
|
+
this,
|
|
56
|
+
new SeekIncrementalBaseStrategy(),
|
|
57
|
+
CONFIG_TAP_SEEK
|
|
58
|
+
);
|
|
44
59
|
|
|
45
60
|
this.longPressSeekController = new LongPressSeekController(
|
|
46
61
|
this,
|
|
47
|
-
|
|
62
|
+
new SeekIncrementalBaseStrategy(),
|
|
63
|
+
CONFIG_LONG_PRESS
|
|
48
64
|
);
|
|
65
|
+
|
|
66
|
+
this.currentSeekController = this.tapSeekController;
|
|
49
67
|
}
|
|
50
68
|
|
|
51
|
-
getDelayedSeekProgressObservable() {
|
|
69
|
+
getDelayedSeekProgressObservable = () => {
|
|
52
70
|
return this.delayedSeekProgressSubject;
|
|
53
|
-
}
|
|
71
|
+
};
|
|
54
72
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.tapSeekController
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
this.longPressSeekController
|
|
64
|
-
|
|
65
|
-
},
|
|
66
|
-
onRewindLongPress: () => {
|
|
67
|
-
this.longPressSeekController.onPressStart(SEEK_TYPE.REWIND);
|
|
68
|
-
this.tapSeekController.reset();
|
|
69
|
-
},
|
|
70
|
-
onForwardPressOut: () => this.longPressSeekController.onPressEnd(),
|
|
71
|
-
onRewindPressOut: () => this.longPressSeekController.onPressEnd(),
|
|
72
|
-
};
|
|
73
|
-
}
|
|
73
|
+
setStrategy = (seekStrategy: SEEK_STRATEGY) => {
|
|
74
|
+
switch (seekStrategy) {
|
|
75
|
+
case SEEK_STRATEGY.TAP_SEEK:
|
|
76
|
+
this.currentSeekController = this.tapSeekController;
|
|
77
|
+
log_debug("TVSeekController: setStrategy - TAP_SEEK");
|
|
78
|
+
|
|
79
|
+
break;
|
|
80
|
+
case SEEK_STRATEGY.AUTO_SEEK:
|
|
81
|
+
this.currentSeekController = this.longPressSeekController;
|
|
82
|
+
log_debug("TVSeekController: setStrategy - AUTO_SEEK");
|
|
74
83
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
}
|
|
87
|
+
};
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const player = this.getPlayer();
|
|
82
|
-
if (!player) return;
|
|
89
|
+
handleStartSeek = (seekType: SEEK_TYPE) => {
|
|
90
|
+
this.currentSeekType = seekType;
|
|
83
91
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
this.pausePlayer();
|
|
92
|
+
if (this.isPlayerInitiallyPaused === null) {
|
|
93
|
+
this.isPlayerInitiallyPaused = this.playerController.isPaused();
|
|
87
94
|
}
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
this.clearLongPressThresholdTimeout();
|
|
97
|
+
this.clearSeekCompleteTimeout();
|
|
98
|
+
this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
|
|
99
|
+
this.currentSeekController.onStartSeek(seekType);
|
|
100
|
+
|
|
101
|
+
this.longPressThresholdTimeout = setTimeout(() => {
|
|
102
|
+
this.setStrategy(SEEK_STRATEGY.AUTO_SEEK);
|
|
103
|
+
this.currentSeekController.onStartSeek(seekType);
|
|
104
|
+
}, LONG_PRESS_THRESHOLD);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
onForwardPress = (): boolean => {
|
|
108
|
+
this.handleStartSeek(SEEK_TYPE.FORWARD);
|
|
109
|
+
|
|
110
|
+
return true;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
onRewindPress = (): boolean => {
|
|
114
|
+
this.handleStartSeek(SEEK_TYPE.REWIND);
|
|
115
|
+
|
|
116
|
+
return true;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
onSeekEnd = () => {
|
|
120
|
+
this.clearLongPressThresholdTimeout();
|
|
121
|
+
this.currentSeekController.onSeekEnd();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
onRewindPressOut = () => {
|
|
125
|
+
this.onSeekEnd();
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
onForwardPressOut = () => {
|
|
129
|
+
this.onSeekEnd();
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
onVideoProgress = (position: number) => {
|
|
133
|
+
if (this.delayedSeekPosition !== null) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
this.delayedSeekProgressSubject.next(position);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
handleDelayedSeek = (offset: number = 0) => {
|
|
141
|
+
this.handlePlayerPause();
|
|
142
|
+
|
|
143
|
+
const currentPos =
|
|
144
|
+
this.delayedSeekPosition === null
|
|
145
|
+
? this.playerController.getPosition()
|
|
146
|
+
: this.delayedSeekPosition;
|
|
147
|
+
|
|
91
148
|
let targetPos = currentPos;
|
|
92
149
|
|
|
93
|
-
if (
|
|
94
|
-
targetPos = Math.min(
|
|
150
|
+
if (this.currentSeekType === SEEK_TYPE.FORWARD) {
|
|
151
|
+
targetPos = Math.min(
|
|
152
|
+
currentPos + offset,
|
|
153
|
+
this.playerController.getSeekableDuration()
|
|
154
|
+
);
|
|
155
|
+
} else if (this.currentSeekType === SEEK_TYPE.REWIND) {
|
|
156
|
+
targetPos = Math.max(0, currentPos - offset);
|
|
95
157
|
} else {
|
|
96
|
-
|
|
158
|
+
log_warning(
|
|
159
|
+
`TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
|
|
160
|
+
);
|
|
97
161
|
}
|
|
98
162
|
|
|
99
|
-
this.delayedSeekOffset = newOffset;
|
|
100
|
-
|
|
101
163
|
log_debug(
|
|
102
|
-
`TVSeekController: handleDelayedSeek - targetPos: ${targetPos},
|
|
164
|
+
`TVSeekController: handleDelayedSeek - targetPos: ${targetPos}, skipTime: ${offset}`
|
|
103
165
|
);
|
|
104
166
|
|
|
167
|
+
const prevValue = this.delayedSeekProgressSubject.getValue();
|
|
168
|
+
|
|
169
|
+
if (prevValue !== null) {
|
|
170
|
+
const delta = Math.abs(prevValue - targetPos);
|
|
171
|
+
|
|
172
|
+
if (delta < 1) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
this.delayedSeekPosition = targetPos;
|
|
105
178
|
this.delayedSeekProgressSubject.next(targetPos);
|
|
106
|
-
}
|
|
179
|
+
};
|
|
107
180
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
181
|
+
handleSeekTo = (newPosition: number) => {
|
|
182
|
+
this.playerController.seekTo(newPosition);
|
|
183
|
+
|
|
184
|
+
if (!this.isPlayerInitiallyPaused) {
|
|
185
|
+
this.playerController.play();
|
|
186
|
+
}
|
|
187
|
+
};
|
|
114
188
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (!player) return;
|
|
189
|
+
handleSeek = (offset: number) => {
|
|
190
|
+
this.playerController[this.currentSeekType](offset);
|
|
118
191
|
|
|
119
|
-
if (
|
|
120
|
-
|
|
192
|
+
if (!this.isPlayerInitiallyPaused) {
|
|
193
|
+
this.playerController.play();
|
|
121
194
|
}
|
|
122
|
-
}
|
|
195
|
+
};
|
|
123
196
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
197
|
+
handleSeekComplete = () => {
|
|
198
|
+
this.clearSeekCompleteTimeout();
|
|
199
|
+
|
|
200
|
+
this.seekEndTimeout = setTimeout(() => {
|
|
201
|
+
if (this.delayedSeekPosition !== null) {
|
|
202
|
+
this.handleSeekTo(this.delayedSeekPosition);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
log_debug(
|
|
206
|
+
`handleSeekComplete: Seek finished, type: ${this.currentSeekController.title}, seekPosition: ${this.delayedSeekPosition}. Reset all states and seek position.`
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
this.resetAll();
|
|
210
|
+
}, SEEK_END_TIMEOUT_DURATION);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
isSeeking = (): boolean => {
|
|
214
|
+
return this.delayedSeekPosition !== null;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
handlePlayerPause = () => {
|
|
218
|
+
if (this.playerController.isPaused()) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
this.playerController.pause();
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
clearSeekCompleteTimeout = () => {
|
|
226
|
+
if (this.seekEndTimeout === null) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
clearTimeout(this.seekEndTimeout);
|
|
231
|
+
this.seekEndTimeout = null;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
clearLongPressThresholdTimeout = () => {
|
|
235
|
+
if (this.longPressThresholdTimeout === null) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
clearTimeout(this.longPressThresholdTimeout);
|
|
240
|
+
this.longPressThresholdTimeout = null;
|
|
241
|
+
};
|
|
129
242
|
|
|
130
|
-
/**
|
|
131
|
-
* Reset *all* relevant state and strategy controllers
|
|
132
|
-
*/
|
|
133
243
|
resetAll() {
|
|
134
244
|
log_debug("TVSeekController: Reset all states");
|
|
135
245
|
this.currentSeekType = null;
|
|
136
|
-
this.delayedSeekOffset = null;
|
|
137
|
-
this.delayedSeekProgressSubject.next(null);
|
|
138
246
|
|
|
139
|
-
this.
|
|
140
|
-
this.
|
|
141
|
-
}
|
|
247
|
+
this.delayedSeekPosition = null;
|
|
248
|
+
this.isPlayerInitiallyPaused = null;
|
|
142
249
|
|
|
143
|
-
|
|
144
|
-
|
|
250
|
+
this.clearSeekCompleteTimeout();
|
|
251
|
+
this.clearLongPressThresholdTimeout();
|
|
145
252
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
253
|
+
this.tapSeekController.reset();
|
|
254
|
+
this.longPressSeekController.reset();
|
|
149
255
|
|
|
150
|
-
|
|
256
|
+
this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
|
|
151
257
|
}
|
|
152
258
|
}
|
|
@@ -1,73 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
ISeekController,
|
|
3
|
+
ISeekControllerDelegate,
|
|
4
|
+
SeekIncrementalBaseStrategy,
|
|
5
|
+
} from "./ISeekController";
|
|
6
|
+
import { SEEK_TYPE } from "../const";
|
|
7
|
+
import { log_debug } from "./TVSeekController";
|
|
8
|
+
|
|
9
|
+
interface TapPressConfig {
|
|
10
|
+
CLICKS_BEFORE_PAUSE: number;
|
|
11
|
+
}
|
|
7
12
|
|
|
8
13
|
export class TapSeekController implements ISeekController {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onPressStart(seekType: SEEK_TYPE) {
|
|
16
|
-
log_debug(`TapSeekController: start tap seek type: ${seekType}.`);
|
|
14
|
+
readonly title = "TapSeek";
|
|
15
|
+
constructor(
|
|
16
|
+
private seekControllerDelegate: ISeekControllerDelegate,
|
|
17
|
+
private seekIncrementalStrategy: SeekIncrementalBaseStrategy,
|
|
18
|
+
private config: TapPressConfig
|
|
19
|
+
) {}
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
onStartSeek = (seekType: SEEK_TYPE) => {
|
|
22
|
+
log_debug(`${this.title}: start tap seek type: ${seekType}.`);
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
this.parent.currentSeekType = seekType;
|
|
25
|
-
|
|
26
|
-
if (this.tapSequenceTimeout) {
|
|
27
|
-
clearTimeout(this.tapSequenceTimeout);
|
|
28
|
-
this.tapSequenceTimeout = null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
this.tapSequenceTimeout = setTimeout(() => {
|
|
32
|
-
if (this.parent.delayedSeekOffset !== null) {
|
|
33
|
-
this.parent.seekPlayer(this.parent.delayedSeekOffset);
|
|
34
|
-
}
|
|
24
|
+
const skipTime = this.seekIncrementalStrategy.getSkipTime();
|
|
25
|
+
const seekMultiplier = this.seekIncrementalStrategy.getSkipMultiplier();
|
|
35
26
|
|
|
27
|
+
if (seekMultiplier > this.config.CLICKS_BEFORE_PAUSE) {
|
|
36
28
|
log_debug(
|
|
37
|
-
|
|
29
|
+
`${this.title}: handle delayed seek type:${seekType} - skipTime: ${skipTime}, seekMultiplier: ${seekMultiplier}.`
|
|
38
30
|
);
|
|
39
31
|
|
|
40
|
-
this.
|
|
41
|
-
}, this.ON_PRESS_RESET_DURATION);
|
|
42
|
-
|
|
43
|
-
const clicksBeforePause = 3;
|
|
44
|
-
const skipTime = getSkipTime(this.seekMultiplier);
|
|
45
|
-
|
|
46
|
-
if (this.seekMultiplier > clicksBeforePause) {
|
|
47
|
-
log_debug(
|
|
48
|
-
`TapSeekController: handle delayed seek type:${seekType} - skipTime: ${skipTime}.`
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
this.parent.handleDelayedSeek(seekType, skipTime);
|
|
32
|
+
this.seekControllerDelegate.handleDelayedSeek(skipTime);
|
|
52
33
|
} else {
|
|
53
34
|
log_debug(
|
|
54
|
-
|
|
35
|
+
`${this.title}: handle seek type:${seekType} - skipTime: ${skipTime}.`
|
|
55
36
|
);
|
|
56
37
|
|
|
57
|
-
this.
|
|
38
|
+
this.seekControllerDelegate.handleSeek(skipTime);
|
|
58
39
|
}
|
|
59
40
|
|
|
60
|
-
this.
|
|
61
|
-
}
|
|
41
|
+
this.seekIncrementalStrategy.increment();
|
|
42
|
+
};
|
|
62
43
|
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
onSeekEnd = () => {
|
|
45
|
+
this.seekControllerDelegate.handleSeekComplete();
|
|
46
|
+
};
|
|
65
47
|
|
|
66
|
-
|
|
48
|
+
reset = () => {
|
|
49
|
+
log_debug("{this.title}: Reset states");
|
|
67
50
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.tapSequenceTimeout = null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
51
|
+
this.seekIncrementalStrategy.reset();
|
|
52
|
+
};
|
|
73
53
|
}
|
|
@@ -5,22 +5,14 @@ import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
|
5
5
|
|
|
6
6
|
import { useAutoSeek } from "../useAutoSeek";
|
|
7
7
|
|
|
8
|
-
jest.useFakeTimers();
|
|
8
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
9
9
|
|
|
10
10
|
const rewind = jest.fn();
|
|
11
11
|
const forward = jest.fn();
|
|
12
|
-
const exitDelayedSeek = jest.fn();
|
|
13
|
-
const enterDelayedSeek = jest.fn();
|
|
14
12
|
|
|
15
13
|
jest
|
|
16
14
|
.spyOn(playerManager, "getInstanceController")
|
|
17
|
-
|
|
18
|
-
.mockImplementation(() => ({
|
|
19
|
-
rewind,
|
|
20
|
-
forward,
|
|
21
|
-
exitDelayedSeek,
|
|
22
|
-
enterDelayedSeek,
|
|
23
|
-
}));
|
|
15
|
+
.mockReturnValue({ rewind, forward });
|
|
24
16
|
|
|
25
17
|
describe("useAutoSeek", () => {
|
|
26
18
|
beforeEach(() => {
|