0

I am trying to setup a webrtc peerconnection, but on receiving remote tracks no video or audio is playing in the html video element.

I think the issue is with multipal tracks that I am receiving, a total of 4 with 2 video and 2 audio tracks, Images Attached.

Note:- Offer, Answer and ICE candidate setup is working fine!

RemoteVideoRef.current.srcObject = new MediaStream();

peerconnection.ontrack = (event) => {
   event.streams[0].getTracks().forEach((track) => {
   RemoteVideoRef.current.srcObject.addTrack(track);
  });
};

first-2/4 tacks revived

next-2/4 tracks received

1 Answers1

1

I have a Solution for this Look at this Code...

HTML CODE: You need only the Video tag.

Index.html

<video id="remoteScreen"  autoplay="true"></video>

Screenshare.js file

const getLocalScreenCaptureStream = async () => {try {
const constraints = { video: { cursor: 'always' }, audio: false };
const screenCaptureStream = await navigator.mediaDevices.getDisplayMedia(constraints); 
return screenCaptureStream
} catch (error) {
console.error('failed to get local screen', error)
}
}

main.js

var localStreamScreen = null;
async function shareScreen() {localStreamScreen = await getLocalScreenCaptureStream(); console.log("localStreamScreen: ", localStreamScreen)}

screenshare.js

function handleRemoteStreamAddedScreen(event) {
console.log('Remote stream added.');
alert('Remote stream added.');
 if ('srcObject' in remoteScreen) {
remoteScreen.srcObject = event.streams[0];
 } else {
// deprecated
remoteScreen.src = window.URL.createObjectURL(event.stream);
}
 remoteScreenStream = event.stream};

I Hope, it will work for you.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 21 '22 at 15:45
  • Nope, I don't think so this relates to my question, the issue is with WebRTC peer connection ontarck() method. – Peter Austin Nov 22 '22 at 16:05
  • Can you please give me full code for solve and issue. And btw this code is of Webrtc screen sharing project. I have code for screen sharing, Mouse move from client side and also feature of Keyboards. – Naju Bhadarka Nov 23 '22 at 06:13
  • I have a similar issue. In my case, it was caused by ICE Candidate mismatch. If you have a user.name in SDP, ensure the user.name is the same in ICE candidate that you are sending. – Martin Oputa Jun 16 '23 at 13:59