I am facing difficulty in running the remote stream. I am getting stream Object Ontrack Event but the video not getting played. (auto run is true) this is happening with a few peers, not with all the peers.
peer.iceConnectionState state changed to 'disconnected' and will never come back to the connected state.
what could be the solution for this situation.
peer.ontrack = e => {
console.log('video is receiveing')
e.track.onunmute = () => {
console.log('track unmuted');
addVideoElement(userId, e.streams[0])
}
}
function addVideoElement(userId, stream) {
const existingVideoElement = document.getElementById(userId)
console.log('existingVideoElement ',existingVideoElement)
if(existingVideoElement) {
existingVideoElement.srcObject = stream
return
}
console.log('new element for user', userId)
const videoCointainer = document.getElementById('videoListContainer')
const videoElement = document.createElement('video')
videoElement.setAttribute('id',userId)
videoElement.srcObject = stream
videoElement.muted = 0
videoElement.autoplay = true
if(iOS) {
videoElement.playsInline = true
}
if (userId === socket.id) {
videoElement.volume = 0
}
videoCointainer.appendChild(videoElement)
shouldMute(false)
}
Just because you get a stream object this does not mean the peerconnection got established which is a prerequisite for receiving data to display. If the first ice connection state you hit is "disconnected" that means the connection failed. Adding a TURN server increases the chance of success.