Closed omardoma closed 5 years ago
Based on the code you provided, you're removing the stream, before you add the stream:
Adding null isn't valid and will throw the same error.
peer.addStream(null) // not valid
Keep track of which stream was added to the peer.
this.members
.filter(member => member.peer)
.forEach(member => {
if (!member.localStream) return
member.peer.removeStream(member.localStream));
})
this.members
.filter(member => member.peer)
.forEach(member => {
member.localStream = this.localStream
member.peer.addStream(member.localStream)
});
Based on the code you provided, you're removing the stream, before you add the stream:
Adding null isn't valid and will throw the same error.
peer.addStream(null) // not valid
Keep track of which stream was added to the peer.
this.members .filter(member => member.peer) .forEach(member => { if (!member.localStream) return member.peer.removeStream(member.localStream)); })
this.members .filter(member => member.peer) .forEach(member => { member.localStream = this.localStream member.peer.addStream(member.localStream) });
I believe you got me wrong, this code runs when there is already a localStream that is shared with all peers and a user presses a button to switch on/off his video, so what happens is, I remove the current localStream which is never a null value, then close it, then initialize a new one with the new constraints and add it to the peers, so I am just switching an already existing and not null stream.
Can you log these three things before you call removeStream
?
console.log(peer._senderMap.get(this.localStream.getTracks()[0])
console.log(peer._senderMap.get(this.localStream.getTracks()[0]).get(this.localStream))
console.log(this.localStream)
Hi,
i have the same issue. It is not every time but sometimes i'll get the same error.
This is my source code
console.log("Pause stream");
try {
console.log(this.localStream);
console.log(this.RTCPeer._senderMap.get(this.localStream.getTracks()[0]));
console.log(this.RTCPeer._senderMap.get(this.localStream.getTracks()[0]).get(this.localStream));
}
catch( ex ) {
console.log( ex );
}
this.RTCPeer.removeStream(this.localStream);
This is my console.log output
gbt.js:410 Pause stream gbt.js:413 MediaStream {id: "iFru3oJQanTcCMGcCy80uOc6fCDuEcdSF4sY", active: true, onaddtrack: null, onremovetrack: null, onactive: null, …}active: trueid: "iFru3oJQanTcCMGcCy80uOc6fCDuEcdSF4sY"onactive: nullonaddtrack: nulloninactive: nullonremovetrack: nullproto: MediaStream gbt.js:414 undefined gbt.js:418 TypeError: Cannot read property 'get' of undefined at GBT.PauseStream (gbt.js:415) at HTMLButtonElement.
(bmas.html?debug=1:602) at HTMLButtonElement.dispatch (jquery.min.js:3) at HTMLButtonElement.q.handle (jquery.min.js:3) logger.min.js:1 rtc peer error Error: Cannot remove track that was never added.
I think the screenshot is easier to read:
It is on chrome 71.
Do You need more Informations?
Regards schirrmie
Thanks @schirrmie, that's very helpful.
Could you log two more things in browser console? Screenshot is fine.
console.log(this.RTCPeer._senderMap)
console.log(this.localStream.getTracks())
Hi, thank You for your quick reply.
This is the source code
console.log("Pause stream");
try {
console.log(this.localStream);
console.log(this.RTCPeer._senderMap)
console.log(this.localStream.getTracks())
console.log(this.RTCPeer._senderMap.get(this.localStream.getTracks()[0]));
console.log(this.RTCPeer._senderMap.get(this.localStream.getTracks()[0]).get(this.localStream));
}
catch( ex ) {
console.log( ex );
}
this.RTCPeer.removeStream(this.localStream);
And here is the console output:
this.RTCPeer._senderMap
is empty, which I don't think is possible if you've called addStream()
. Can you double-check that addStream is being called before removeStream?
Are you using replaceTrack at all?
Hi,
I never call addStream. But all streams are working, sending and receiving. I initialize SimplePeer like this:
var peer_options = {
initiator: initiator,
config: {
iceTransportPolicy: 'relay',
//rtcpMuxPolicy: 'negotiate',
iceServers: [
{ **** },
]
},
};
peer_options.stream = this.localStream;
this.RTCPeer = new SimplePeer( peer_options );
Anything wrong with this? Again video ist working fine, I see both sending and receiving on both sides.
Regards schirrmie
Oh and no I don't use replaceTrack.
I don't know how to reproduce this issue. It only happens 1 of 4 tries and I always do the same. It is strange :)
Do you call removeStream inside of an event, like “connect”?
No it is after the connect in an user event. A Button to enable / disable Video sending.
@t-mullen The issue in my case is, I start the peer connection with a MediaStream in the streams array, then when I need to switch off video for example on a click of a button, I do removeStream -> stop the stream -> addStream, but I get the error mentioned in the initial issue comment.
So it basically doesn't consider the initial connection stream as added before, and thus when you try to remove it even though it is there in the array of streams, it throws the error because you never did call addStream on it.
addStream
is called internally if you use the constructor option. And it's always called.
I'm not able to reproduce this at all...
Could you log the ID of the peer before you call addStream
and before you call removeStream
(to make sure it's indeed the same peer object).
console.log(peer.id)
Can you try putting a small timeout before you remove the stream? (To rule out any eventing race conditions).
setTimeout(()=>{
peer.removeStream(localStream)
}, 1000)
Alright, I've been able to reproduce this. Working on a fix.
Finally! thats great to hear, thanks for your hard work man!
hi, my issue is with reconnecting. After let's say answer peer reconnects the offering peer tries to switch the camera and gets an error, my case is with replace track...
Any solution, please?
I am using the latest version of the library, so basically what I am trying to do is to switch video on and off in my many to many call, so my approach is:
But I am getting the following error: