Start to request screen sharing

This commit is contained in:
2020-04-13 16:48:58 +02:00
parent d297bf92d0
commit 40ef78acc6
4 changed files with 280 additions and 6 deletions

View File

@ -791,4 +791,31 @@ function IsFullScreen(){
*/
function checkEmojiCode(s) {
return s.match(/^:[a-zA-Z0-9]+:$/) != null
}
/**
* Request user screen as stream
*
* @return {Promise<MediaStream>}
*/
function requestUserScreen() {
return new Promise((onSuccess, onFailure) => {
getScreenId(function (error, sourceId, screen_constraints) {
if(error != null)
return onFailure(error)
// error == null || 'permission-denied' || 'not-installed' || 'installed-disabled' || 'not-chrome'
// sourceId == null || 'string' || 'firefox'
if(navigator.getDisplayMedia) {
navigator.getDisplayMedia(screen_constraints).then(onSuccess, onFailure);
}
else {
navigator.mediaDevices.getUserMedia(screen_constraints).then(onSuccess).catch(onFailure);
}
});
})
}

View File

@ -254,6 +254,9 @@ class CallWindow extends CustomEvents {
// Parse list of menu entries
for(const entry of menuEntries) {
if(entry.needVideo && !this.allowVideo)
continue
const a = createElem2({
appendTo: menuEntriesTarget,
type: "li",
@ -666,14 +669,33 @@ class CallWindow extends CustomEvents {
* Start to send this client audio & video
*
* @param {boolean} includeVideo
* @param {boolean} shareScreen
*/
async startStreaming(includeVideo) {
async startStreaming(includeVideo, shareScreen = false) {
// First, query user media
const stream = await navigator.mediaDevices.getUserMedia({
video: this.conv.can_have_video_call && includeVideo,
audio: true
})
let videoConstraints = this.conv.can_have_video_call && includeVideo;
let stream;
// Get user screen
if(includeVideo && shareScreen) {
stream = await requestUserScreen(true)
const second_stream = await navigator.mediaDevices.getUserMedia({
audio: true
})
stream.addTrack(second_stream.getAudioTracks()[0])
}
// Use regular webcam
else {
// First, query user media
stream = await navigator.mediaDevices.getUserMedia({
video: videoConstraints,
audio: true,
})
}
this.mainStream = stream;
if(includeVideo)