1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Add getScreenshareContraints()

This is nicer since we avoid some async functions

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2021-03-02 12:58:45 +01:00
parent 5849ea8e63
commit e7562898cd

View File

@@ -178,7 +178,6 @@ enum ConstraintsType {
Audio = "audio",
Video = "video",
AudioVideo = "audiovideo",
Screenshare = "screenshare",
}
/**
@@ -335,10 +334,10 @@ export class MatrixCall extends EventEmitter {
* Place a voice call to this room.
* @throws If you have not specified a listener for 'error' events.
*/
async placeVoiceCall() {
placeVoiceCall() {
logger.debug("placeVoiceCall");
this.checkForErrorListener();
const constraints = await getUserMediaContraints(ConstraintsType.Audio);
const constraints = getUserMediaContraints(ConstraintsType.Audio);
this.placeCallWithConstraints(constraints);
this.type = CallType.Voice;
}
@@ -351,12 +350,12 @@ export class MatrixCall extends EventEmitter {
* to render the local camera preview.
* @throws If you have not specified a listener for 'error' events.
*/
async placeVideoCall(remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement) {
placeVideoCall(remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement) {
logger.debug("placeVideoCall");
this.checkForErrorListener();
this.localVideoElement = localVideoElement;
this.remoteVideoElement = remoteVideoElement;
const constraints = await getUserMediaContraints(ConstraintsType.AudioVideo);
const constraints = getUserMediaContraints(ConstraintsType.AudioVideo);
this.placeCallWithConstraints(constraints);
this.type = CallType.Video;
}
@@ -382,10 +381,7 @@ export class MatrixCall extends EventEmitter {
this.remoteVideoElement = remoteVideoElement;
try {
const screenshareConstraints = await getUserMediaContraints(
ConstraintsType.Screenshare,
selectDesktopCapturerSource,
);
const screenshareConstraints = await getScreenshareContraints();
if (window.electron?.getDesktopCapturerSources) {
// We are using Electron
logger.debug("Getting screen stream using getUserMedia()...");
@@ -397,7 +393,7 @@ export class MatrixCall extends EventEmitter {
}
logger.debug("Got screen stream, requesting audio stream...");
const audioConstraints = await getUserMediaContraints(ConstraintsType.Audio);
const audioConstraints = getUserMediaContraints(ConstraintsType.Audio);
this.placeCallWithConstraints(audioConstraints);
} catch (err) {
this.emit(CallEvent.Error,
@@ -598,7 +594,7 @@ export class MatrixCall extends EventEmitter {
logger.debug(`Answering call ${this.callId} of type ${this.type}`);
if (!this.localAVStream && !this.waitForLocalAVStream) {
const constraints = await getUserMediaContraints(
const constraints = getUserMediaContraints(
this.type == CallType.Video ?
ConstraintsType.AudioVideo:
ConstraintsType.Audio,
@@ -1704,10 +1700,7 @@ function setTracksEnabled(tracks: Array<MediaStreamTrack>, enabled: boolean) {
}
}
async function getUserMediaContraints(
type: ConstraintsType,
selectDesktopCapturerSource?: () => Promise<DesktopCapturerSource>,
) {
function getUserMediaContraints(type: ConstraintsType) {
const isWebkit = !!navigator.webkitGetUserMedia;
switch (type) {
@@ -1750,7 +1743,10 @@ async function getUserMediaContraints(
},
};
}
case ConstraintsType.Screenshare: {
}
}
async function getScreenshareContraints(selectDesktopCapturerSource?: () => Promise<DesktopCapturerSource>) {
if (window.electron?.getDesktopCapturerSources && selectDesktopCapturerSource) {
// We have access to getDesktopCapturerSources()
logger.debug("Electron getDesktopCapturerSources() is available...");
@@ -1775,8 +1771,6 @@ async function getUserMediaContraints(
};
}
}
}
}
let audioOutput: string;
let audioInput: string;