Hi i´m currently developing a webRTC app. Its a "video adviser", clients make a video call with sellers, and now i want the sellers to also share their screen (without losing the video call). I managed to make it work all together, but when a client finishes the call, and a new client arrives, when the seller tries to share his screen again (with this new client) an error occurs.
The error is the following one: enter image description here
I think that the problem is that the screen sharing API does not support ending and reopening the screen share without refreshing the window (this is what i want, to keep the seller online and listening once he finishes the calls without refreshing the entire page).
This is the code to cancel the screen sharing once a client leaves the call:
if(yourConn.getLocalStreams()[1] != null){
var screenStreaming = yourConn.getLocalStreams()[1];
yourConn.removeStream(screenStreaming);
screenStreaming.getTracks().forEach(track => track.stop());
}
I know this code stops succesfully the screen sharing but i dont understand why when i create a new screen sharing stream, the error that i posted appears. I really need help.
By the way, im using Chrome.
Thanks to all for reading and sorry if i dont asked clearly, this is my first question.
Starting and stopping screensharing is certainly possible more than once. InvalidStateError sounds (vaguely) like you are trying to reuse the id from the chooseDesktopMedia that is passed in chromeMediaSourceId more than once. This is not possible afaik and you need to call chooseDesktopMedia again (and let the user select the screen again)