@100mslive/hms-video-store 0.2.48 → 0.2.51
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 +4 -2
- package/dist/core/hmsSDKStore/HMSSDKActions.d.ts +7 -3
- package/dist/core/hmsSDKStore/adapter.d.ts +13 -0
- package/dist/core/hmsSDKStore/sdkTypes.d.ts +2 -2
- package/dist/core/schema/playlist.d.ts +9 -10
- package/dist/core/schema/room.d.ts +11 -0
- package/dist/core/selectors/selectors.d.ts +20 -0
- package/dist/hms-video-store.cjs.development.js +83 -29
- 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 +82 -30
- package/dist/hms-video-store.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/core/hmsSDKStore/HMSPlaylist.ts +11 -5
- package/src/core/hmsSDKStore/HMSSDKActions.ts +43 -31
- package/src/core/hmsSDKStore/adapter.ts +15 -0
- package/src/core/hmsSDKStore/sdkTypes.ts +4 -0
- package/src/core/schema/playlist.ts +9 -10
- package/src/core/schema/room.ts +11 -0
- package/src/core/schema/schema.ts +11 -0
- package/src/core/selectors/selectors.ts +3 -0
- package/src/test/fakeStore.ts +11 -0
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.51",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -55,11 +55,11 @@
|
|
|
55
55
|
"zustand": "3.5.7"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
|
-
"@100mslive/hms-video": "0.0.
|
|
58
|
+
"@100mslive/hms-video": "0.0.199",
|
|
59
59
|
"events": "^3.3.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@100mslive/hms-video": "0.0.
|
|
62
|
+
"@100mslive/hms-video": "0.0.199",
|
|
63
63
|
"@size-limit/file": "^5.0.3",
|
|
64
64
|
"events": "^3.3.0",
|
|
65
65
|
"husky": "^6.0.0",
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { HMSPlaylistItem, HMSPlaylistType, IHMSPlaylistActions } from '../schema';
|
|
2
2
|
import { HMSPlaylistManager } from './sdkTypes';
|
|
3
3
|
import { HMSLogger } from '../../common/ui-logger';
|
|
4
|
+
import { IHMSStore } from '../IHMSStore';
|
|
5
|
+
import { selectVideoPlaylist, selectAudioPlaylist } from '../selectors';
|
|
4
6
|
|
|
5
7
|
export class HMSPlaylist implements IHMSPlaylistActions {
|
|
6
8
|
private type: HMSPlaylistType;
|
|
@@ -8,24 +10,28 @@ export class HMSPlaylist implements IHMSPlaylistActions {
|
|
|
8
10
|
private playlistManager: HMSPlaylistManager,
|
|
9
11
|
type: HMSPlaylistType,
|
|
10
12
|
private syncPlaylistState: (action: string) => void,
|
|
13
|
+
private store: IHMSStore,
|
|
11
14
|
) {
|
|
12
15
|
this.type = type;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
async play(id: string): Promise<void> {
|
|
16
19
|
if (!id) {
|
|
17
|
-
HMSLogger.w('Please pass id
|
|
20
|
+
HMSLogger.w('Please pass id to play');
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
20
23
|
await this.playlistManager.setEnabled(true, { id, type: this.type });
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
async pause(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
async pause(): Promise<void> {
|
|
27
|
+
const selector =
|
|
28
|
+
this.type === HMSPlaylistType.audio ? selectAudioPlaylist : selectVideoPlaylist;
|
|
29
|
+
const selection = this.store.getState(selector.selection);
|
|
30
|
+
if (!selection.id) {
|
|
31
|
+
HMSLogger.w('No item is currently playing to pause');
|
|
26
32
|
return;
|
|
27
33
|
}
|
|
28
|
-
await this.playlistManager.setEnabled(false, { id, type: this.type });
|
|
34
|
+
await this.playlistManager.setEnabled(false, { id: selection.id, type: this.type });
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
async playNext(): Promise<void> {
|
|
@@ -5,63 +5,64 @@ import {
|
|
|
5
5
|
HMSMessageInput,
|
|
6
6
|
HMSPeer,
|
|
7
7
|
HMSPeerID,
|
|
8
|
+
HMSPlaylistType,
|
|
8
9
|
HMSRoomState,
|
|
9
10
|
HMSStore,
|
|
10
11
|
HMSTrack,
|
|
11
12
|
HMSTrackID,
|
|
12
13
|
HMSTrackSource,
|
|
14
|
+
IHMSPlaylistActions,
|
|
13
15
|
} from '../schema';
|
|
14
16
|
import { IHMSActions } from '../IHMSActions';
|
|
15
17
|
import * as sdkTypes from './sdkTypes';
|
|
16
18
|
import { SDKToHMS } from './adapter';
|
|
17
19
|
import {
|
|
20
|
+
HMSRoleChangeRequest,
|
|
21
|
+
selectHMSMessagesCount,
|
|
18
22
|
selectIsLocalScreenShared,
|
|
23
|
+
selectIsLocalVideoDisplayEnabled,
|
|
19
24
|
selectIsLocalVideoEnabled,
|
|
20
25
|
selectLocalAudioTrackID,
|
|
21
|
-
selectLocalVideoTrackID,
|
|
22
|
-
selectHMSMessagesCount,
|
|
23
|
-
selectIsLocalVideoDisplayEnabled,
|
|
24
26
|
selectLocalPeer,
|
|
27
|
+
selectLocalTrackIDs,
|
|
28
|
+
selectLocalVideoTrackID,
|
|
25
29
|
selectPeerByID,
|
|
26
|
-
HMSRoleChangeRequest,
|
|
27
|
-
selectTrackByID,
|
|
28
|
-
selectRoomStarted,
|
|
29
30
|
selectPermissions,
|
|
30
31
|
selectRolesMap,
|
|
31
|
-
|
|
32
|
+
selectRoomStarted,
|
|
32
33
|
selectRoomState,
|
|
34
|
+
selectTrackByID,
|
|
33
35
|
} from '../selectors';
|
|
34
36
|
import { HMSLogger } from '../../common/ui-logger';
|
|
35
37
|
import {
|
|
36
|
-
HMSSdk,
|
|
37
|
-
HMSVideoPlugin,
|
|
38
38
|
HMSAudioPlugin,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
HMSAudioTrack as SDKHMSAudioTrack,
|
|
40
|
+
HMSChangeTrackStateRequest as SDKHMSChangeTrackStateRequest,
|
|
41
|
+
HMSException as SDKHMSException,
|
|
42
|
+
HMSLeaveRoomRequest as SDKHMSLeaveRoomRequest,
|
|
42
43
|
HMSLocalAudioTrack as SDKHMSLocalAudioTrack,
|
|
44
|
+
HMSLocalTrack as SDKHMSLocalTrack,
|
|
43
45
|
HMSLocalVideoTrack as SDKHMSLocalVideoTrack,
|
|
46
|
+
HMSLogLevel,
|
|
44
47
|
HMSRemoteTrack as SDKHMSRemoteTrack,
|
|
45
|
-
|
|
46
|
-
HMSVideoTrack as SDKHMSVideoTrack,
|
|
47
|
-
HMSException as SDKHMSException,
|
|
48
|
+
HMSRemoteVideoTrack as SDKHMSRemoteVideoTrack,
|
|
48
49
|
HMSRoleChangeRequest as SDKHMSRoleChangeRequest,
|
|
49
|
-
|
|
50
|
+
HMSSdk,
|
|
50
51
|
HMSSimulcastLayer,
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
HMSTrack as SDKHMSTrack,
|
|
53
|
+
HMSVideoPlugin,
|
|
54
|
+
HMSVideoTrack as SDKHMSVideoTrack,
|
|
53
55
|
} from '@100mslive/hms-video';
|
|
54
56
|
import { IHMSStore } from '../IHMSStore';
|
|
55
57
|
|
|
56
58
|
import {
|
|
59
|
+
areArraysEqual,
|
|
57
60
|
mergeNewPeersInDraft,
|
|
58
61
|
mergeNewTracksInDraft,
|
|
59
|
-
areArraysEqual,
|
|
60
62
|
} from './sdkUtils/storeMergeUtils';
|
|
61
63
|
import { HMSNotifications } from './HMSNotifications';
|
|
62
64
|
import { NamedSetState } from './internalTypes';
|
|
63
65
|
import { isRemoteTrack } from './sdkUtils/sdkUtils';
|
|
64
|
-
import { HMSPlaylistType, IHMSPlaylistActions } from '../schema';
|
|
65
66
|
import { HMSPlaylist } from './HMSPlaylist';
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -123,7 +124,7 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
123
124
|
if (track) {
|
|
124
125
|
if (track instanceof SDKHMSRemoteVideoTrack) {
|
|
125
126
|
track.preferLayer(layer);
|
|
126
|
-
this.
|
|
127
|
+
this.updateVideoLayer(trackId, 'setPreferredLayer');
|
|
127
128
|
} else {
|
|
128
129
|
HMSLogger.w(`track ${trackId} is not an video track`);
|
|
129
130
|
}
|
|
@@ -348,6 +349,7 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
348
349
|
const sdkTrack = this.hmsSDKTracks[trackID];
|
|
349
350
|
if (sdkTrack && sdkTrack.type === 'video') {
|
|
350
351
|
await (sdkTrack as SDKHMSVideoTrack).removeSink(videoElement);
|
|
352
|
+
this.updateVideoLayer(trackID, 'detachVideo');
|
|
351
353
|
} else {
|
|
352
354
|
this.logPossibleInconsistency('no video track found to remove sink');
|
|
353
355
|
}
|
|
@@ -559,16 +561,7 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
559
561
|
const sdkTrack = this.hmsSDKTracks[trackID];
|
|
560
562
|
if (sdkTrack && sdkTrack.type === 'video') {
|
|
561
563
|
await (sdkTrack as SDKHMSVideoTrack).addSink(videoElement);
|
|
562
|
-
|
|
563
|
-
if (
|
|
564
|
-
sdkTrack instanceof SDKHMSRemoteVideoTrack &&
|
|
565
|
-
sdkTrack.getSimulcastDefinitions().length > 0
|
|
566
|
-
) {
|
|
567
|
-
this.setState(draft => {
|
|
568
|
-
const layer = sdkTrack.getSimulcastLayer();
|
|
569
|
-
draft.tracks[trackID].layer = layer;
|
|
570
|
-
}, 'updateLayerOnAttach');
|
|
571
|
-
}
|
|
564
|
+
this.updateVideoLayer(trackID, 'attachVideo');
|
|
572
565
|
} else {
|
|
573
566
|
this.logPossibleInconsistency('no video track found to add sink');
|
|
574
567
|
}
|
|
@@ -617,6 +610,9 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
617
610
|
}
|
|
618
611
|
}
|
|
619
612
|
|
|
613
|
+
const recording = this.sdk.getRecordingState();
|
|
614
|
+
const rtmp = this.sdk.getRTMPState();
|
|
615
|
+
|
|
620
616
|
// then merge them carefully with our store so if something hasn't changed
|
|
621
617
|
// the reference shouldn't change. Note that the draftStore is an immer draft
|
|
622
618
|
// object.
|
|
@@ -631,6 +627,7 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
631
627
|
this.hmsSDKTracks = newHmsSDkTracks;
|
|
632
628
|
Object.assign(draftStore.roles, SDKToHMS.convertRoles(this.sdk.getRoles()));
|
|
633
629
|
Object.assign(draftStore.playlist, SDKToHMS.convertPlaylist(this.sdk.getPlaylistManager()));
|
|
630
|
+
Object.assign(draftStore.room, SDKToHMS.convertRecordingRTMPState(recording, rtmp));
|
|
634
631
|
}, action);
|
|
635
632
|
}
|
|
636
633
|
|
|
@@ -647,11 +644,13 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
647
644
|
this.sdk.getPlaylistManager(),
|
|
648
645
|
HMSPlaylistType.audio,
|
|
649
646
|
this.syncPlaylistState.bind(this),
|
|
647
|
+
this.store,
|
|
650
648
|
);
|
|
651
649
|
this.videoPlaylist = new HMSPlaylist(
|
|
652
650
|
this.sdk.getPlaylistManager(),
|
|
653
651
|
HMSPlaylistType.video,
|
|
654
652
|
this.syncRoomState.bind(this),
|
|
653
|
+
this.store,
|
|
655
654
|
);
|
|
656
655
|
this.syncRoomState('joinSync');
|
|
657
656
|
this.setState(store => {
|
|
@@ -828,6 +827,19 @@ export class HMSSDKActions implements IHMSActions {
|
|
|
828
827
|
HMSLogger.e('received error from sdk', error);
|
|
829
828
|
}
|
|
830
829
|
|
|
830
|
+
/**
|
|
831
|
+
* the layer gets updated on addsink/removesink/preferlayer calls, for simulcast there
|
|
832
|
+
* can be multiple layers, while for non simulcast there will be None and High.
|
|
833
|
+
*/
|
|
834
|
+
private updateVideoLayer(trackID: string, action: string) {
|
|
835
|
+
const sdkTrack = this.hmsSDKTracks[trackID];
|
|
836
|
+
if (sdkTrack && sdkTrack instanceof SDKHMSRemoteVideoTrack) {
|
|
837
|
+
this.setState(draft => {
|
|
838
|
+
draft.tracks[trackID].layer = sdkTrack.getSimulcastLayer();
|
|
839
|
+
}, action);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
831
843
|
private handleTrackRemove(sdkTrack: SDKHMSTrack, sdkPeer: sdkTypes.HMSPeer) {
|
|
832
844
|
this.setState(draftStore => {
|
|
833
845
|
const hmsPeer = draftStore.peers[sdkPeer.peerId];
|
|
@@ -188,4 +188,19 @@ export class SDKToHMS {
|
|
|
188
188
|
currentTime: playlistManager.getCurrentTime(type),
|
|
189
189
|
};
|
|
190
190
|
}
|
|
191
|
+
|
|
192
|
+
static convertRecordingRTMPState(
|
|
193
|
+
recording: sdkTypes.HMSRecording | undefined,
|
|
194
|
+
rtmp: sdkTypes.HMSRTMP | undefined,
|
|
195
|
+
) {
|
|
196
|
+
return {
|
|
197
|
+
recording: {
|
|
198
|
+
browser: {
|
|
199
|
+
running: !!recording?.browser.running,
|
|
200
|
+
},
|
|
201
|
+
server: { running: !!recording?.server?.running },
|
|
202
|
+
},
|
|
203
|
+
rtmp: { running: !!rtmp?.running },
|
|
204
|
+
};
|
|
205
|
+
}
|
|
191
206
|
}
|
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
HMSPlaylistManager,
|
|
23
23
|
HMSPlaylistProgressEvent,
|
|
24
24
|
RTMPRecordingConfig,
|
|
25
|
+
HMSRecording,
|
|
26
|
+
HMSRTMP,
|
|
25
27
|
} from '@100mslive/hms-video';
|
|
26
28
|
|
|
27
29
|
export {
|
|
@@ -48,4 +50,6 @@ export {
|
|
|
48
50
|
HMSPlaylistManager,
|
|
49
51
|
HMSPlaylistProgressEvent,
|
|
50
52
|
RTMPRecordingConfig,
|
|
53
|
+
HMSRecording,
|
|
54
|
+
HMSRTMP,
|
|
51
55
|
};
|
|
@@ -40,40 +40,39 @@ export interface HMSPlaylist<T> {
|
|
|
40
40
|
|
|
41
41
|
export interface IHMSPlaylistActions {
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Pass the id of the item to be played
|
|
44
44
|
* @param {string} id - id of playlist item
|
|
45
45
|
*/
|
|
46
46
|
play(id: string): Promise<void>;
|
|
47
47
|
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {string} id - id of playlist item
|
|
48
|
+
* Pauses current playing item
|
|
50
49
|
*/
|
|
51
|
-
pause(
|
|
50
|
+
pause(): Promise<void>;
|
|
52
51
|
/**
|
|
53
|
-
* PlayNext
|
|
52
|
+
* PlayNext
|
|
54
53
|
*/
|
|
55
54
|
playNext(): Promise<void>;
|
|
56
55
|
/**
|
|
57
|
-
* PlayPrevious
|
|
56
|
+
* PlayPrevious
|
|
58
57
|
*/
|
|
59
58
|
playPrevious(): Promise<void>;
|
|
60
59
|
/**
|
|
61
|
-
* seek
|
|
60
|
+
* seek passing seekValue - this is relative to current position
|
|
62
61
|
* @param {number} seekValue - number in seconds to move forwards(pass negative values to move backwards)
|
|
63
62
|
*/
|
|
64
63
|
seek(seekValue: number): void;
|
|
65
64
|
/**
|
|
66
|
-
* seek
|
|
65
|
+
* seek passing seekValue - seekValue will be absolute
|
|
67
66
|
* @param {number} seekValue - value in seconds of absolute position in the playlist item duration
|
|
68
67
|
*/
|
|
69
68
|
seekTo(seekValue: number): void;
|
|
70
69
|
/**
|
|
71
|
-
* set
|
|
70
|
+
* set volume passing volume
|
|
72
71
|
* @param {number} volume - number between 0-100
|
|
73
72
|
*/
|
|
74
73
|
setVolume(volume: number): void;
|
|
75
74
|
/**
|
|
76
|
-
* pass list
|
|
75
|
+
* pass list to set playlist
|
|
77
76
|
* @param {HMSPlaylistItem[]} - list of playlist items
|
|
78
77
|
*/
|
|
79
78
|
setList<T>(list: HMSPlaylistItem<T>[]): void;
|
package/src/core/schema/room.ts
CHANGED
|
@@ -19,4 +19,15 @@ export interface HMSRoom {
|
|
|
19
19
|
shareableLink: string;
|
|
20
20
|
hasWaitingRoom: boolean;
|
|
21
21
|
roomState: HMSRoomState;
|
|
22
|
+
recording: {
|
|
23
|
+
browser: {
|
|
24
|
+
running: boolean;
|
|
25
|
+
};
|
|
26
|
+
server: {
|
|
27
|
+
running: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
rtmp: {
|
|
31
|
+
running: boolean;
|
|
32
|
+
};
|
|
22
33
|
}
|
|
@@ -42,6 +42,17 @@ export const createDefaultStoreState = (): HMSStore => {
|
|
|
42
42
|
shareableLink: '',
|
|
43
43
|
hasWaitingRoom: false,
|
|
44
44
|
roomState: HMSRoomState.Disconnected,
|
|
45
|
+
recording: {
|
|
46
|
+
browser: {
|
|
47
|
+
running: false,
|
|
48
|
+
},
|
|
49
|
+
server: {
|
|
50
|
+
running: false,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
rtmp: {
|
|
54
|
+
running: false,
|
|
55
|
+
},
|
|
45
56
|
},
|
|
46
57
|
peers: {},
|
|
47
58
|
tracks: {},
|
|
@@ -379,3 +379,6 @@ export const selectIsAllowedToSubscribe = createSelector([selectLocalPeerRole],
|
|
|
379
379
|
* Select the permissions which determine what actions the local peer can do.
|
|
380
380
|
*/
|
|
381
381
|
export const selectPermissions = createSelector(selectLocalPeerRole, role => role?.permissions);
|
|
382
|
+
|
|
383
|
+
export const selectRecordingState = createSelector(selectRoom, room => room.recording);
|
|
384
|
+
export const selectRTMPState = createSelector(selectRoom, room => room.rtmp);
|
package/src/test/fakeStore.ts
CHANGED
|
@@ -60,6 +60,17 @@ export const makeFakeStore = (): HMSStore => {
|
|
|
60
60
|
shareableLink: '',
|
|
61
61
|
hasWaitingRoom: false,
|
|
62
62
|
roomState: HMSRoomState.Disconnected,
|
|
63
|
+
recording: {
|
|
64
|
+
browser: {
|
|
65
|
+
running: false,
|
|
66
|
+
},
|
|
67
|
+
server: {
|
|
68
|
+
running: false,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
rtmp: {
|
|
72
|
+
running: false,
|
|
73
|
+
},
|
|
63
74
|
},
|
|
64
75
|
peers: {
|
|
65
76
|
'1': {
|