Stream close on remove-stream

We are upgrading from licode 3 to 4.4 and are noticing an issue with the handling of stream-removed events when streams are unpublished.

In our application, we create a stream from a screen share. Once a stream is created, connections and other actions publish and unpublish that stream, many times if required. The problem is that when a client unpublishes a stream, it stops the source html stream. Once this happens, the source screen share is not available to share again.

Why is an erizo stream stopped, closed and deleted when it is removed from a room? Shouldn’t you be able to re-use an erizo stream for a subsequent re-publish? If the client can’t use re-use the Erizo stream, at least it should be able to re-use the underlying html stream.

In more detail, here is the code for Room.removeStream, where the stream stopped, closed and the source stream deleted:

  const removeStream = (streamInput) => {
    const stream = streamInput;
    if (stream.stream) {
      // Remove HTML element
      stream.hide();

      stream.stop();
      stream.close();
      delete stream.stream;
    }
    .....
  };

That call to stream.close() finds the source HTML stream and stops all the tracks on it:

  that.close = () => {
     .....
      // Remove HTML element
      that.hide();
      if (that.stream !== undefined) {
        that.stream.getTracks().forEach((trackInput) => {
          const track = trackInput;
          track.onended = null;
          track.stop();
        });
      }
      that.stream = undefined;
    }
  };

If I remove the room.removeStream code under “Remove the HTML element”, everything works as we need it to.

It seems like this code has been present for a long time, but in previous versions, it didn’t work the way it was intended in our application. In licode verison 3, the erizo stream’s input stream (erizoStream.stream) that came back from stream-removed events was always undefined. I’m not sure why event handling has changed but that stream.stream is now defined and track.stop() is called, and our screen share is destroyed.

Is there some other way I should be using the API to prevent the destruction of my input streams when the erizo stream is unpublished?