Remote VideoStream not working with WebRTC

后端 未结 2 1147
猫巷女王i
猫巷女王i 2020-12-14 03:50

EDIT: I wrote a detailed tutorial explaining how to build an simple Videochat-application including a signaling server:

Tutorial: Create your own Videochat-Applicat

相关标签:
2条回答
  • 2020-12-14 04:09
    function sharescreen(){
    getScreenStream(function(screenStream) {
    localpearconnection.removeTrack(localStream); 
    localpearconnection.addStream(screenStream);
    localpearconnection.createOffer().then(description => createdLocalDescription(description)).catch(errorHandler);
    document.getElementById('localVideo').srcObject = screenStream;});}
    
    function getScreenStream(callback) {
    if (navigator.getDisplayMedia) {
        navigator.getDisplayMedia({
            video: true
        }).then(screenStream => {
            callback(screenStream);
        });
    } else if (navigator.mediaDevices.getDisplayMedia) {
        navigator.mediaDevices.getDisplayMedia({
            video: true
        }).then(screenStream => {
            callback(screenStream);
        });
    } else {
        getScreenId(function(error, sourceId, screen_constraints) {
            navigator.mediaDevices.getUserMedia(screen_constraints).then(function(screenStream) {
                callback(screenStream);
            });
        });
    }}
    

    The above code working for me.

    0 讨论(0)
  • 2020-12-14 04:29

    I was having trouble with essentially the same thing recently, and the best advice I got from someone else on here was to create a version of my program in which I manually copied and pasted the SDP and ICE info from one "peer" (i.e., browser tab) to another and vice versa.

    By doing this, I realized several things:

    1. You must call the addStream method of the peer connection object before you attempt to create any offers/answers.

    2. Upon calling the createOffer or createAnswer method, the ICE candidates for that client are instantly generated. However, once you've sent the ICE info to the other peer, you cannot actually set the ICE info until after a remote description is set (by using the received offer/answer).

    3. Make sure that you are properly encoding all info about to be sent on the wire. In JS, this means that you should use the encodeURIComponent function on all data about to be sent on the wire. I had an issue in which SDP and ICE info would sometimes be set properly and sometimes not. It had to do with the fact that I was not URI-encoding the data, which led to any plus signs in the data being turned into spaces, which messed everything up.

    Anyway, like I said, I recommend creating a version of your program in which you have a bunch of text areas for spitting out all the data to the screen, and then have other text areas that you can paste copied data into for setting it for the other peer.
    Doing this really clarified the whole WebRTC process, which honestly, is not well explained in any documents/tutorials that I've seen yet.

    Good luck, and let me know if I can help anymore.

    0 讨论(0)
提交回复
热议问题