@100mslive/hms-video-store 0.2.43 → 0.2.44
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/dist/core/hmsSDKStore/HMSPlaylist.d.ts +3 -5
- package/dist/core/hmsSDKStore/HMSSDKActions.d.ts +1 -0
- package/dist/core/hmsSDKStore/adapter.d.ts +2 -0
- package/dist/core/schema/playlist.d.ts +3 -4
- package/dist/hms-video-store.cjs.development.js +91 -86
- package/dist/hms-video-store.cjs.development.js.map +1 -1
- package/dist/hms-video-store.cjs.production.min.js +1 -1
- package/dist/hms-video-store.cjs.production.min.js.map +1 -1
- package/dist/hms-video-store.esm.js +91 -86
- package/dist/hms-video-store.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/core/hmsSDKStore/HMSPlaylist.ts +16 -29
- package/src/core/hmsSDKStore/HMSSDKActions.ts +31 -3
- package/src/core/hmsSDKStore/adapter.ts +6 -5
- package/src/core/schema/playlist.ts +3 -4
- package/src/core/schema/schema.ts +2 -0
- package/src/core/selectors/playlistselectors.ts +16 -14
- package/src/test/fakeStore.ts +2 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.44",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"zustand": "3.5.7"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@100mslive/hms-video": "0.0.
|
|
58
|
+
"@100mslive/hms-video": "0.0.187",
|
|
59
59
|
"events": "^3.3.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@size-limit/file": "^5.0.3",
|
|
63
|
-
"@100mslive/hms-video": "0.0.
|
|
63
|
+
"@100mslive/hms-video": "0.0.187",
|
|
64
64
|
"events": "^3.3.0",
|
|
65
65
|
"husky": "^6.0.0",
|
|
66
66
|
"size-limit": "^5.0.3",
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { HMSPlaylistItem, HMSPlaylistType,
|
|
1
|
+
import { HMSPlaylistItem, HMSPlaylistType, IHMSPlaylistActions } from '../schema';
|
|
2
2
|
import { HMSPlaylistManager } from './sdkTypes';
|
|
3
3
|
import { HMSLogger } from '../../common/ui-logger';
|
|
4
|
-
import { SDKToHMS } from './adapter';
|
|
5
4
|
|
|
6
5
|
export class HMSPlaylist implements IHMSPlaylistActions {
|
|
7
6
|
private type: HMSPlaylistType;
|
|
8
7
|
constructor(
|
|
9
8
|
private playlistManager: HMSPlaylistManager,
|
|
10
9
|
type: HMSPlaylistType,
|
|
11
|
-
private
|
|
12
|
-
private setState: (fn: (store: HMSStore) => void, name: string) => void,
|
|
10
|
+
private syncPlaylistState: (action: string) => void,
|
|
13
11
|
) {
|
|
14
12
|
this.type = type;
|
|
15
13
|
}
|
|
@@ -20,58 +18,47 @@ export class HMSPlaylist implements IHMSPlaylistActions {
|
|
|
20
18
|
return;
|
|
21
19
|
}
|
|
22
20
|
await this.playlistManager.setEnabled(true, { id, type: this.type });
|
|
23
|
-
this.syncRoomState(`playOn${this.type}Playlist`);
|
|
24
21
|
}
|
|
22
|
+
|
|
25
23
|
async pause(id: string): Promise<void> {
|
|
26
24
|
if (!id) {
|
|
27
25
|
HMSLogger.w('Please pass id and type to pause');
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
28
|
await this.playlistManager.setEnabled(false, { id, type: this.type });
|
|
31
|
-
this.
|
|
29
|
+
this.syncPlaylistState(`pauseOn${this.type}Playlist`);
|
|
32
30
|
}
|
|
31
|
+
|
|
33
32
|
async playNext(): Promise<void> {
|
|
34
33
|
await this.playlistManager.playNext(this.type);
|
|
35
|
-
this.syncRoomState(`playPreviousOn${this.type}Playlist`);
|
|
36
34
|
}
|
|
35
|
+
|
|
37
36
|
async playPrevious(): Promise<void> {
|
|
38
37
|
await this.playlistManager.playPrevious(this.type);
|
|
39
|
-
this.syncRoomState(`playPreviousOn${this.type}Playlist`);
|
|
40
38
|
}
|
|
39
|
+
|
|
41
40
|
seek(seekValue: number): void {
|
|
42
41
|
this.playlistManager.seek(seekValue, this.type);
|
|
43
|
-
this.
|
|
44
|
-
draftStore.playlist[this.type].progress = SDKToHMS.convertPlaylist(this.playlistManager)[
|
|
45
|
-
this.type
|
|
46
|
-
].progress;
|
|
47
|
-
}, `seekOn${this.type}Playlist`);
|
|
42
|
+
this.syncPlaylistState(`seekOn${this.type}Playlist`);
|
|
48
43
|
}
|
|
44
|
+
|
|
49
45
|
seekTo(seekValue: number): void {
|
|
50
46
|
this.playlistManager.seekTo(seekValue, this.type);
|
|
51
|
-
this.
|
|
52
|
-
draftStore.playlist[this.type].progress = SDKToHMS.convertPlaylist(this.playlistManager)[
|
|
53
|
-
this.type
|
|
54
|
-
].progress;
|
|
55
|
-
}, `seekToOn${this.type}Playlist`);
|
|
47
|
+
this.syncPlaylistState(`seekToOn${this.type}Playlist`);
|
|
56
48
|
}
|
|
49
|
+
|
|
57
50
|
setVolume(volume: number): void {
|
|
58
51
|
this.playlistManager.setVolume(volume, this.type);
|
|
59
|
-
this.
|
|
60
|
-
draftStore.playlist[this.type].volume = SDKToHMS.convertPlaylist(this.playlistManager)[
|
|
61
|
-
this.type
|
|
62
|
-
].volume;
|
|
63
|
-
}, `setVolumeOn${this.type}Playlist`);
|
|
52
|
+
this.syncPlaylistState(`setVolumeOn${this.type}Playlist`);
|
|
64
53
|
}
|
|
54
|
+
|
|
65
55
|
setList<T>(list: HMSPlaylistItem<T>[]): void {
|
|
66
56
|
this.playlistManager.setList(list);
|
|
67
|
-
this.
|
|
57
|
+
this.syncPlaylistState(`setListOn${this.type}Playlist`);
|
|
68
58
|
}
|
|
59
|
+
|
|
69
60
|
async stop(): Promise<void> {
|
|
70
61
|
await this.playlistManager.stop(this.type);
|
|
71
|
-
this.
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getCurrentTime() {
|
|
75
|
-
return this.playlistManager.getCurrentTime(this.type);
|
|
62
|
+
this.syncPlaylistState(`stop${this.type}Playlist`);
|
|
76
63
|
}
|
|
77
64
|
}
|
|
@@ -635,17 +635,21 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
635
635
|
this.audioPlaylist = new HMSPlaylist(
|
|
636
636
|
this.sdk.getPlaylistManager(),
|
|
637
637
|
HMSPlaylistType.audio,
|
|
638
|
-
this.
|
|
639
|
-
this.setState.bind(this),
|
|
638
|
+
this.syncPlaylistState.bind(this),
|
|
640
639
|
);
|
|
641
640
|
this.videoPlaylist = new HMSPlaylist(
|
|
642
641
|
this.sdk.getPlaylistManager(),
|
|
643
642
|
HMSPlaylistType.video,
|
|
644
643
|
this.syncRoomState.bind(this),
|
|
645
|
-
this.setState.bind(this),
|
|
646
644
|
);
|
|
647
645
|
this.syncRoomState('joinSync');
|
|
648
646
|
this.sdk.getPlaylistManager().onProgress(this.setProgress);
|
|
647
|
+
this.sdk.getPlaylistManager().onNewTrackStart((item: sdkTypes.HMSPlaylistItem<any>) => {
|
|
648
|
+
this.syncPlaylistState(`playOn${item.type}Playlist`);
|
|
649
|
+
});
|
|
650
|
+
this.sdk.getPlaylistManager().onPlaylistEnded((type: HMSPlaylistType) => {
|
|
651
|
+
this.syncPlaylistState(`${type}PlaylistEnded`);
|
|
652
|
+
});
|
|
649
653
|
}
|
|
650
654
|
|
|
651
655
|
protected onRoomUpdate() {
|
|
@@ -997,9 +1001,33 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
997
1001
|
private setProgress = ({ type, progress }: sdkTypes.HMSPlaylistProgressEvent) => {
|
|
998
1002
|
this.setState(draftStore => {
|
|
999
1003
|
draftStore.playlist[type].progress = progress;
|
|
1004
|
+
draftStore.playlist[type].currentTime = this.sdk.getPlaylistManager().getCurrentTime(type);
|
|
1000
1005
|
}, 'playlistProgress');
|
|
1001
1006
|
};
|
|
1002
1007
|
|
|
1008
|
+
private syncPlaylistState = (action: string) => {
|
|
1009
|
+
const sdkPeers: sdkTypes.HMSPeer[] = this.sdk.getPeers();
|
|
1010
|
+
const newHmsTracks: Record<HMSTrackID, Partial<HMSTrack>> = {};
|
|
1011
|
+
const newHmsSDkTracks: Record<HMSTrackID, SDKHMSTrack> = {};
|
|
1012
|
+
|
|
1013
|
+
// first convert everything in the new format
|
|
1014
|
+
for (let sdkPeer of sdkPeers) {
|
|
1015
|
+
const sdkTracks = [sdkPeer.audioTrack, sdkPeer.videoTrack, ...sdkPeer.auxiliaryTracks];
|
|
1016
|
+
for (let sdkTrack of sdkTracks) {
|
|
1017
|
+
if (!sdkTrack) {
|
|
1018
|
+
continue;
|
|
1019
|
+
}
|
|
1020
|
+
const hmsTrack = SDKToHMS.convertTrack(sdkTrack);
|
|
1021
|
+
newHmsTracks[hmsTrack.id] = hmsTrack;
|
|
1022
|
+
newHmsSDkTracks[sdkTrack.trackId] = sdkTrack;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
this.setState(draftStore => {
|
|
1026
|
+
mergeNewTracksInDraft(draftStore.tracks, newHmsTracks);
|
|
1027
|
+
Object.assign(draftStore.playlist, SDKToHMS.convertPlaylist(this.sdk.getPlaylistManager()));
|
|
1028
|
+
}, action);
|
|
1029
|
+
};
|
|
1030
|
+
|
|
1003
1031
|
/**
|
|
1004
1032
|
* setState is separate so any future changes to how state change can be done from one place.
|
|
1005
1033
|
* @param fn
|
|
@@ -167,11 +167,11 @@ export class SDKToHMS {
|
|
|
167
167
|
const list = playlistManager.getList(type);
|
|
168
168
|
const currentIndex = playlistManager.getCurrentIndex(type);
|
|
169
169
|
|
|
170
|
-
playlistManager.getList(type).forEach(
|
|
171
|
-
const isSelected =
|
|
172
|
-
convertedPlaylist[
|
|
173
|
-
...
|
|
174
|
-
type:
|
|
170
|
+
playlistManager.getList(type).forEach(playlistItem => {
|
|
171
|
+
const isSelected = playlistItem.url === currentSelection?.url;
|
|
172
|
+
convertedPlaylist[playlistItem.id] = {
|
|
173
|
+
...playlistItem,
|
|
174
|
+
type: playlistItem.type as HMSPlaylistType,
|
|
175
175
|
selected: isSelected,
|
|
176
176
|
playing: isSelected && isPlaying,
|
|
177
177
|
};
|
|
@@ -185,6 +185,7 @@ export class SDKToHMS {
|
|
|
185
185
|
},
|
|
186
186
|
progress,
|
|
187
187
|
volume,
|
|
188
|
+
currentTime: playlistManager.getCurrentTime(type),
|
|
188
189
|
};
|
|
189
190
|
}
|
|
190
191
|
}
|
|
@@ -27,12 +27,14 @@ export interface HMSPlaylist<T> {
|
|
|
27
27
|
selection: HMSPlaylistSelection;
|
|
28
28
|
progress: number;
|
|
29
29
|
volume: number;
|
|
30
|
+
currentTime: number;
|
|
30
31
|
};
|
|
31
32
|
video: {
|
|
32
33
|
list: Record<string, HMSPlaylistItem<T>>;
|
|
33
34
|
selection: HMSPlaylistSelection;
|
|
34
35
|
progress: number;
|
|
35
36
|
volume: number;
|
|
37
|
+
currentTime: number;
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
|
|
@@ -79,10 +81,6 @@ export interface IHMSPlaylistActions {
|
|
|
79
81
|
* Stop the current playback and remove the tracks
|
|
80
82
|
*/
|
|
81
83
|
stop(): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* Get current time of the current playing item
|
|
84
|
-
*/
|
|
85
|
-
getCurrentTime(): number;
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
export interface HMSPlaylistSelector {
|
|
@@ -99,4 +97,5 @@ export interface HMSPlaylistSelector {
|
|
|
99
97
|
selectedItem: <T>(store: HMSStore) => HMSPlaylistItem<T>;
|
|
100
98
|
progress: (store: HMSStore) => number;
|
|
101
99
|
volume: (store: HMSStore) => number;
|
|
100
|
+
currentTime: (store: HMSStore) => number;
|
|
102
101
|
}
|
|
@@ -51,12 +51,14 @@ export const createDefaultStoreState = (): HMSStore => {
|
|
|
51
51
|
selection: { id: '', hasPrevious: false, hasNext: false },
|
|
52
52
|
progress: 0,
|
|
53
53
|
volume: 0,
|
|
54
|
+
currentTime: 0,
|
|
54
55
|
},
|
|
55
56
|
video: {
|
|
56
57
|
list: {},
|
|
57
58
|
selection: { id: '', hasPrevious: false, hasNext: false },
|
|
58
59
|
progress: 0,
|
|
59
60
|
volume: 0,
|
|
61
|
+
currentTime: 0,
|
|
60
62
|
},
|
|
61
63
|
},
|
|
62
64
|
messages: { byID: {}, allIDs: [] },
|
|
@@ -15,6 +15,10 @@ const selectPlaylistProgress = (type: HMSPlaylistType = HMSPlaylistType.audio) =
|
|
|
15
15
|
store: HMSStore,
|
|
16
16
|
) => store.playlist[type].progress;
|
|
17
17
|
|
|
18
|
+
const selectPlaylistCurrentTime = (type: HMSPlaylistType = HMSPlaylistType.audio) => (
|
|
19
|
+
store: HMSStore,
|
|
20
|
+
) => store.playlist[type].currentTime;
|
|
21
|
+
|
|
18
22
|
const selectPlaylistVolume = (type: HMSPlaylistType = HMSPlaylistType.audio) => (store: HMSStore) =>
|
|
19
23
|
store.playlist[type].volume;
|
|
20
24
|
|
|
@@ -39,21 +43,19 @@ const selectPlaylistSelectedItem = (type: HMSPlaylistType = HMSPlaylistType.audi
|
|
|
39
43
|
);
|
|
40
44
|
|
|
41
45
|
export const selectAudioPlaylist: HMSPlaylistSelector = {
|
|
42
|
-
selection:
|
|
43
|
-
progress:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
),
|
|
46
|
+
selection: selectPlaylistSelection(HMSPlaylistType.audio),
|
|
47
|
+
progress: selectPlaylistProgress(HMSPlaylistType.audio),
|
|
48
|
+
currentTime: selectPlaylistCurrentTime(HMSPlaylistType.audio),
|
|
49
|
+
volume: selectPlaylistVolume(HMSPlaylistType.audio),
|
|
50
|
+
list: selectPlaylist(HMSPlaylistType.audio),
|
|
51
|
+
selectedItem: <any>selectPlaylistSelectedItem(HMSPlaylistType.audio),
|
|
49
52
|
};
|
|
50
53
|
|
|
51
54
|
export const selectVideoPlaylist: HMSPlaylistSelector = {
|
|
52
|
-
selection:
|
|
53
|
-
progress:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
),
|
|
55
|
+
selection: selectPlaylistSelection(HMSPlaylistType.video),
|
|
56
|
+
progress: selectPlaylistProgress(HMSPlaylistType.video),
|
|
57
|
+
currentTime: selectPlaylistCurrentTime(HMSPlaylistType.audio),
|
|
58
|
+
volume: selectPlaylistVolume(HMSPlaylistType.video),
|
|
59
|
+
list: selectPlaylist(HMSPlaylistType.video),
|
|
60
|
+
selectedItem: <any>selectPlaylistSelectedItem(HMSPlaylistType.video),
|
|
59
61
|
};
|
package/src/test/fakeStore.ts
CHANGED
|
@@ -113,6 +113,7 @@ export const makeFakeStore = (): HMSStore => {
|
|
|
113
113
|
selection: { id: 'audio1', hasNext: true, hasPrevious: false },
|
|
114
114
|
progress: 20,
|
|
115
115
|
volume: 100,
|
|
116
|
+
currentTime: 10,
|
|
116
117
|
},
|
|
117
118
|
video: {
|
|
118
119
|
list: {
|
|
@@ -136,6 +137,7 @@ export const makeFakeStore = (): HMSStore => {
|
|
|
136
137
|
selection: { id: 'video1', hasNext: true, hasPrevious: false },
|
|
137
138
|
progress: 30,
|
|
138
139
|
volume: 100,
|
|
140
|
+
currentTime: 20,
|
|
139
141
|
},
|
|
140
142
|
},
|
|
141
143
|
messages: {
|