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
Get screen-sharing working, somehow
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
@@ -46,6 +46,31 @@ import { RoomMember } from '../models/room-member';
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
export interface ElectronDesktopCapturerSource {
|
||||||
|
display_id: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ElectronGetSourcesOptions {
|
||||||
|
fetchWindowIcons?: boolean;
|
||||||
|
thumbnailSize?: {
|
||||||
|
height: number;
|
||||||
|
width: number;
|
||||||
|
};
|
||||||
|
types: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
desktopCapturer?: {
|
||||||
|
getSources(options: ElectronGetSourcesOptions): Promise<ElectronDesktopCapturerSource[]>;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
interface CallOpts {
|
interface CallOpts {
|
||||||
roomId?: string,
|
roomId?: string,
|
||||||
client?: any, // Fix when client is TSified
|
client?: any, // Fix when client is TSified
|
||||||
@@ -332,23 +357,84 @@ 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 placeScreenSharingCall(remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement) {
|
async placeScreenSharingCall(
|
||||||
|
remoteVideoElement: HTMLVideoElement,
|
||||||
|
localVideoElement: HTMLVideoElement,
|
||||||
|
selectDesktopCapturerSource: (
|
||||||
|
sources: Array<ElectronDesktopCapturerSource>,
|
||||||
|
) => Promise<ElectronDesktopCapturerSource>,
|
||||||
|
) {
|
||||||
logger.debug("placeScreenSharingCall");
|
logger.debug("placeScreenSharingCall");
|
||||||
this.checkForErrorListener();
|
this.checkForErrorListener();
|
||||||
this.localVideoElement = localVideoElement;
|
this.localVideoElement = localVideoElement;
|
||||||
this.remoteVideoElement = remoteVideoElement;
|
this.remoteVideoElement = remoteVideoElement;
|
||||||
try {
|
|
||||||
this.screenSharingStream = await navigator.mediaDevices.getDisplayMedia({'audio': false});
|
if (window.desktopCapturer) {
|
||||||
logger.debug("Got screen stream, requesting audio stream...");
|
// We have access to the Electron desktop capturer
|
||||||
const audioConstraints = getUserMediaVideoContraints(CallType.Voice);
|
logger.debug("Electron desktopCapturer is available");
|
||||||
this.placeCallWithConstraints(audioConstraints);
|
try {
|
||||||
} catch (err) {
|
const options: ElectronGetSourcesOptions = {
|
||||||
this.emit(CallEvent.Error,
|
thumbnailSize: {
|
||||||
new CallError(
|
height: 176,
|
||||||
CallErrorCode.NoUserMedia,
|
width: 312,
|
||||||
"Failed to get screen-sharing stream: ", err,
|
},
|
||||||
),
|
types: [
|
||||||
);
|
"screen",
|
||||||
|
"window",
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
window.desktopCapturer.getSources(options).then((sources: Array<ElectronDesktopCapturerSource>) => {
|
||||||
|
console.log("Sources:", sources);
|
||||||
|
selectDesktopCapturerSource(sources).then((selectedSource)=> {
|
||||||
|
console.log("Source:", selectedSource);
|
||||||
|
window.navigator.mediaDevices.getUserMedia({
|
||||||
|
audio: false,
|
||||||
|
video: {
|
||||||
|
mandatory: {
|
||||||
|
chromeMediaSource: "desktop",
|
||||||
|
chromeMediaSourceId: selectedSource.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).then((stream)=> {
|
||||||
|
this.screenSharingStream = stream;
|
||||||
|
console.log("Stream", this.screenSharingStream);
|
||||||
|
logger.debug("Got screen stream, requesting audio stream...");
|
||||||
|
|
||||||
|
const audioConstraints = getUserMediaVideoContraints(CallType.Voice);
|
||||||
|
this.placeCallWithConstraints(audioConstraints);
|
||||||
|
}).catch( (error) => {
|
||||||
|
this.emit(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}).catch((error) => {
|
||||||
|
this.emit(error);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
this.emit(CallEvent.Error,
|
||||||
|
new CallError(
|
||||||
|
CallErrorCode.NoUserMedia,
|
||||||
|
"Failed to get screen-sharing stream: ", err,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* We do not have access to the Electron desktop capturer,
|
||||||
|
* therefore we can assume we are on the web */
|
||||||
|
logger.debug("Electron desktopCapturer is not available");
|
||||||
|
try {
|
||||||
|
this.screenSharingStream = await navigator.mediaDevices.getDisplayMedia({'audio': false});
|
||||||
|
logger.debug("Got screen stream, requesting audio stream...");
|
||||||
|
const audioConstraints = getUserMediaVideoContraints(CallType.Voice);
|
||||||
|
this.placeCallWithConstraints(audioConstraints);
|
||||||
|
} catch (err) {
|
||||||
|
this.emit(CallEvent.Error,
|
||||||
|
new CallError(
|
||||||
|
CallErrorCode.NoUserMedia,
|
||||||
|
"Failed to get screen-sharing stream: ", err,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.type = CallType.Video;
|
this.type = CallType.Video;
|
||||||
|
|||||||
Reference in New Issue
Block a user