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

**URL:** <https://mediasoup.discourse.group/t/on-trackended-does-not-work-when-closing-the-webcam/1428>\
**Category:** mediasoup libraries\
**Created:** [July 12, 2020, 3:56pm UTC](https://mediasoup.discourse.group/t/on-trackended-does-not-work-when-closing-the-webcam/1428 "2020-07-12T15:56:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Madriix](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/madriix/32/1020_2.png) [@Madriix](https://mediasoup.discourse.group/u/Madriix)\
**Post date:** [July 12, 2020, 3:56pm UTC](https://mediasoup.discourse.group/t/on-trackended-does-not-work-when-closing-the-webcam/1428/1 "2020-07-12T15:56:54Z")

</div>

Hello

I am concerned by this same problem: : [detecting consumer closed/ track ended](https://mediasoup.discourse.group/t/detecting-consumer-closed-track-ended/592)

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:

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

```

For the transmitter, it is placed here:

```auto
 async sendVideo(track) {
    console.warn("room.sendVideo()");
    const videoProducer = await this.sendTransport.produce({
      track
    });
    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](https://github.com/meething/meething-mediasoup)

salutations

---

<div class="post-metadata">

**Author:** ![TheSalarKhan](https://yyz2.discourse-cdn.com/free1/user_avatar/mediasoup.discourse.group/thesalarkhan/32/630_2.png) [@TheSalarKhan](https://mediasoup.discourse.group/u/TheSalarKhan)\
**Post date:** [July 14, 2020, 12:36pm UTC](https://mediasoup.discourse.group/t/on-trackended-does-not-work-when-closing-the-webcam/1428/2 "2020-07-14T12:36:31Z")

</div>

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:

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

```

👍
