@applicaster/zapp-react-native-utils 13.0.0-alpha.2459003363 → 13.0.0-alpha.2635505531
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 +3 -0
- package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +180 -0
- package/appUtils/playerManager/index.ts +2 -6
- package/appUtils/playerManager/player.ts +13 -5
- package/appUtils/playerManager/playerNative.ts +2 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +17 -3
- package/package.json +2 -2
- package/reactHooks/player/TVSeekControlller/ISeekController.ts +7 -0
- package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +124 -0
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +152 -0
- package/reactHooks/player/TVSeekControlller/TapSeekController.ts +73 -0
- package/reactHooks/player/__tests__/useAutoSeek.test.tsx +8 -1
- package/reactHooks/player/const.ts +1 -1
- package/reactHooks/player/useAutoSeek.tsx +29 -10
- package/reactHooks/player/useSeek.tsx +3 -52
- package/reactHooks/player/useTapSeek.tsx +34 -7
|
@@ -77,6 +77,9 @@ const web = {
|
|
|
77
77
|
Exit: { code: "Exit", keyCode: null },
|
|
78
78
|
Escape: { code: "Escape", keyCode: 27 },
|
|
79
79
|
EscapeDevice: { code: "Escape", keyCode: 27 },
|
|
80
|
+
Z: { code: "KeyZ", keyCode: 90 },
|
|
81
|
+
X: { code: "KeyX", keyCode: 88 },
|
|
82
|
+
C: { code: "KeyC", keyCode: 67 },
|
|
80
83
|
};
|
|
81
84
|
|
|
82
85
|
const android_tv = {
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Player } from "./player";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
|
|
4
|
+
export class DelayedSeekPlayerWrapper extends Player {
|
|
5
|
+
private wrappedPlayer: Player;
|
|
6
|
+
private delayedSeekPosition: number;
|
|
7
|
+
private wasPlaying: boolean;
|
|
8
|
+
|
|
9
|
+
constructor(props, player: Player) {
|
|
10
|
+
super(props);
|
|
11
|
+
this.wrappedPlayer = player;
|
|
12
|
+
this.delayedSeekPosition = null;
|
|
13
|
+
|
|
14
|
+
this.wrappedPlayer.addListener({
|
|
15
|
+
id: "Master-Wrapper-Listener",
|
|
16
|
+
listener: this,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getOverlayObservable = () => {
|
|
23
|
+
return this.wrappedPlayer.getOverlayObservable();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
getEntryObservable = (): BehaviorSubject<ZappEntry | null> => {
|
|
27
|
+
return this.wrappedPlayer.getEntryObservable();
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
getEntry = (): ZappEntry | null => this.wrappedPlayer.getEntry();
|
|
31
|
+
|
|
32
|
+
getListener = (): QuickBrickPlayer.SharedPlayerCallBacks => {
|
|
33
|
+
return this.wrappedPlayer.getListener();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
togglePlayPause = () => {
|
|
37
|
+
this.wrappedPlayer.togglePlayPause();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
selectTrack = (_track) => this.wrappedPlayer.selectTrack(_track);
|
|
41
|
+
|
|
42
|
+
// Implement all default methods by delegating them to wrapped player
|
|
43
|
+
public seekTo = (position: number) => {
|
|
44
|
+
this.wrappedPlayer.seekTo(position);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
public isPlaying = () => {
|
|
48
|
+
return this.wrappedPlayer.isPlaying();
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
public isPaused = () => {
|
|
52
|
+
return this.wrappedPlayer.isPaused();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
public play = () => {
|
|
56
|
+
this.wrappedPlayer.play();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
public pause = () => {
|
|
60
|
+
this.wrappedPlayer.pause();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
getState = () => {
|
|
64
|
+
const currentState = this.wrappedPlayer.getState();
|
|
65
|
+
|
|
66
|
+
if (this.delayedSeekPosition === null) {
|
|
67
|
+
return currentState;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...currentState,
|
|
72
|
+
contentPosition: this.delayedSeekPosition,
|
|
73
|
+
isPaused: false,
|
|
74
|
+
seekPosition: this.delayedSeekPosition,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
forward = (deltaTime: number) => {
|
|
79
|
+
if (this.delayedSeekPosition !== null) {
|
|
80
|
+
this.delayedSeekPosition += deltaTime;
|
|
81
|
+
this.playerState.seekPosition = this.delayedSeekPosition;
|
|
82
|
+
|
|
83
|
+
this.onVideoProgress({
|
|
84
|
+
currentTime: this.playerState.seekPosition,
|
|
85
|
+
duration: this.getDuration(),
|
|
86
|
+
seekableDuration: this.playerState.seekableDuration,
|
|
87
|
+
isLive: this.playerState.isLive,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// this.scheduleResumePlayback(DELAYED_SEEK_DELAY, this.delayedSeekPosition);
|
|
91
|
+
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (this.playerState.seekPosition == null) {
|
|
96
|
+
this.playerState.seekPosition = this.playerState.contentPosition;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.playerState.seekPosition += deltaTime;
|
|
100
|
+
|
|
101
|
+
this.wrappedPlayer.forward(deltaTime);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
rewind = (deltaTime: number) => {
|
|
105
|
+
if (this.delayedSeekPosition !== null) {
|
|
106
|
+
this.delayedSeekPosition -= deltaTime;
|
|
107
|
+
|
|
108
|
+
if (this.delayedSeekPosition < 0) {
|
|
109
|
+
this.delayedSeekPosition = 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.playerState.seekPosition = this.delayedSeekPosition;
|
|
113
|
+
|
|
114
|
+
this.onVideoProgress({
|
|
115
|
+
currentTime: this.playerState.seekPosition,
|
|
116
|
+
duration: this.getDuration(),
|
|
117
|
+
seekableDuration: this.playerState.seekableDuration,
|
|
118
|
+
isLive: this.playerState.isLive,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// this.scheduleResumePlayback(DELAYED_SEEK_DELAY, this.delayedSeekPosition);
|
|
122
|
+
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (this.playerState.seekPosition == null) {
|
|
127
|
+
this.playerState.seekPosition = this.playerState.contentPosition;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
this.playerState.seekPosition -= deltaTime;
|
|
131
|
+
this.wrappedPlayer.rewind(deltaTime);
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
public getConfig = () => this.wrappedPlayer.getConfig();
|
|
135
|
+
|
|
136
|
+
// TODO: replace with enum of supported orientations
|
|
137
|
+
isFullScreenSupported(): boolean {
|
|
138
|
+
return this.wrappedPlayer.isFullScreenSupported();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
public supportsNativeControls = (): boolean =>
|
|
142
|
+
this.wrappedPlayer.supportsNativeControls();
|
|
143
|
+
|
|
144
|
+
public supportNativeCast = (): boolean =>
|
|
145
|
+
this.wrappedPlayer.supportNativeCast();
|
|
146
|
+
|
|
147
|
+
public isInDelayedSeek = () => this.delayedSeekPosition !== null;
|
|
148
|
+
|
|
149
|
+
public enterDelayedSeek() {
|
|
150
|
+
if (this.delayedSeekPosition !== null) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (this.playerState.seekPosition === null) {
|
|
155
|
+
this.playerState.seekPosition = this.playerState.contentPosition;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
this.delayedSeekPosition = this.playerState.seekPosition;
|
|
159
|
+
|
|
160
|
+
if (!this.isPaused()) {
|
|
161
|
+
this.wasPlaying = true;
|
|
162
|
+
this.wrappedPlayer.pause();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
public exitDelayedSeek() {
|
|
167
|
+
if (this.delayedSeekPosition === null) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
this.wrappedPlayer.seekTo(this.delayedSeekPosition);
|
|
172
|
+
|
|
173
|
+
if (this.wasPlaying) {
|
|
174
|
+
this.wasPlaying = false;
|
|
175
|
+
this.wrappedPlayer.play();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this.delayedSeekPosition = null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -169,12 +169,8 @@ export class PlayerManager {
|
|
|
169
169
|
this.addPlayer(id, playerController);
|
|
170
170
|
|
|
171
171
|
if (playerController.playerRole === PlayerRole.Primary) {
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
if (pluginId !== playerController.playerPluginId) {
|
|
175
|
-
RNPlayerManager[pluginId].stopBackgroundPlayback?.();
|
|
176
|
-
}
|
|
177
|
-
});
|
|
172
|
+
if (playerController.playerPluginId !== "QuickBrickPlayerPlugin") {
|
|
173
|
+
RNPlayerManager?.["QuickBrickPlayerPlugin"]?.stopBackgroundPlayback?.();
|
|
178
174
|
}
|
|
179
175
|
|
|
180
176
|
playerController.addListener({
|
|
@@ -91,6 +91,8 @@ export class Player {
|
|
|
91
91
|
this.onVideoProgress = this.onVideoProgress.bind(this);
|
|
92
92
|
this.onVideoLoad = this.onVideoLoad.bind(this);
|
|
93
93
|
this.isFullScreenSupported = this.isFullScreenSupported.bind(this);
|
|
94
|
+
this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
|
|
95
|
+
|
|
94
96
|
this.entryObservable = null;
|
|
95
97
|
}
|
|
96
98
|
|
|
@@ -321,7 +323,7 @@ export class Player {
|
|
|
321
323
|
* You should use dispatchPlayerEvent at PlayerContainer or call playerManager.invokeHandler directly
|
|
322
324
|
* This allows you to use one method for everything.
|
|
323
325
|
*/
|
|
324
|
-
|
|
326
|
+
onPlayerSeekStart = (event: QuickBrickPlayer.OnSeekStartEvent) => {
|
|
325
327
|
const { isLive, seekableDuration, currentTime, duration, seekTime } = event;
|
|
326
328
|
|
|
327
329
|
this.setPlaybackState({ currentTime, duration, seekableDuration, isLive });
|
|
@@ -336,10 +338,11 @@ export class Player {
|
|
|
336
338
|
});
|
|
337
339
|
};
|
|
338
340
|
|
|
339
|
-
|
|
341
|
+
onPlayerSeekComplete(event: QuickBrickPlayer.OnSeekCompleteEvent) {
|
|
340
342
|
const { isLive, seekableDuration, currentTime, duration } = event;
|
|
341
343
|
|
|
342
344
|
this.setPlaybackState({ currentTime, duration, seekableDuration, isLive });
|
|
345
|
+
|
|
343
346
|
this.playerState.seekPosition = null;
|
|
344
347
|
|
|
345
348
|
if (!isLive) {
|
|
@@ -350,7 +353,7 @@ export class Player {
|
|
|
350
353
|
callbackName: SharedPlayerCallBacksKeys.OnPlayerSeekComplete,
|
|
351
354
|
event,
|
|
352
355
|
});
|
|
353
|
-
}
|
|
356
|
+
}
|
|
354
357
|
|
|
355
358
|
onVideoEnd = (event) => {
|
|
356
359
|
this.invokeListenersUpdate({
|
|
@@ -653,8 +656,8 @@ export class Player {
|
|
|
653
656
|
};
|
|
654
657
|
|
|
655
658
|
public getListener = (): QuickBrickPlayer.SharedPlayerCallBacks => ({
|
|
656
|
-
onPlayerSeekStart: this.
|
|
657
|
-
onPlayerSeekComplete: this.
|
|
659
|
+
onPlayerSeekStart: this.onPlayerSeekStart,
|
|
660
|
+
onPlayerSeekComplete: this.onPlayerSeekComplete,
|
|
658
661
|
onVideoEnd: this.onVideoEnd,
|
|
659
662
|
onError: this.onError,
|
|
660
663
|
onVideoError: this.onVideoError,
|
|
@@ -733,5 +736,10 @@ export class Player {
|
|
|
733
736
|
|
|
734
737
|
public supportsNativeControls = (): boolean => false;
|
|
735
738
|
public supportNativeCast = (): boolean => false;
|
|
739
|
+
|
|
740
|
+
public isInDelayedSeek = (): boolean => false;
|
|
741
|
+
public enterDelayedSeek() {}
|
|
742
|
+
|
|
743
|
+
public exitDelayedSeek() {}
|
|
736
744
|
public destroy = () => {};
|
|
737
745
|
}
|
|
@@ -222,9 +222,10 @@ export class PlayerNative extends Player {
|
|
|
222
222
|
|
|
223
223
|
onVideoLoad = (event) => {
|
|
224
224
|
if (this.startPosition) {
|
|
225
|
-
super.onVideoLoad({ ...event, ignoreContinueWatching: true });
|
|
226
225
|
this.seekTo(this.startPosition);
|
|
227
226
|
this.startPosition = null;
|
|
227
|
+
|
|
228
|
+
super.onVideoLoad({ ...event, ignoreContinueWatching: true });
|
|
228
229
|
} else {
|
|
229
230
|
super.onVideoLoad(event);
|
|
230
231
|
}
|
|
@@ -5,6 +5,8 @@ import { playerManager } from "./index";
|
|
|
5
5
|
import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
|
|
6
6
|
import { PlayerRole } from "./conts";
|
|
7
7
|
import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
|
|
8
|
+
import { isTV } from "../../reactUtils";
|
|
9
|
+
import { DelayedSeekPlayerWrapper } from "./DelayedSeekPlayerWrapper";
|
|
8
10
|
|
|
9
11
|
// TODO: Rename to ControllerType
|
|
10
12
|
export const usePlayerControllerSetup = ({
|
|
@@ -39,7 +41,7 @@ export const usePlayerControllerSetup = ({
|
|
|
39
41
|
? { supports_native_controls: true, ...config }
|
|
40
42
|
: config;
|
|
41
43
|
|
|
42
|
-
const
|
|
44
|
+
const combinedProps = {
|
|
43
45
|
player: ref,
|
|
44
46
|
listener: props as any,
|
|
45
47
|
config: newConfig,
|
|
@@ -47,9 +49,21 @@ export const usePlayerControllerSetup = ({
|
|
|
47
49
|
entry,
|
|
48
50
|
playerPluginId: pluginId,
|
|
49
51
|
playerRole: PlayerRole.Primary,
|
|
50
|
-
}
|
|
52
|
+
};
|
|
51
53
|
|
|
52
|
-
|
|
54
|
+
if (isTV()) {
|
|
55
|
+
const wrappedPlayerController = new ControllerType({
|
|
56
|
+
...combinedProps,
|
|
57
|
+
playerRole: PlayerRole.Unspecified,
|
|
58
|
+
playerId: playerId + "." + "wrapped",
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
setPlayerController(
|
|
62
|
+
new DelayedSeekPlayerWrapper(combinedProps, wrappedPlayerController)
|
|
63
|
+
);
|
|
64
|
+
} else {
|
|
65
|
+
setPlayerController(new ControllerType(combinedProps));
|
|
66
|
+
}
|
|
53
67
|
}, [playerId, entry?.id]);
|
|
54
68
|
|
|
55
69
|
React.useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.2635505531",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "13.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.2635505531",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// LongPressSeekController.ts
|
|
2
|
+
import { ISeekController } from "./ISeekController";
|
|
3
|
+
import { SEEK_TYPE } from "../const";
|
|
4
|
+
import {
|
|
5
|
+
log_debug,
|
|
6
|
+
log_error,
|
|
7
|
+
log_verbose,
|
|
8
|
+
TVSeekController,
|
|
9
|
+
} from "./TVSeekController";
|
|
10
|
+
import { timer, interval, Subscription } from "rxjs";
|
|
11
|
+
import { switchMap, tap } from "rxjs/operators";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Example interface for the configuration needed for long-press seeking.
|
|
15
|
+
*/
|
|
16
|
+
interface LongPressConfig {
|
|
17
|
+
LONG_PRESS_THRESHOLD: number; // ms
|
|
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
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class LongPressSeekController implements ISeekController {
|
|
25
|
+
private pressStartTime = 0;
|
|
26
|
+
private isLongPressActive = false;
|
|
27
|
+
private currentSkipAmount = 0;
|
|
28
|
+
private subscription: Subscription | null = null;
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
private parent: TVSeekController,
|
|
32
|
+
private config: LongPressConfig
|
|
33
|
+
) {}
|
|
34
|
+
|
|
35
|
+
onPressStart(seekType: SEEK_TYPE) {
|
|
36
|
+
this.cleanUpSubscription();
|
|
37
|
+
|
|
38
|
+
log_debug(
|
|
39
|
+
`LongPressSeekController: start long press seek type:${seekType}.`
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
this.parent.currentSeekType = seekType;
|
|
43
|
+
this.parent.pausePlayer();
|
|
44
|
+
|
|
45
|
+
this.pressStartTime = Date.now();
|
|
46
|
+
this.isLongPressActive = true;
|
|
47
|
+
this.currentSkipAmount = this.config.INITIAL_SKIP_AMOUNT;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* We wait LONG_PRESS_THRESHOLD ms to confirm it's a long press.
|
|
51
|
+
* If it still active, we switch to an interval that emits every TIMER_INTERVAL_MS.
|
|
52
|
+
*/
|
|
53
|
+
const threshold$ = timer(this.config.LONG_PRESS_THRESHOLD).pipe(
|
|
54
|
+
tap(() =>
|
|
55
|
+
log_verbose("LongPressSeekController: Crossed long-press threshold")
|
|
56
|
+
),
|
|
57
|
+
switchMap(() => {
|
|
58
|
+
return interval(this.config.TIMER_INTERVAL_MS).pipe(
|
|
59
|
+
tap(() => {
|
|
60
|
+
this.parent.handleDelayedSeek(
|
|
61
|
+
this.parent.currentSeekType,
|
|
62
|
+
this.currentSkipAmount
|
|
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
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
onPressEnd() {
|
|
92
|
+
const pressDuration = Date.now() - this.pressStartTime;
|
|
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();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
reset() {
|
|
113
|
+
this.isLongPressActive = false;
|
|
114
|
+
this.currentSkipAmount = 0;
|
|
115
|
+
this.cleanUpSubscription();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private cleanUpSubscription() {
|
|
119
|
+
if (this.subscription) {
|
|
120
|
+
this.subscription.unsubscribe();
|
|
121
|
+
this.subscription = null;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { TapSeekController } from "./TapSeekController";
|
|
3
|
+
import { LongPressSeekController } from "./LongPressSeekController";
|
|
4
|
+
import { playerManager } from "../../../appUtils";
|
|
5
|
+
import { SEEK_TYPE } from "../const";
|
|
6
|
+
import { createLogger } from "../../../logger";
|
|
7
|
+
|
|
8
|
+
export const { log_warning, log_debug, log_info, log_error, log_verbose } =
|
|
9
|
+
createLogger({
|
|
10
|
+
category: "General",
|
|
11
|
+
subsystem: "TVSeekController",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
export class TVSeekController {
|
|
15
|
+
private static instance: TVSeekController;
|
|
16
|
+
public static getInstance() {
|
|
17
|
+
if (!TVSeekController.instance) {
|
|
18
|
+
TVSeekController.instance = new TVSeekController();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return TVSeekController.instance;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// -- SHARED STATE ACROSS STRATEGIES --
|
|
25
|
+
public currentSeekType: SEEK_TYPE | null = null;
|
|
26
|
+
public delayedSeekOffset: number | null = null;
|
|
27
|
+
private delayedSeekProgressSubject = new BehaviorSubject<number | null>(null);
|
|
28
|
+
|
|
29
|
+
// -- STRATEGY INSTANCES --
|
|
30
|
+
private tapSeekController: TapSeekController;
|
|
31
|
+
private longPressSeekController: LongPressSeekController;
|
|
32
|
+
|
|
33
|
+
// Example config for long press
|
|
34
|
+
private config = {
|
|
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
|
+
};
|
|
41
|
+
|
|
42
|
+
private constructor() {
|
|
43
|
+
this.tapSeekController = new TapSeekController(this);
|
|
44
|
+
|
|
45
|
+
this.longPressSeekController = new LongPressSeekController(
|
|
46
|
+
this,
|
|
47
|
+
this.config
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
getDelayedSeekProgressObservable() {
|
|
52
|
+
return this.delayedSeekProgressSubject;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
getSeekMethods() {
|
|
56
|
+
return {
|
|
57
|
+
onForwardPress: () =>
|
|
58
|
+
this.tapSeekController.onPressStart(SEEK_TYPE.FORWARD),
|
|
59
|
+
onRewindPress: () =>
|
|
60
|
+
this.tapSeekController.onPressStart(SEEK_TYPE.REWIND),
|
|
61
|
+
|
|
62
|
+
onForwardLongPress: () => {
|
|
63
|
+
this.longPressSeekController.onPressStart(SEEK_TYPE.FORWARD);
|
|
64
|
+
this.tapSeekController.reset();
|
|
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
|
+
}
|
|
74
|
+
|
|
75
|
+
// ---------------------------
|
|
76
|
+
// SHARED METHODS
|
|
77
|
+
// ---------------------------
|
|
78
|
+
|
|
79
|
+
/** Called by either strategy to accumulate offset while paused. */
|
|
80
|
+
handleDelayedSeek(eventType: SEEK_TYPE, skipTime: number) {
|
|
81
|
+
const player = this.getPlayer();
|
|
82
|
+
if (!player) return;
|
|
83
|
+
|
|
84
|
+
// If not previously delayed, we pause the first time
|
|
85
|
+
if (this.delayedSeekOffset === null) {
|
|
86
|
+
this.pausePlayer();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const newOffset = (this.delayedSeekOffset || 0) + skipTime;
|
|
90
|
+
const currentPos = player.getPosition();
|
|
91
|
+
let targetPos = currentPos;
|
|
92
|
+
|
|
93
|
+
if (eventType === SEEK_TYPE.FORWARD) {
|
|
94
|
+
targetPos = Math.min(currentPos + newOffset, player.getDuration());
|
|
95
|
+
} else {
|
|
96
|
+
targetPos = Math.max(0, currentPos - newOffset);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
this.delayedSeekOffset = newOffset;
|
|
100
|
+
|
|
101
|
+
log_debug(
|
|
102
|
+
`TVSeekController: handleDelayedSeek - targetPos: ${targetPos}, offset: ${newOffset}, skipTime: ${skipTime}`
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
this.delayedSeekProgressSubject.next(targetPos);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
seekPlayer(offset: number) {
|
|
109
|
+
const player = this.getPlayer();
|
|
110
|
+
if (!player || !this.currentSeekType) return;
|
|
111
|
+
player[this.currentSeekType](offset);
|
|
112
|
+
this.playerPlay();
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
playerPlay() {
|
|
116
|
+
const player = this.getPlayer();
|
|
117
|
+
if (!player) return;
|
|
118
|
+
|
|
119
|
+
if (player.isPaused()) {
|
|
120
|
+
player.play();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
pausePlayer() {
|
|
125
|
+
const player = this.getPlayer();
|
|
126
|
+
if (!player) return;
|
|
127
|
+
player.pause();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Reset *all* relevant state and strategy controllers
|
|
132
|
+
*/
|
|
133
|
+
resetAll() {
|
|
134
|
+
log_debug("TVSeekController: Reset all states");
|
|
135
|
+
this.currentSeekType = null;
|
|
136
|
+
this.delayedSeekOffset = null;
|
|
137
|
+
this.delayedSeekProgressSubject.next(null);
|
|
138
|
+
|
|
139
|
+
this.tapSeekController.reset();
|
|
140
|
+
this.longPressSeekController.reset();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private getPlayer() {
|
|
144
|
+
const player = playerManager.getInstanceController();
|
|
145
|
+
|
|
146
|
+
if (!player) {
|
|
147
|
+
log_warning("TVSeekController: No valid player controller found");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return player;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { ISeekController } from "./ISeekController";
|
|
2
|
+
import { SEEK_TYPE, MAX_SEEK_TIME, SKIP_TIME_BASE } from "../const";
|
|
3
|
+
import { log_debug, TVSeekController } from "./TVSeekController";
|
|
4
|
+
|
|
5
|
+
const getSkipTime = (multiplier: number) =>
|
|
6
|
+
Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
|
|
7
|
+
|
|
8
|
+
export class TapSeekController implements ISeekController {
|
|
9
|
+
private tapSequenceTimeout: NodeJS.Timeout | null = null;
|
|
10
|
+
private seekMultiplier = 1;
|
|
11
|
+
private readonly ON_PRESS_RESET_DURATION = 500; // ms
|
|
12
|
+
|
|
13
|
+
constructor(private parent: TVSeekController) {}
|
|
14
|
+
|
|
15
|
+
onPressStart(seekType: SEEK_TYPE) {
|
|
16
|
+
log_debug(`TapSeekController: start tap seek type: ${seekType}.`);
|
|
17
|
+
|
|
18
|
+
const prevSeekType = this.parent.currentSeekType;
|
|
19
|
+
|
|
20
|
+
if (prevSeekType !== seekType) {
|
|
21
|
+
this.reset();
|
|
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
|
+
}
|
|
35
|
+
|
|
36
|
+
log_debug(
|
|
37
|
+
`TapSeekController: Tap sequence timeout fired, delayedSeekOffset: ${this.parent.delayedSeekOffset}.`
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
this.parent.resetAll();
|
|
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);
|
|
52
|
+
} else {
|
|
53
|
+
log_debug(
|
|
54
|
+
`TapSeekController: handle seek type:${seekType} - skipTime: ${skipTime}.`
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
this.parent.seekPlayer(skipTime);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this.seekMultiplier++;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
reset() {
|
|
64
|
+
log_debug("TapSeekController: Reset states");
|
|
65
|
+
|
|
66
|
+
this.seekMultiplier = 1;
|
|
67
|
+
|
|
68
|
+
if (this.tapSequenceTimeout) {
|
|
69
|
+
clearTimeout(this.tapSequenceTimeout);
|
|
70
|
+
this.tapSequenceTimeout = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -9,11 +9,18 @@ jest.useFakeTimers();
|
|
|
9
9
|
|
|
10
10
|
const rewind = jest.fn();
|
|
11
11
|
const forward = jest.fn();
|
|
12
|
+
const exitDelayedSeek = jest.fn();
|
|
13
|
+
const enterDelayedSeek = jest.fn();
|
|
12
14
|
|
|
13
15
|
jest
|
|
14
16
|
.spyOn(playerManager, "getInstanceController")
|
|
15
17
|
// @ts-ignore
|
|
16
|
-
.mockImplementation(() => ({
|
|
18
|
+
.mockImplementation(() => ({
|
|
19
|
+
rewind,
|
|
20
|
+
forward,
|
|
21
|
+
exitDelayedSeek,
|
|
22
|
+
enterDelayedSeek,
|
|
23
|
+
}));
|
|
17
24
|
|
|
18
25
|
describe("useAutoSeek", () => {
|
|
19
26
|
beforeEach(() => {
|
|
@@ -13,20 +13,24 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
|
|
|
13
13
|
const [isRunning, setIsRunning] = useState<boolean>(false);
|
|
14
14
|
const [direction, setDirection] = useState<Nullable<SEEK_TYPE>>(null);
|
|
15
15
|
const [multiplier, setMultiplier] = useState(1);
|
|
16
|
+
|
|
16
17
|
const intervalTimer = React.useRef(null);
|
|
17
18
|
const prevRunning = usePrevious(isRunning);
|
|
18
19
|
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
} catch (err) {
|
|
23
|
-
intervalTimer.current = null;
|
|
20
|
+
const setIntervalTimer = (cb) => {
|
|
21
|
+
if (intervalTimer.current) {
|
|
22
|
+
return;
|
|
24
23
|
}
|
|
24
|
+
|
|
25
|
+
intervalTimer.current = setInterval(() => {
|
|
26
|
+
intervalTimer.current = null;
|
|
27
|
+
cb();
|
|
28
|
+
}, ON_HOLD_INTERVAL);
|
|
25
29
|
};
|
|
26
30
|
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
intervalTimer.current =
|
|
31
|
+
const clearIntervalTimer = () => {
|
|
32
|
+
clearInterval(intervalTimer.current);
|
|
33
|
+
intervalTimer.current = null;
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
const resetState = () => {
|
|
@@ -37,6 +41,21 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
|
|
|
37
41
|
};
|
|
38
42
|
|
|
39
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
|
+
|
|
40
59
|
const player = playerManager.getInstanceController();
|
|
41
60
|
|
|
42
61
|
if (!player) return;
|
|
@@ -45,7 +64,7 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
|
|
|
45
64
|
player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
|
|
46
65
|
resetHUDTimer();
|
|
47
66
|
}
|
|
48
|
-
}, [multiplier, direction]);
|
|
67
|
+
}, [multiplier, direction, isRunning]);
|
|
49
68
|
|
|
50
69
|
useEffect(() => {
|
|
51
70
|
if (isRunning && isRunning !== prevRunning) {
|
|
@@ -77,7 +96,7 @@ export const useAutoSeek = (resetHUDTimer = noop) => {
|
|
|
77
96
|
setDirection(eventType);
|
|
78
97
|
setIsRunning(true);
|
|
79
98
|
},
|
|
80
|
-
[isRunning]
|
|
99
|
+
[isRunning, autoSeekStop]
|
|
81
100
|
);
|
|
82
101
|
|
|
83
102
|
return React.useMemo(
|
|
@@ -1,58 +1,9 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { SEEK_TYPE } from "./const";
|
|
3
|
-
import { useTapSeek } from "./useTapSeek";
|
|
4
|
-
import { useAutoSeek } from "./useAutoSeek";
|
|
1
|
+
import React, { useMemo } from "react";
|
|
5
2
|
import { noop } from "../../functionUtils";
|
|
3
|
+
import { TVSeekController } from "./TVSeekControlller/TVSeekController";
|
|
6
4
|
|
|
7
5
|
export const useSeek = (resetHUDTimer = noop) => {
|
|
8
|
-
|
|
9
|
-
const { autoSeekStart, autoSeekStop } = useAutoSeek(resetHUDTimer);
|
|
10
|
-
|
|
11
|
-
const onForwardPress = () => {
|
|
12
|
-
handlePressEvent(SEEK_TYPE.FORWARD);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const onRewindPress = () => {
|
|
16
|
-
handlePressEvent(SEEK_TYPE.REWIND);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const onForwardPressIn = () => {
|
|
20
|
-
autoSeekStart(SEEK_TYPE.FORWARD);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const onForwardPressOut = () => {
|
|
24
|
-
autoSeekStop();
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const onRewindPressIn = () => {
|
|
28
|
-
autoSeekStart(SEEK_TYPE.REWIND);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const onRewindLongPress = () => {
|
|
32
|
-
autoSeekStart(SEEK_TYPE.REWIND);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const onForwardLongPress = () => {
|
|
36
|
-
autoSeekStart(SEEK_TYPE.FORWARD);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const onRewindPressOut = () => {
|
|
40
|
-
autoSeekStop();
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return React.useMemo(
|
|
44
|
-
() => ({
|
|
45
|
-
onForwardPress,
|
|
46
|
-
onRewindPress,
|
|
47
|
-
onForwardPressIn,
|
|
48
|
-
onForwardPressOut,
|
|
49
|
-
onRewindPressIn,
|
|
50
|
-
onRewindPressOut,
|
|
51
|
-
onRewindLongPress,
|
|
52
|
-
onForwardLongPress,
|
|
53
|
-
}),
|
|
54
|
-
[handlePressEvent, autoSeekStart]
|
|
55
|
-
);
|
|
6
|
+
return useMemo(() => TVSeekController.getInstance().getSeekMethods(), []);
|
|
56
7
|
};
|
|
57
8
|
|
|
58
9
|
export const withUseSeek = (Component) =>
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useRef } from "react";
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import {
|
|
4
4
|
MAX_SEEK_TIME,
|
|
@@ -10,13 +10,11 @@ import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
|
10
10
|
|
|
11
11
|
type SeekType = SEEK_TYPE | null;
|
|
12
12
|
|
|
13
|
-
const getSkipTime = (multiplier) =>
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return skipTime;
|
|
17
|
-
};
|
|
13
|
+
const getSkipTime = (multiplier) =>
|
|
14
|
+
R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
|
|
18
15
|
|
|
19
16
|
export const useTapSeek = () => {
|
|
17
|
+
const [resumeTimer, setResumeTimer] = useState<NodeJS.Timeout>(null);
|
|
20
18
|
const onPressMultiplier = useRef(1);
|
|
21
19
|
const lastPressTime = useRef(0);
|
|
22
20
|
const currentOnPressEventType = useRef<SeekType>(null);
|
|
@@ -46,12 +44,41 @@ export const useTapSeek = () => {
|
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
const seekTime = getSkipTime(onPressMultiplier.current);
|
|
47
|
+
|
|
49
48
|
player[eventType](seekTime);
|
|
50
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
|
+
|
|
51
78
|
lastPressTime.current = now;
|
|
52
79
|
currentOnPressEventType.current = eventType;
|
|
53
80
|
},
|
|
54
|
-
[resetMultiplier]
|
|
81
|
+
[resetMultiplier, resumeTimer]
|
|
55
82
|
);
|
|
56
83
|
|
|
57
84
|
return handlePressEvent;
|