@applicaster/quick-brick-player 13.0.0-alpha.8490438700 → 13.0.0-alpha.8532113155

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-player",
3
- "version": "13.0.0-alpha.8490438700",
3
+ "version": "13.0.0-alpha.8532113155",
4
4
  "description": "Quick Brick Player",
5
5
  "main": "./src/index.ts",
6
6
  "types": "index.d.ts",
@@ -37,10 +37,10 @@
37
37
  "homepage": "https://github.com/applicaster/quickbrick#readme",
38
38
  "dependencies": {
39
39
  "@applicaster/quick-brick-mobile-transport-controls": "13.0.0-rc.28",
40
- "@applicaster/quick-brick-tv-transport-controls": "13.0.0-rc.26",
41
- "@applicaster/zapp-react-native-tvos-app": "13.0.0-alpha.8490438700",
42
- "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.8490438700",
43
- "@applicaster/zapp-react-native-utils": "13.0.0-alpha.8490438700",
40
+ "@applicaster/quick-brick-tv-transport-controls": "13.0.0-rc.31",
41
+ "@applicaster/zapp-react-native-tvos-app": "13.0.0-alpha.8532113155",
42
+ "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.8532113155",
43
+ "@applicaster/zapp-react-native-utils": "13.0.0-alpha.8532113155",
44
44
  "keymirror": "^0.1.1",
45
45
  "query-string": "7.1.3",
46
46
  "react-native-web-linear-gradient": "1.1.2",
@@ -328,8 +328,12 @@ export const AudioPlayerWrapper: React.FC<Props> = (props: Props) => {
328
328
  onSleepSelect,
329
329
  ]);
330
330
 
331
+ // This method does not actually cancel the sleep timer
332
+ // (and should not to avoid race condition),
333
+ // it just performs the cleanup when timer expires
334
+ // TODO: rename it in code above
331
335
  const cancelSleepTimer = React.useCallback(() => {
332
- sleepTimerManager?.cancelSleepTimer();
336
+ sleepTimerManager?.onTimerExpired();
333
337
  }, [sleepTimerManager]);
334
338
 
335
339
  const onCloseVideoModal = React.useCallback(() => {
@@ -40,94 +40,77 @@ export class SleepTimerController {
40
40
  return this.sleepTimerStateSubject.asObservable();
41
41
  }
42
42
 
43
- async cancelSleepTimer() {
44
- this.player.cancelSleepTimer?.();
43
+ private async scheduleSleep(sleepDate): Promise<boolean> {
44
+ log_debug(`Setting sleep interval to ${sleepDate}`);
45
45
 
46
- await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
47
-
48
- this.sleepTimerStateSubject.next(new SleepTimerState(SLEEP_TIMER_OFF, 0));
49
- }
50
-
51
- private async startSleepTimer(futureSleepDate: number) {
52
46
  try {
53
- log_debug(`Starting sleep timer at ${futureSleepDate}`);
54
47
  this.player.cancelSleepTimer?.();
55
- this.player.startSleepTimer?.(futureSleepDate);
48
+ this.player.startSleepTimer?.(sleepDate);
56
49
 
57
- return futureSleepDate;
50
+ return true;
58
51
  } catch (e) {
59
52
  log_error("Failed to start sleep timer", { error: e.message });
60
53
 
61
- return 0;
54
+ return false;
62
55
  }
63
56
  }
64
57
 
65
- private async handleSleep(timerValue: number, currentFutureSleepDate = null) {
66
- log_debug("Handling sleep interval", {
67
- timerValue,
68
- currentFutureSleepDate,
69
- });
70
-
71
- if (timerValue === 0) {
72
- await this.cancelSleepTimer();
58
+ async setSleepTimer(item: SleepTimer) {
59
+ // User has selected Off state
60
+ if (item.value === 0) {
61
+ log_debug("Cancelling sleep timer");
62
+ this.player.cancelSleepTimer?.();
73
63
 
74
- return timerValue;
64
+ return this.onTimerExpired();
75
65
  }
76
66
 
77
- // starting a new timer
78
- if (currentFutureSleepDate == null) {
79
- log_debug(`Starting sleep timer in ${timerValue} minutes`);
80
- const futureSleepDate = Date.now() + timerValue * 60000;
67
+ log_debug(`Starting sleep timer in ${item.value} minutes`);
81
68
 
82
- return this.startSleepTimer(futureSleepDate);
83
- }
69
+ const futureSleepDate = Date.now() + item.value * 60000;
84
70
 
85
- // restoring previous timer (leftover time interval)
86
- if (hasDatePassed(currentFutureSleepDate)) {
87
- log_debug("Sleep date has already passed");
88
- await this.cancelSleepTimer();
71
+ if (await this.scheduleSleep(futureSleepDate)) {
72
+ await localStorage.setItem(
73
+ SLEEP_PREFERENCE_KEY,
74
+ { ...item, futureSleepDate },
75
+ NAMESPACE
76
+ );
89
77
 
90
- return 0;
78
+ this.sleepTimerStateSubject.next(
79
+ new SleepTimerState(item, futureSleepDate)
80
+ );
91
81
  }
82
+ }
92
83
 
93
- log_debug(`Starting sleep timer at ${timerValue}`);
84
+ async onTimerExpired() {
85
+ await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
94
86
 
95
- return this.startSleepTimer(currentFutureSleepDate);
87
+ this.sleepTimerStateSubject.next(new SleepTimerState(SLEEP_TIMER_OFF, 0));
96
88
  }
97
89
 
98
90
  async loadSleep() {
99
91
  const sleep = await localStorage.getItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
100
92
 
101
- if (sleep) {
102
- const { futureSleepDate, ...rest } = sleep;
93
+ if (!sleep) return;
103
94
 
104
- const sleepTimerDate = await this.handleSleep(
105
- sleep.value,
106
- futureSleepDate
107
- );
95
+ const { futureSleepDate, ...rest } = sleep;
108
96
 
109
- this.sleepTimerStateSubject.next(
110
- new SleepTimerState(rest as SleepTimer, sleepTimerDate)
111
- );
97
+ if (!futureSleepDate || hasDatePassed(futureSleepDate)) {
98
+ log_debug("Sleep date has already passed");
99
+ await localStorage.removeItem(SLEEP_PREFERENCE_KEY, NAMESPACE);
112
100
 
113
- log_debug(`Sleep state restored, will go to sleep at ${futureSleepDate}`);
101
+ return;
114
102
  }
115
- }
116
-
117
- async setSleepTimer(item: SleepTimer) {
118
- const futureSleepDate = await this.handleSleep(item.value);
119
103
 
120
- await localStorage.setItem(
121
- SLEEP_PREFERENCE_KEY,
122
- { ...item, futureSleepDate },
123
- NAMESPACE
124
- );
104
+ if (await this.scheduleSleep(futureSleepDate)) {
105
+ log_debug(`Sleep state restored, will go to sleep at ${futureSleepDate}`);
125
106
 
126
- this.sleepTimerStateSubject.next(
127
- new SleepTimerState(item, futureSleepDate)
128
- );
107
+ this.sleepTimerStateSubject.next(
108
+ new SleepTimerState(rest as SleepTimer, futureSleepDate)
109
+ );
110
+ }
129
111
  }
130
112
 
113
+ // Will be called if user closed the player explicitly.
131
114
  // TODO: check if it will be called on Android when we need.
132
115
  // Probably we will have to handle it on native instead.
133
116
  public static async onPlayerDestroy() {
@@ -21,6 +21,7 @@ export const DEFAULT_SPEED: PlaybackSpeed = {
21
21
  value: 1.0,
22
22
  };
23
23
 
24
+ // todo: should not be applied to live streams
24
25
  export class SpeedController {
25
26
  private playbackSpeedSubject = new BehaviorSubject<PlaybackSpeed>(
26
27
  DEFAULT_SPEED