-
Notifications
You must be signed in to change notification settings - Fork 28
/
selectorUtils.ts
87 lines (77 loc) · 2.22 KB
/
selectorUtils.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import {
HMSPeer,
HMSPublishAllowed,
HMSRole,
HMSScreenAudioTrack,
HMSScreenVideoTrack,
HMSStore,
HMSTrack,
HMSTrackID,
HMSVideoTrack,
} from '../schema';
export function getScreenSharesByPeer(tracks: Record<HMSTrackID, HMSTrack>, peer?: HMSPeer | null) {
let videoTrack = undefined;
let audioTrack = undefined;
if (peer) {
for (const trackID of peer.auxiliaryTracks) {
const track = tracks[trackID];
if (isScreenShare(track)) {
audioTrack = isAudio(track) ? track : audioTrack;
videoTrack = isVideo(track) ? track : videoTrack;
}
}
}
// to use the proper type, right now it is only used for screenshare.
return { video: videoTrack as HMSScreenVideoTrack, audio: audioTrack as HMSScreenAudioTrack };
}
export function isAudio(track: HMSTrack | undefined) {
return track && track.type === 'audio';
}
export function isVideo(track: HMSTrack | undefined) {
return track && track.type === 'video';
}
export function isScreenShare(track: HMSTrack | undefined) {
return track && track.source === 'screen';
}
export function isAudioPlaylist(track: HMSTrack | undefined) {
return track && track.source === 'audioplaylist';
}
export function isVideoPlaylist(track: HMSTrack | undefined) {
return track && track.source === 'videoplaylist';
}
export function isDegraded(track: HMSVideoTrack) {
if (track) {
return Boolean(track?.degraded);
}
return false;
}
export function isTrackEnabled(store: HMSStore, trackID?: string) {
if (trackID && store.tracks[trackID]) {
return store.tracks[trackID].enabled;
}
return false;
}
/**
* Should UI show the video track as enabled
*/
export function isTrackDisplayEnabled(store: HMSStore, trackID?: string) {
if (trackID && store.tracks[trackID]) {
return store.tracks[trackID].displayEnabled;
}
return false;
}
export function isRoleAllowedToPublish(role?: HMSRole | null): HMSPublishAllowed {
let video = false,
audio = false,
screen = false;
if (role?.publishParams?.allowed) {
video = role.publishParams.allowed.includes('video');
audio = role.publishParams.allowed.includes('audio');
screen = role.publishParams.allowed.includes('screen');
}
return {
video,
audio,
screen,
};
}