无法在kurento node js app中进行屏幕共享

时间:2017-05-29 15:23:20

标签: google-chrome webrtc kurento

以下代码适用于Firefox,但不适用于chrome。我有一个用于屏幕共享的chrome扩展程序,屏幕流被捕获,我可以将其发送到浏览器上的视频元素,但它不会转到其他webrtc端。

function getScreenConstraints(test, callback) {
var firefoxScreenConstraints = {
    mozMediaSource: 'window',
    mediaSource: 'window'
};

//if(isFirefox) return firefoxScreenConstraints;

if (isFirefox) return callback(null, firefoxScreenConstraints);

// this statement defines getUserMedia constraints
// that will be used to capture content of screen
var screen_constraints = {
    mandatory: {
        chromeMediaSource: chromeMediaSource,
        maxWidth: screen.width > 1920 ? screen.width : 1920,
        maxHeight: screen.height > 1080 ? screen.height : 1080
    }
};

// this statement verifies chrome extension availability
// if installed and available then it will invoke extension API
// otherwise it will fallback to command-line based screen capturing API
if (chromeMediaSource == 'desktop' && !sourceId) {




    getSourceId(function() {

        screen_constraints.mandatory.chromeMediaSourceId = sourceId;
        /*navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
                    navigator.getUserMedia({ video: screen_constraints }, function(stream) {
                        var video = document.querySelector('video');
                        console.log(video);
                        //var video = document.getElementById('videoInput');
                        video.src = URL.createObjectURL(stream);
                        video.play();
                    }, function(error) {
                        alert(JSON.stringify(error, null, '\t'));
                    });*/
        callback(sourceId == 'PermissionDeniedError' ? sourceId : null, screen_constraints);
    });
    //return;
}

// this statement sets gets 'sourceId" and sets "chromeMediaSourceId" 
if (chromeMediaSource == 'desktop') {
    screen_constraints.mandatory.chromeMediaSourceId = sourceId;


}
console.log(screen_constraints);
// now invoking native getUserMedia API
callback(null, screen_constraints);
}

function screen(to, from) {
if (to == '') {
    window.alert("You must specify the peer name");
    return;
}

var constraints = {
    audio: true,
    video: {
        mediaSource: 'window' || 'screen'
    }
}

setCallState(PROCESSING_CALL);

showSpinner(videoInput, videoOutput);

var options = {
    localVideo: videoInput, //if you want to see what you are sharing
    onicecandidate: onIceCandidate,
    sendSource: 'screen',
    mediaConstraints: constraints
}

webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendonly(options,
    function(error) {
        if (error) return onError(error) //You'll need to use whatever you use for handling errors

        this.generateOffer(
            function(error, offerSdp) {
                if (error) {
                    console.error(error);
                    setCallState(NO_CALL);
                }
                $("#callDiv").fadeIn();
                var message = {
                    id: 'call',
                    from: from,
                    to: to,
                    sdpOffer: offerSdp,
                    type: 'screen'
                };
                sendMessage(message);
            });
    });
  }

0 个答案:

没有答案