Event fired on localTrack.dispose()

Dear all, I’m developing a desktop sharing app using lib-jitsi-meet.js. I’m able to share the screen on a p2p connection, but I encountered issues when stopping the desktop sharing video stream. My client code is based on “example.js”. My understanding is when I stop the stream, I should loop through
“localTracks” and call “dispose()”, something like this:

"
for (let i = 0; i < localTracks.length; i++) {
localTracks[i].dispose();
}
"

And on the other side, the event fired would be “JitsiMeetJS.events.conference.TRACK_REMOVED”

  1. I wonder if my understanding is correct.
  2. Somehow “JitsiMeetJS.events.conference.TRACK_REMOVED” was triggered on the side that provides/starts the desktop stream, but it didn’t trigger on the other side that receives the stream.

Thanks.

I noticed when the track was removed from the laptop (the client that initiated the stream), the other client received “JitsiMeetJS.events.conference.TRACK_MUTE_CHANGED”. When the laptop left the conference (room), the client side (stream receiving end) received “JitsiMeetJS.events.conference.TRACK_REMOVED”. What is the correct way to close the stream on the sending side? Is it supposed to be “track.dispose()”? Thanks.