-
Notifications
You must be signed in to change notification settings - Fork 28
/
derivedSelectors.ts
61 lines (54 loc) · 1.98 KB
/
derivedSelectors.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
import { createSelector } from 'reselect';
import { selectLocalPeerRole, selectPeersMap, selectPreviewRole, selectRolesMap, selectTracksMap } from './selectors';
import { isRoleAllowedToPublish } from './selectorUtils';
import { HMSRole } from '../internal';
import { HMSPeer, HMSStore } from '../schema';
export interface HMSPeerWithMuteStatus {
peer: HMSPeer;
isAudioEnabled?: boolean;
}
/**
* @privateRemarks
* this is more friendly to UI format, the object in store has only peer id and role name instead of the full objects
*/
export interface HMSRoleChangeRequest {
requestedBy?: HMSPeer;
role: HMSRole;
token: string;
}
export const selectPeersWithAudioStatus = createSelector([selectPeersMap, selectTracksMap], (peersMap, tracksMap) => {
const participants: HMSPeerWithMuteStatus[] = Object.values(peersMap).map(peer => {
return {
peer: peer,
isAudioEnabled: peer.audioTrack ? tracksMap[peer.audioTrack]?.enabled : false,
};
});
return participants;
});
const selectRoleChangeStoreRequest = (store: HMSStore) => {
return store.roleChangeRequests[0] || null;
};
/**
* Select the role change request received for your local peer.
*/
export const selectRoleChangeRequest = createSelector(
[selectRoleChangeStoreRequest, selectPeersMap, selectRolesMap],
(request, peersMap, rolesMap): HMSRoleChangeRequest | null => {
if (!request) {
return null;
}
return {
requestedBy: request.requestedBy ? peersMap[request.requestedBy] : undefined,
role: rolesMap[request.roleName],
token: request.token,
};
},
);
/**
* Select what streams is the local peer allowed to publish from video, audio and screenshare.
*/
export const selectIsAllowedToPublish = createSelector([selectLocalPeerRole], role => isRoleAllowedToPublish(role));
/**
* Select what streams is the local peer allowed to preview from video, audio
*/
export const selectIsAllowedToPreviewMedia = createSelector([selectPreviewRole], role => isRoleAllowedToPublish(role));