1

I am using simple-peer in my video chat web application. If both the users are in audio call how can I add Video track and how can I disable it. If I use replaceTrack I am again which is giving this issue

error Error: [object RTCErrorEvent]
at makeError (index.js:17)
at RTCDataChannel._channel.onerror (index.js:490)

I am showing a profile picture if the video is not enabled for users. if Video is enabled I want to replace this picture with video and replace it for all people in the call

yoonus
  • 41
  • 7

1 Answers1

1

If both the users enabled audio only, stream contain only audio track so here we can add black space (ended video track ).so we can easily solve this issue for more info visit this https://blog.mozilla.org/webrtc/warm-up-with-replacetrack/

Code from the above link


    let silence = () => {
      let ctx = new AudioContext(), oscillator = ctx.createOscillator();
      let dst = oscillator.connect(ctx.createMediaStreamDestination());
      oscillator.start();
      return Object.assign(dst.stream.getAudioTracks()[0], {enabled: false});
    }
    
    let black = ({width = 640, height = 480} = {}) => {
      let canvas = Object.assign(document.createElement("canvas"), {width, height});
      canvas.getContext('2d').fillRect(0, 0, width, height);
      let stream = canvas.captureStream();
      return Object.assign(stream.getVideoTracks()[0], {enabled: false});
    }
    
    let blackSilence = (...args) => new MediaStream([black(...args), silence()]);
    
    video.srcObject = blackSilence();

yoonus
  • 41
  • 7
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Jourmand Sep 07 '21 at 13:26