[lib-jitsi-meet] Screenshare between Chrome and Firefox


I’ve been working for a couple of weeks with the lib-jitsi-meet API. Everything worked really well so far, but now I keep hitting my head against a wall when it comes to screensharing:

First, I followed the official example in https://github.com/jitsi/lib-jitsi-meet/blob/3c8d411c96fdfa18c57111630f29880f3f72949e/doc/example/example.js#L205-L226 but the results were very inconsistent and didn’t work on chrome.

I found this issue on github https://github.com/jitsi/lib-jitsi-meet/issues/1124 where the takeaway was “make sure you wait for disposal and remove tracks from the room”.

Now the screenshare is working well for Firefox, but unfortunately not in Chrome:
firefox <> firefox :white_check_mark:
chrome > firefox :white_check_mark:
firefox > chrome :x: (screenshare starts, freezes after ~1 sec and never comes back, switching back to camera doesn’t help)
chrome <> chrome :x: (only works the second time I activate screensharing, never the first)

I’m sure I’m doing something wrong, as it works on the jitsi-meet frontend in the same constellation - and even if my receiving end (the one receiving the screenshare) is in the jitsi-meet frontend and the sender is using the custom frontend it’s still working, only if both clients are in the custom frontend it stops working.
(same goes for the official example of the lib-jitsi-meet API btw.)

Would be thankful for some guidance where I’m going wrong and/or some best-practice tips for how to make it work…
here is a code snippet of the video switch:

export async function switchVideo() { 
    isVideo = !isVideo;
    if(localTracks[1]) {
      await room.removeTrack(localTracks[1]);
      await localTracks[1].dispose();
    return createLocalSwitchTrack(isVideo);

  function createLocalSwitchTrack(isVideo) {
    return JitsiMeetJS.createLocalTracks({
      devices: [isVideo ? "video" : "desktop"]
      .then(tracks => {
          if(localTracks.length > 2) console.warn("localtracks length is greater then 2, should only be 2");
          return localTracks;