-
Notifications
You must be signed in to change notification settings - Fork 28
/
playlistselectors.ts
71 lines (61 loc) · 2.46 KB
/
playlistselectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { createSelector } from 'reselect';
import { HMSPlaylistSelector, HMSPlaylistType, HMSStore } from '../schema';
/**
* @internal
*/
const selectPlaylistMap =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].list;
const selectPlaylistSelection =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].selection;
const selectPlaylistProgress =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].progress;
const selectPlaylistCurrentTime =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].currentTime;
const selectPlaylistPlaybackRate =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].playbackRate;
const selectPlaylistVolume =
(type: HMSPlaylistType = HMSPlaylistType.audio) =>
(store: HMSStore) =>
store.playlist[type].volume;
/**
* Select an array of playlist items.
*/
const selectPlaylist = (type: HMSPlaylistType = HMSPlaylistType.audio) =>
createSelector(selectPlaylistMap(type), storePlaylist => {
return Object.values(storePlaylist);
});
const selectPlaylistSelectedItem = (type: HMSPlaylistType = HMSPlaylistType.audio) =>
createSelector(selectPlaylistMap(type), selectPlaylistSelection(type), (storePlaylist, currentSelection) => {
if (!currentSelection.id) {
return;
}
return storePlaylist[currentSelection.id];
});
export const selectAudioPlaylist: HMSPlaylistSelector = {
selection: selectPlaylistSelection(HMSPlaylistType.audio),
progress: selectPlaylistProgress(HMSPlaylistType.audio),
currentTime: selectPlaylistCurrentTime(HMSPlaylistType.audio),
playbackRate: selectPlaylistPlaybackRate(HMSPlaylistType.audio),
volume: selectPlaylistVolume(HMSPlaylistType.audio),
list: selectPlaylist(HMSPlaylistType.audio),
selectedItem: selectPlaylistSelectedItem(HMSPlaylistType.audio) as any,
};
export const selectVideoPlaylist: HMSPlaylistSelector = {
selection: selectPlaylistSelection(HMSPlaylistType.video),
progress: selectPlaylistProgress(HMSPlaylistType.video),
currentTime: selectPlaylistCurrentTime(HMSPlaylistType.video),
playbackRate: selectPlaylistPlaybackRate(HMSPlaylistType.video),
volume: selectPlaylistVolume(HMSPlaylistType.video),
list: selectPlaylist(HMSPlaylistType.video),
selectedItem: selectPlaylistSelectedItem(HMSPlaylistType.video) as any,
};