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