jqueryhtmlwebrtcrtcmulticonnection

Add camera to existing connection between two user


I am facing this error when i add camera to existing connection, here is code by which i am connecting or adding the additional camera to the connection from first user to second user

 if (connection.mediaConstraints.video.optional.length && connection.attachStreams.length)
 { 
     connection.mediaConstraints.video.optional[0].sourceId = videoSourceId;
     var stream = event.stream;
     connection.removeStream({ audio: true });
     connection.addStream({ audio: true, video: true });
     videoId = this.id; 
  }

and this error occurs when i am trying this error: enter image description here

and by searching for this error i have tried every things but didn't get any solution if any one can give my solution.


Solution

  • Please try this:

    connection.mediaConstraints.video = {
        mandatory: {}, // keep this empty or use valid parameters
        optional: [{ // reset or override optional array
            sourceId: 'video-source-id'
        }]
    };
    
    if (DetectRTC.browser.name === 'Firefox') {
        connection.mediaConstraints.video = {
            deviceId: 'video-source-id' // Firefox requires "deviceId"
        };
    }
    
    connection.addStream({
        video: true
    });
    

    Points:

    1. Make sure that there is ONLY_ONE sourceId in the optional array.

      That's why always override/reset optional array.

    2. Make sure that mandatory constraints has empty or valid parameters.