1
0
mirror of https://github.com/pavlobu/deskreen.git synced 2025-05-18 16:30:10 -07:00
deskreen/app/features/PeerConnection/getDesktopSourceStreamBySourceID.ts
2020-12-09 16:17:02 +02:00

46 lines
1.2 KiB
TypeScript

export default async (
sourceID: string,
width: number | null | undefined = undefined,
height: number | null | undefined = undefined,
minSizeMultiplier = 1,
maxSizeMultiplier = 1,
minFrameRate = 15,
maxFrameRate = 60
) => {
if (width && height) {
return navigator.mediaDevices.getUserMedia({
audio: false,
video: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fine here, mandatory does not exist, it's a problem with types
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceID,
minWidth: width * minSizeMultiplier,
maxWidth: width * maxSizeMultiplier,
minHeight: height * minSizeMultiplier,
maxHeight: height * maxSizeMultiplier,
minFrameRate,
maxFrameRate,
},
},
});
}
return navigator.mediaDevices.getUserMedia({
audio: false,
video: {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore: fine here, mandatory does not exist, it's a problem with types
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceID,
minFrameRate,
maxFrameRate,
},
},
});
};