on ('trackended') does not work when closing the webcam


I am concerned by this same problem: : detecting consumer closed/ track ended

The “User Logged Out” system cannot be made by displaying it to both the sender and the recipient.

Do you know where to place this code JavaScript:

consumer.on("transportclose", async () => {
	console.warn("consumer.close() by transportclose");
	this.emit("@consumerDisconnected", { nickname: "test is disconnected" });

For the transmitter, it is placed here:

 async sendVideo(track) {
    const videoProducer = await this.sendTransport.produce({
    videoProducer.on("trackended", async () => {
      console.warn("producer.close() by trackended");
      await this._closeProducer(videoProducer);
    return videoProducer;

But I don’t know where to place the transportclose,

do you have an idea ?

I use this: https://github.com/meething/meething-mediasoup


The thread that you are addressing points to a generic WebRTC problem, so even though there is an event on mediasoup-client for trackended it does not get fired because of browser implementation.

You can do this out of band, and inform consumers about when a transport / producer ends on the server using an external mechanism like WebSocket.

But if you’re still thinking of doing it in band. Your best bet is still:

consumer.on(“trackended”, fn())


1 Like