# sessionDisconnected event invoke multiple times, what can be reasons for this?

**URL:** <https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339>\
**Category:** Issues developing apps\
**Tags:** v2\
**Created:** [March 28, 2020, 10:16am UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339 "2020-03-28T10:16:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![robin](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/robin/32/911_2.png) [@robin](https://openvidu.discourse.group/u/robin)\
**Post date:** [March 28, 2020, 10:16am UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339/1 "2020-03-28T10:16:17Z")

</div>

![Screenshot 2020-03-28 at 3.58.17 PM](https://global.discourse-cdn.com/free1/uploads/openvidu/original/1X/ffca346a8e3f30a41aa786214e40fbe88d53816d.png)  
I close session using REST-API, Everything is fine in server side. But in the client side - `sessionDisconnected` event invoke multiple times!  
I like to mention, when i stream only camera it works fine(means sessionDisconnected event trigger only once). But if i share screen, sessionDisconnected event trigger two times for camera session!  
What can be possible reasons for this problems ?  
Thank’s

---

<div class="post-metadata">

**Author:** ![pabloFuente](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/pablofuente/32/2536_2.png) [@pabloFuente](https://openvidu.discourse.group/u/pabloFuente)\
**Post date:** [March 28, 2020, 11:57am UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339/2 "2020-03-28T11:57:32Z")

</div>

If you are publishing a camera and at the same time publishing a screen, then it is normal to have 2 sessionDisconnected events. There’s no official support for publishing multiple Publisher objects per connected user yet, so the “hack” to have multiple publishers in the same session is to actually have 2 different connections to the session. It’s like there are two users connected to the session, so you’ll receive 2 sessionDisconnected events.

---

<div class="post-metadata">

**Author:** ![robin](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/robin/32/911_2.png) [@robin](https://openvidu.discourse.group/u/robin)\
**Post date:** [March 28, 2020, 2:49pm UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339/3 "2020-03-28T14:49:09Z")

</div>

I create two separate session, cameraSession for publishing camera and screenSession for publishing screen. when i publish both camera + screen, sessionDisconnected for cameraSession invoke two times, and screenSession is disconnected with reason `network disconnected`.  
Is there any way to destroy or remove all instances related to a particular session manually from client side ?

---

<div class="post-metadata">

**Author:** ![robin](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/robin/32/911_2.png) [@robin](https://openvidu.discourse.group/u/robin)\
**Post date:** [March 29, 2020, 6:51am UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339/4 "2020-03-29T06:51:17Z")

</div>

![Screenshot 2020-03-29 at 12.37.40 PM](https://global.discourse-cdn.com/free1/uploads/openvidu/original/1X/5de56b18cfffdebbf2fa741d5ada0f4616df33f3.jpeg)  
Here is my frontend UI, i create two separate session - one for screen share & one for camera stream.  
Using `once` instead of `on` i solve the problem, twice invoke of `sessionDisconnected` event.

> ```
> this.cameraSession.once('sessionDisconnected', event => {
> //.....
> })
> 
> ```

But the problem is the error of `Websocket is already in closing state....`. And when i end stream, cameraSession disconnected properly with valid reason - `sessionClosedByServer`, but screenSession doesn’t.  
Here is the complete log when i click `End Stream` Button.

---

<div class="post-metadata">

**Author:** ![robin](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/robin/32/911_2.png) [@robin](https://openvidu.discourse.group/u/robin)\
**Post date:** [March 29, 2020, 6:52am UTC](https://openvidu.discourse.group/t/sessiondisconnected-event-invoke-multiple-times-what-can-be-reasons-for-this/339/5 "2020-03-29T06:52:13Z")

</div>

And here is the complete log when i click `End Stream`

 ![Screenshot 2020-03-29 at 12.39.39 PM](https://global.discourse-cdn.com/free1/uploads/openvidu/original/1X/80277c395ed98ccf8b32129c2359efdc2951fd17.png)
