@applicaster/zapp-react-native-utils 13.0.0-alpha.4138374149 → 13.0.0-alpha.4515349201

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.
@@ -77,6 +77,10 @@ const web = {
77
77
  Exit: { code: "Exit", keyCode: null },
78
78
  Escape: { code: "Escape", keyCode: 27 },
79
79
  EscapeDevice: { code: "Escape", keyCode: 27 },
80
+ // For Debugging
81
+ Z: { code: "KeyZ", keyCode: 90 },
82
+ X: { code: "KeyX", keyCode: 88 },
83
+ C: { code: "KeyC", keyCode: 67 },
80
84
  };
81
85
 
82
86
  const android_tv = {
@@ -0,0 +1,68 @@
1
+ export type SeekKeyHandlerListener = {
2
+ onRewindPress: () => boolean;
3
+ onForwardPress: () => boolean;
4
+ onRewindPressOut: () => void;
5
+ onForwardPressOut: () => void;
6
+ };
7
+
8
+ export class KeyInputHandler {
9
+ private static instance: KeyInputHandler;
10
+
11
+ public static getInstance() {
12
+ if (!KeyInputHandler.instance) {
13
+ KeyInputHandler.instance = new KeyInputHandler();
14
+ }
15
+
16
+ return KeyInputHandler.instance;
17
+ }
18
+
19
+ constructor() {
20
+ this.listeners = [];
21
+ }
22
+
23
+ private listeners: SeekKeyHandlerListener[] = [];
24
+
25
+ addListener = (listener: SeekKeyHandlerListener) => {
26
+ this.listeners.splice(0, 0, listener);
27
+
28
+ return () => this.removeListener(listener);
29
+ };
30
+
31
+ removeListener = (listener: SeekKeyHandlerListener) => {
32
+ this.listeners = this.listeners.filter((l) => l !== listener);
33
+ };
34
+
35
+ onRewindPress = () => {
36
+ for (const element of this.listeners) {
37
+ if (element.onRewindPress()) {
38
+ break;
39
+ }
40
+ }
41
+ };
42
+
43
+ onForwardPress = () => {
44
+ for (const element of this.listeners) {
45
+ if (element.onForwardPress()) {
46
+ break;
47
+ }
48
+ }
49
+ };
50
+
51
+ // TODO: Event should be send to listeners who handled down event
52
+ onRewindPressOut = () => {
53
+ this.listeners.forEach((listener) => listener.onRewindPressOut());
54
+ };
55
+
56
+ onForwardPressOut = () => {
57
+ this.listeners.forEach((listener) => listener.onForwardPressOut());
58
+ };
59
+
60
+ getSeekMethods = () => {
61
+ return {
62
+ onForwardPress: this.onForwardPress,
63
+ onRewindPress: this.onRewindPress,
64
+ onForwardPressOut: this.onForwardPressOut,
65
+ onRewindPressOut: this.onRewindPressOut,
66
+ };
67
+ };
68
+ }
@@ -169,8 +169,12 @@ export class PlayerManager {
169
169
  this.addPlayer(id, playerController);
170
170
 
171
171
  if (playerController.playerRole === PlayerRole.Primary) {
172
- if (playerController.playerPluginId !== "QuickBrickPlayerPlugin") {
173
- RNPlayerManager?.["QuickBrickPlayerPlugin"]?.stopBackgroundPlayback?.();
172
+ if (RNPlayerManager) {
173
+ Object.keys(RNPlayerManager).forEach((pluginId) => {
174
+ if (pluginId !== playerController.playerPluginId) {
175
+ RNPlayerManager[pluginId]?.stopBackgroundPlayback?.();
176
+ }
177
+ });
174
178
  }
175
179
 
176
180
  playerController.addListener({
@@ -5,6 +5,7 @@ import { createLogger, utilsLogger } from "../../logger";
5
5
  import { getBoolFromConfigValue } from "../../configurationUtils";
6
6
  import { PlayerRole, SharedPlayerCallBacksKeys } from "./conts";
7
7
  import { OverlaysObserver } from "./OverlayObserver/OverlaysObserver";
8
+ import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
8
9
 
9
10
  const logger = createLogger({
10
11
  category: "PlayerController",
@@ -49,6 +50,8 @@ export class Player {
49
50
  [key: string]: QuickBrickPlayer.SharedPlayerCallBacks;
50
51
  } = {};
51
52
 
53
+ public seekController?: TVSeekController | null;
54
+
52
55
  get entry(): ZappEntry | null {
53
56
  return this._entry;
54
57
  }
@@ -59,6 +62,8 @@ export class Player {
59
62
  }
60
63
 
61
64
  constructor(props) {
65
+ this.seekController = null;
66
+
62
67
  this.playerState = {
63
68
  // We want isLive null by default to be able not to show controls if we do not know type
64
69
  isLive: null,
@@ -91,6 +96,8 @@ export class Player {
91
96
  this.onVideoProgress = this.onVideoProgress.bind(this);
92
97
  this.onVideoLoad = this.onVideoLoad.bind(this);
93
98
  this.isFullScreenSupported = this.isFullScreenSupported.bind(this);
99
+ this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
100
+
94
101
  this.entryObservable = null;
95
102
  }
96
103
 
@@ -321,7 +328,7 @@ export class Player {
321
328
  * You should use dispatchPlayerEvent at PlayerContainer or call playerManager.invokeHandler directly
322
329
  * This allows you to use one method for everything.
323
330
  */
324
- onSeekStart = (event: QuickBrickPlayer.OnSeekStartEvent) => {
331
+ onPlayerSeekStart = (event: QuickBrickPlayer.OnSeekStartEvent) => {
325
332
  const { isLive, seekableDuration, currentTime, duration, seekTime } = event;
326
333
 
327
334
  this.setPlaybackState({ currentTime, duration, seekableDuration, isLive });
@@ -336,10 +343,11 @@ export class Player {
336
343
  });
337
344
  };
338
345
 
339
- onSeekComplete = (event: QuickBrickPlayer.OnSeekCompleteEvent) => {
346
+ onPlayerSeekComplete = (event: QuickBrickPlayer.OnSeekCompleteEvent) => {
340
347
  const { isLive, seekableDuration, currentTime, duration } = event;
341
348
 
342
349
  this.setPlaybackState({ currentTime, duration, seekableDuration, isLive });
350
+
343
351
  this.playerState.seekPosition = null;
344
352
 
345
353
  if (!isLive) {
@@ -620,14 +628,18 @@ export class Player {
620
628
  selectTrack = (_track) => {};
621
629
 
622
630
  protected notifyPlayHeadPositionUpdate = () => {
631
+ const currentTime = this.getPosition();
632
+
623
633
  const event = {
624
- currentTime: this.getPosition(),
634
+ currentTime,
625
635
  duration: this.getDuration(),
626
636
  item: this.getEntry(),
627
637
  seekableDuration: this.playerState.seekableDuration,
628
638
  isLive: this.isLive(),
629
639
  };
630
640
 
641
+ this.seekController?.onVideoProgress(currentTime);
642
+
631
643
  this.invokeListenersUpdate({
632
644
  callbackName: SharedPlayerCallBacksKeys.OnVideoProgress,
633
645
  event,
@@ -653,8 +665,8 @@ export class Player {
653
665
  };
654
666
 
655
667
  public getListener = (): QuickBrickPlayer.SharedPlayerCallBacks => ({
656
- onPlayerSeekStart: this.onSeekStart,
657
- onPlayerSeekComplete: this.onSeekComplete,
668
+ onPlayerSeekStart: this.onPlayerSeekStart,
669
+ onPlayerSeekComplete: this.onPlayerSeekComplete,
658
670
  onVideoEnd: this.onVideoEnd,
659
671
  onError: this.onError,
660
672
  onVideoError: this.onVideoError,
@@ -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
  }
@@ -39,7 +39,7 @@ export const usePlayerControllerSetup = ({
39
39
  ? { supports_native_controls: true, ...config }
40
40
  : config;
41
41
 
42
- const newPlayerController = new ControllerType({
42
+ const combinedProps = {
43
43
  player: ref,
44
44
  listener: props as any,
45
45
  config: newConfig,
@@ -47,9 +47,9 @@ export const usePlayerControllerSetup = ({
47
47
  entry,
48
48
  playerPluginId: pluginId,
49
49
  playerRole: PlayerRole.Primary,
50
- });
50
+ };
51
51
 
52
- setPlayerController(newPlayerController);
52
+ setPlayerController(new ControllerType(combinedProps));
53
53
  }, [playerId, entry?.id]);
54
54
 
55
55
  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.4138374149",
3
+ "version": "13.0.0-alpha.4515349201",
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.4138374149",
31
+ "@applicaster/applicaster-types": "13.0.0-alpha.4515349201",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -0,0 +1,15 @@
1
+ import { SEEK_TYPE } from "../const";
2
+
3
+ export interface ISeekControllerDelegate {
4
+ handleDelayedSeek(offset: number): void;
5
+ handleSeek(offset: number): void;
6
+ handleSeekComplete(): void;
7
+ handlePlayerPause(): void;
8
+ delayedSeekOffset: number | null;
9
+ }
10
+
11
+ export interface ISeekController {
12
+ onStartSeek(seekType: SEEK_TYPE): void;
13
+ onSeekEnd(): void;
14
+ reset(): void;
15
+ }
@@ -0,0 +1,92 @@
1
+ import { ISeekController, ISeekControllerDelegate } from "./ISeekController";
2
+ import { SEEK_TYPE } from "../const";
3
+ import { log_debug, log_error, log_verbose } from "./TVSeekController";
4
+ import { interval, Subscription } from "rxjs";
5
+ import { tap } from "rxjs/operators";
6
+
7
+ interface LongPressConfig {
8
+ TIMER_INTERVAL_MS: number; // ms
9
+ SKIP_INCREMENT_STEP: number; // seconds
10
+ MAX_SKIP_PER_TICK: number; // seconds
11
+ INITIAL_SKIP_AMOUNT: number; // e.g., 10s to start
12
+ }
13
+
14
+ export class LongPressSeekController implements ISeekController {
15
+ isLongPressActive = false;
16
+ private currentSkipAmount = 0;
17
+ private subscription: Subscription | null = null;
18
+
19
+ constructor(
20
+ private seekControllerDelegate: ISeekControllerDelegate,
21
+ private config: LongPressConfig
22
+ ) {}
23
+
24
+ onStartSeek(seekType: SEEK_TYPE) {
25
+ this.cleanUpSubscription();
26
+
27
+ log_debug(
28
+ `LongPressSeekController: start long press seek type:${seekType}.`
29
+ );
30
+
31
+ this.seekControllerDelegate.handlePlayerPause();
32
+
33
+ this.isLongPressActive = true;
34
+ this.currentSkipAmount = this.config.INITIAL_SKIP_AMOUNT;
35
+
36
+ this.subscription = interval(this.config.TIMER_INTERVAL_MS)
37
+ .pipe(
38
+ tap(() => {
39
+ this.seekControllerDelegate.handleDelayedSeek(this.currentSkipAmount);
40
+
41
+ log_debug(
42
+ `LongPressSeekController: handle delayed seek type: ${seekType} - currentSkipAmount: ${this.currentSkipAmount}.`
43
+ );
44
+
45
+ this.currentSkipAmount = Math.min(
46
+ this.currentSkipAmount + this.config.SKIP_INCREMENT_STEP,
47
+ this.config.MAX_SKIP_PER_TICK
48
+ );
49
+ })
50
+ )
51
+ .subscribe({
52
+ complete: () =>
53
+ log_verbose(
54
+ "LongPressSeekController: Long press subscription complete"
55
+ ),
56
+ error: (err) =>
57
+ log_error(
58
+ "LongPressSeekController: Long press subscription error",
59
+ err
60
+ ),
61
+ });
62
+ }
63
+
64
+ onSeekEnd() {
65
+ if (this.isLongPressActive) {
66
+ const offset = this.seekControllerDelegate.delayedSeekOffset;
67
+
68
+ if (offset !== null) {
69
+ log_debug(
70
+ `LongPressSeekController: onPressEnd for LongPressSeekController, seek offset: ${offset}`
71
+ );
72
+
73
+ this.seekControllerDelegate.handleSeek(offset);
74
+ }
75
+ }
76
+
77
+ this.seekControllerDelegate.handleSeekComplete();
78
+ }
79
+
80
+ reset() {
81
+ this.isLongPressActive = false;
82
+ this.currentSkipAmount = 0;
83
+ this.cleanUpSubscription();
84
+ }
85
+
86
+ private cleanUpSubscription() {
87
+ if (this.subscription) {
88
+ this.subscription.unsubscribe();
89
+ this.subscription = null;
90
+ }
91
+ }
92
+ }
@@ -0,0 +1,209 @@
1
+ import { BehaviorSubject } from "rxjs";
2
+ import { TapSeekController } from "./TapSeekController";
3
+ import { LongPressSeekController } from "./LongPressSeekController";
4
+ import { SEEK_TYPE } from "../const";
5
+ import { createLogger } from "../../../logger";
6
+ import { Player } from "../../../appUtils/playerManager/player";
7
+ import { SeekKeyHandlerListener } from "../../../appUtils/keyInputHandler/KeyInputHandler";
8
+ import { ISeekController, ISeekControllerDelegate } from "./ISeekController";
9
+
10
+ export const { log_warning, log_debug, log_info, log_error, log_verbose } =
11
+ createLogger({
12
+ category: "General",
13
+ subsystem: "TVSeekController",
14
+ });
15
+
16
+ export enum SEEK_STRATEGY {
17
+ TAP_SEEK = "TAP_SEEK",
18
+ AUTO_SEEK = "AUTO_SEEK",
19
+ }
20
+
21
+ const CONFIG_TAP_SEEK = {
22
+ CLICKS_BEFORE_PAUSE: 0,
23
+ };
24
+
25
+ const CONFIG_LONG_PRESS = {
26
+ TIMER_INTERVAL_MS: 300,
27
+ SKIP_INCREMENT_STEP: 5,
28
+ MAX_SKIP_PER_TICK: 300,
29
+ INITIAL_SKIP_AMOUNT: 10,
30
+ };
31
+
32
+ const LONG_PRESS_THRESHOLD = 500;
33
+
34
+ export class TVSeekController
35
+ implements SeekKeyHandlerListener, ISeekControllerDelegate {
36
+ public delayedSeekOffset: number | null = null;
37
+ private readonly playerController: Player;
38
+ private delayedSeekProgressSubject = new BehaviorSubject<number | null>(null);
39
+ isPlayerInitiallyPaused: null | boolean = null;
40
+ currentSeekType: SEEK_TYPE | null = null;
41
+
42
+ private currentSeekController: ISeekController;
43
+ private readonly tapSeekController: TapSeekController;
44
+ private readonly longPressSeekController: LongPressSeekController;
45
+ private longPressThresholdTimeout: any | null = null;
46
+
47
+ constructor(playerController: Player) {
48
+ this.playerController = playerController;
49
+
50
+ this.tapSeekController = new TapSeekController(this, CONFIG_TAP_SEEK);
51
+
52
+ this.longPressSeekController = new LongPressSeekController(
53
+ this,
54
+ CONFIG_LONG_PRESS
55
+ );
56
+
57
+ this.currentSeekController = this.tapSeekController;
58
+ }
59
+
60
+ getDelayedSeekProgressObservable = () => {
61
+ return this.delayedSeekProgressSubject;
62
+ };
63
+
64
+ setStrategy = (seekStrategy: SEEK_STRATEGY) => {
65
+ switch (seekStrategy) {
66
+ case SEEK_STRATEGY.TAP_SEEK:
67
+ clearTimeout(this.longPressThresholdTimeout);
68
+ this.longPressThresholdTimeout = null;
69
+ this.currentSeekController = this.tapSeekController;
70
+
71
+ break;
72
+ case SEEK_STRATEGY.AUTO_SEEK:
73
+ this.currentSeekController.reset();
74
+ this.currentSeekController = this.longPressSeekController;
75
+ break;
76
+ default:
77
+ }
78
+ };
79
+
80
+ handleStartSeek = (seekType: SEEK_TYPE) => {
81
+ if (this.currentSeekType !== seekType) {
82
+ this.resetAll();
83
+ }
84
+
85
+ this.currentSeekType = seekType;
86
+
87
+ if (this.isPlayerInitiallyPaused === null) {
88
+ this.isPlayerInitiallyPaused = this.playerController.isPaused();
89
+ }
90
+
91
+ this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
92
+ this.currentSeekController.onStartSeek(seekType);
93
+
94
+ this.longPressThresholdTimeout = setTimeout(() => {
95
+ this.setStrategy(SEEK_STRATEGY.AUTO_SEEK);
96
+ this.currentSeekController.onStartSeek(seekType);
97
+ }, LONG_PRESS_THRESHOLD);
98
+ };
99
+
100
+ onForwardPress = (): boolean => {
101
+ this.handleStartSeek(SEEK_TYPE.FORWARD);
102
+
103
+ return true;
104
+ };
105
+
106
+ onRewindPress = (): boolean => {
107
+ this.handleStartSeek(SEEK_TYPE.REWIND);
108
+
109
+ return true;
110
+ };
111
+
112
+ onSeekEnd = () => {
113
+ this.currentSeekController.onSeekEnd();
114
+ this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
115
+ };
116
+
117
+ onRewindPressOut = () => {
118
+ this.onSeekEnd();
119
+ };
120
+
121
+ onForwardPressOut = () => {
122
+ this.onSeekEnd();
123
+ };
124
+
125
+ public onVideoProgress = (position: number) => {
126
+ if (this.delayedSeekOffset) {
127
+ return;
128
+ }
129
+
130
+ // TODO: If 1 second after seek, send
131
+
132
+ this.delayedSeekProgressSubject.next(position);
133
+ };
134
+
135
+ handleDelayedSeek = (offset: number) => {
136
+ this.handlePlayerPause();
137
+
138
+ const newOffset = (this.delayedSeekOffset || 0) + offset;
139
+ const currentPos = this.playerController.getPosition();
140
+ let targetPos = currentPos;
141
+
142
+ if (this.currentSeekType === SEEK_TYPE.FORWARD) {
143
+ targetPos = Math.min(
144
+ currentPos + newOffset,
145
+ this.playerController.getSeekableDuration()
146
+ );
147
+ } else if (this.currentSeekType === SEEK_TYPE.REWIND) {
148
+ targetPos = Math.max(0, currentPos - newOffset);
149
+ } else {
150
+ log_warning(
151
+ `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
152
+ );
153
+ }
154
+
155
+ this.delayedSeekOffset = newOffset;
156
+
157
+ log_debug(
158
+ `TVSeekController: handleDelayedSeek - targetPos: ${targetPos}, offset: ${newOffset}, skipTime: ${offset}`
159
+ );
160
+
161
+ const prevValue = this.delayedSeekProgressSubject.getValue();
162
+
163
+ if (prevValue !== null) {
164
+ const delta = Math.abs(prevValue - targetPos);
165
+
166
+ if (delta < 1) {
167
+ return;
168
+ }
169
+ }
170
+
171
+ this.delayedSeekProgressSubject.next(targetPos);
172
+ };
173
+
174
+ handleSeek = (offset: number) => {
175
+ this.playerController[this.currentSeekType](offset);
176
+
177
+ if (!this.isPlayerInitiallyPaused) {
178
+ this.playerController.play();
179
+ }
180
+ };
181
+
182
+ handleSeekComplete = () => {
183
+ this.resetAll();
184
+ };
185
+
186
+ isAutoSeeking = (): boolean => {
187
+ return this.longPressSeekController.isLongPressActive;
188
+ };
189
+
190
+ handlePlayerPause = () => {
191
+ if (this.playerController.isPaused()) {
192
+ return;
193
+ }
194
+
195
+ this.playerController.pause();
196
+ };
197
+
198
+ resetAll() {
199
+ log_debug("TVSeekController: Reset all states");
200
+ this.currentSeekType = null;
201
+ this.delayedSeekOffset = null;
202
+ this.isPlayerInitiallyPaused = null;
203
+
204
+ this.tapSeekController.reset();
205
+ this.longPressSeekController.reset();
206
+
207
+ this.setStrategy(SEEK_STRATEGY.TAP_SEEK);
208
+ }
209
+ }
@@ -0,0 +1,75 @@
1
+ import { ISeekController, ISeekControllerDelegate } from "./ISeekController";
2
+ import { SEEK_TYPE, MAX_SEEK_TIME, SKIP_TIME_BASE } from "../const";
3
+ import { log_debug } from "./TVSeekController";
4
+
5
+ interface TapPressConfig {
6
+ CLICKS_BEFORE_PAUSE: number;
7
+ }
8
+
9
+ const getSkipTime = (multiplier: number) =>
10
+ Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
11
+
12
+ export class TapSeekController implements ISeekController {
13
+ private tapSequenceTimeout: any | null = null;
14
+ private seekMultiplier = 1;
15
+ private readonly ON_PRESS_RESET_DURATION = 500; // ms
16
+
17
+ constructor(
18
+ private seekControllerDelegate: ISeekControllerDelegate,
19
+ private config: TapPressConfig
20
+ ) {}
21
+
22
+ onStartSeek = (seekType: SEEK_TYPE) => {
23
+ log_debug(`TapSeekController: start tap seek type: ${seekType}.`);
24
+
25
+ if (this.tapSequenceTimeout) {
26
+ clearTimeout(this.tapSequenceTimeout);
27
+ this.tapSequenceTimeout = null;
28
+ }
29
+
30
+ const skipTime = getSkipTime(this.seekMultiplier);
31
+
32
+ if (this.seekMultiplier > this.config.CLICKS_BEFORE_PAUSE) {
33
+ log_debug(
34
+ `TapSeekController: handle delayed seek type:${seekType} - skipTime: ${skipTime}.`
35
+ );
36
+
37
+ this.seekControllerDelegate.handleDelayedSeek(skipTime);
38
+ } else {
39
+ log_debug(
40
+ `TapSeekController: handle seek type:${seekType} - skipTime: ${skipTime}.`
41
+ );
42
+
43
+ this.seekControllerDelegate.handleSeek(skipTime);
44
+ }
45
+
46
+ this.seekMultiplier++;
47
+ };
48
+
49
+ onSeekEnd = () => {
50
+ this.tapSequenceTimeout = setTimeout(() => {
51
+ if (this.seekControllerDelegate.delayedSeekOffset !== null) {
52
+ this.seekControllerDelegate.handleSeek(
53
+ this.seekControllerDelegate.delayedSeekOffset
54
+ );
55
+ }
56
+
57
+ log_debug(
58
+ `TapSeekController: Tap sequence timeout fired, delayedSeekOffset: ${this.seekControllerDelegate.delayedSeekOffset}.`
59
+ );
60
+
61
+ this.seekControllerDelegate.handleSeekComplete();
62
+ }, this.ON_PRESS_RESET_DURATION);
63
+ };
64
+
65
+ reset = () => {
66
+ log_debug("TapSeekController: Reset states");
67
+
68
+ this.seekMultiplier = 1;
69
+
70
+ if (this.tapSequenceTimeout) {
71
+ clearTimeout(this.tapSequenceTimeout);
72
+ this.tapSequenceTimeout = null;
73
+ }
74
+ };
75
+ }
@@ -1,10 +1,6 @@
1
1
  export const SKIP_TIME_BASE = 10;
2
2
 
3
- export const ON_PRESS_RESET_DURATION = 2000;
4
-
5
- export const ON_HOLD_INTERVAL = 500;
6
-
7
- export const MAX_SEEK_TIME = 600;
3
+ export const MAX_SEEK_TIME = 60;
8
4
 
9
5
  export enum SEEK_TYPE {
10
6
  FORWARD = "forward",
@@ -1,7 +1 @@
1
1
  export { useLanguageData } from "./useLanguageData";
2
-
3
- export { useAutoSeek } from "./useAutoSeek";
4
-
5
- export { useTapSeek } from "./useTapSeek";
6
-
7
- export { useSeek, withUseSeek } from "./useSeek";
@@ -1,116 +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
-
13
- jest
14
- .spyOn(playerManager, "getInstanceController")
15
- // @ts-ignore
16
- .mockImplementation(() => ({ rewind, forward }));
17
-
18
- describe("useAutoSeek", () => {
19
- beforeEach(() => {
20
- rewind.mockReset();
21
- forward.mockReset();
22
- });
23
-
24
- describe("autoSeekStart", () => {
25
- it("should call forward method on playerInstance", () => {
26
- const { result } = renderHook(() => useAutoSeek());
27
-
28
- act(() => {
29
- result.current.autoSeekStart(SEEK_TYPE.FORWARD);
30
- });
31
-
32
- expect(forward).toBeCalled();
33
- result.current.autoSeekStop();
34
- });
35
-
36
- it("should call rewind method on playerManager", () => {
37
- const { result } = renderHook(() => useAutoSeek());
38
-
39
- act(() => {
40
- result.current.autoSeekStart(SEEK_TYPE.REWIND);
41
- });
42
-
43
- expect(rewind).toBeCalled();
44
- result.current.autoSeekStop();
45
- });
46
-
47
- it("should call rewind with default skip time", () => {
48
- const { result } = renderHook(() => useAutoSeek());
49
-
50
- act(() => {
51
- result.current.autoSeekStart(SEEK_TYPE.REWIND);
52
- });
53
-
54
- expect(rewind).toBeCalledWith(SKIP_TIME_BASE);
55
- result.current.autoSeekStop();
56
- });
57
-
58
- it("should call forward with default skip time", () => {
59
- const { result } = renderHook(() => useAutoSeek());
60
-
61
- act(() => {
62
- result.current.autoSeekStart(SEEK_TYPE.FORWARD);
63
- });
64
-
65
- expect(forward).toBeCalledWith(SKIP_TIME_BASE);
66
- result.current.autoSeekStop();
67
- });
68
-
69
- it("should call rewind in intervals set in configuration", () => {
70
- const { result } = renderHook(() => useAutoSeek());
71
-
72
- act(() => {
73
- result.current.autoSeekStart(SEEK_TYPE.REWIND);
74
- });
75
-
76
- expect(rewind).toBeCalled();
77
- jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
78
- expect(rewind).toBeCalledTimes(4);
79
- result.current.autoSeekStop();
80
- });
81
-
82
- it("should call forward in intervals set in configuration", () => {
83
- const { result } = renderHook(() => useAutoSeek());
84
-
85
- act(() => {
86
- result.current.autoSeekStart(SEEK_TYPE.FORWARD);
87
- });
88
-
89
- expect(forward).toBeCalled();
90
- jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
91
- expect(forward).toBeCalledTimes(4);
92
- result.current.autoSeekStop();
93
- });
94
- });
95
-
96
- describe("autoSeekStop", () => {
97
- it("should stop calling playerManager method after autoSeekStop is called", () => {
98
- const { result } = renderHook(() => useAutoSeek());
99
-
100
- act(() => {
101
- result.current.autoSeekStart(SEEK_TYPE.FORWARD);
102
- });
103
-
104
- expect(forward).toBeCalled();
105
- jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
106
- expect(forward).toBeCalledTimes(4);
107
-
108
- act(() => {
109
- result.current.autoSeekStop();
110
- });
111
-
112
- jest.advanceTimersByTime(ON_HOLD_INTERVAL * 3);
113
- expect(forward).toBeCalledTimes(4);
114
- });
115
- });
116
- });
@@ -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,87 +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
- const intervalTimer = React.useRef(null);
17
- const prevRunning = usePrevious(isRunning);
18
-
19
- const clearIntervalTimer = () => {
20
- try {
21
- clearInterval(intervalTimer.current);
22
- } catch (err) {
23
- intervalTimer.current = null;
24
- }
25
- };
26
-
27
- const setIntervalTimer = (cb) => {
28
- clearIntervalTimer();
29
- intervalTimer.current = setInterval(cb, ON_HOLD_INTERVAL);
30
- };
31
-
32
- const resetState = () => {
33
- setIsRunning(false);
34
- setDirection(null);
35
- setMultiplier(1);
36
- clearIntervalTimer();
37
- };
38
-
39
- useEffect(() => {
40
- const player = playerManager.getInstanceController();
41
-
42
- if (!player) return;
43
-
44
- if (direction) {
45
- player[direction](Math.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier));
46
- resetHUDTimer();
47
- }
48
- }, [multiplier, direction]);
49
-
50
- useEffect(() => {
51
- if (isRunning && isRunning !== prevRunning) {
52
- setIntervalTimer(() => {
53
- setMultiplier((prev) => {
54
- return prev + 1;
55
- });
56
- });
57
- } else if (!isRunning && isRunning !== prevRunning) {
58
- resetState();
59
- }
60
-
61
- return () => {
62
- clearIntervalTimer();
63
- };
64
- }, [isRunning, direction]);
65
-
66
- const autoSeekStop = React.useCallback(() => {
67
- resetState();
68
- }, []);
69
-
70
- const autoSeekStart = React.useCallback(
71
- (eventType: SEEK_TYPE) => {
72
- // Check if there is another session running
73
- if (isRunning) {
74
- autoSeekStop();
75
- }
76
-
77
- setDirection(eventType);
78
- setIsRunning(true);
79
- },
80
- [isRunning]
81
- );
82
-
83
- return React.useMemo(
84
- () => ({ autoSeekStart, autoSeekStop }),
85
- [autoSeekStart, autoSeekStop]
86
- );
87
- };
@@ -1,66 +0,0 @@
1
- import React from "react";
2
- import { SEEK_TYPE } from "./const";
3
- import { useTapSeek } from "./useTapSeek";
4
- import { useAutoSeek } from "./useAutoSeek";
5
- import { noop } from "../../functionUtils";
6
-
7
- export const useSeek = (resetHUDTimer = noop) => {
8
- const handlePressEvent = useTapSeek();
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
- );
56
- };
57
-
58
- export const withUseSeek = (Component) =>
59
- Object.assign(
60
- (props) => {
61
- const seekMethods = useSeek(props?.resetHUDTimer);
62
-
63
- return <Component {...props} seekMethods={seekMethods} />;
64
- },
65
- { displayName: "WithUseSeek" }
66
- );
@@ -1,58 +0,0 @@
1
- import { useCallback, useRef } 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
- const skipTime = R.min(MAX_SEEK_TIME, SKIP_TIME_BASE * multiplier);
15
-
16
- return skipTime;
17
- };
18
-
19
- export const useTapSeek = () => {
20
- const onPressMultiplier = useRef(1);
21
- const lastPressTime = useRef(0);
22
- const currentOnPressEventType = useRef<SeekType>(null);
23
-
24
- const resetMultiplier = useCallback(() => {
25
- onPressMultiplier.current = 1;
26
- }, []);
27
-
28
- const handlePressEvent = useCallback(
29
- (eventType) => {
30
- const player = playerManager.getInstanceController();
31
- if (!player) return;
32
-
33
- const now = Date.now();
34
- const timeSinceLastPress = now - lastPressTime.current;
35
- const isSameEventType = eventType === currentOnPressEventType.current;
36
-
37
- const isWithinResetDuration =
38
- timeSinceLastPress <= ON_PRESS_RESET_DURATION;
39
-
40
- const shouldIncreaseMultiplier = isSameEventType && isWithinResetDuration;
41
-
42
- if (shouldIncreaseMultiplier) {
43
- onPressMultiplier.current += 1;
44
- } else {
45
- resetMultiplier();
46
- }
47
-
48
- const seekTime = getSkipTime(onPressMultiplier.current);
49
- player[eventType](seekTime);
50
-
51
- lastPressTime.current = now;
52
- currentOnPressEventType.current = eventType;
53
- },
54
- [resetMultiplier]
55
- );
56
-
57
- return handlePressEvent;
58
- };