# Publisher Connection status

**URL:** <https://openvidu.discourse.group/t/publisher-connection-status/3455>\
**Category:** How to implement?\
**Tags:** v2\
**Created:** [October 4, 2021, 10:18am UTC](https://openvidu.discourse.group/t/publisher-connection-status/3455 "2021-10-04T10:18:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruben](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/ruben/32/396_2.png) [@Ruben](https://openvidu.discourse.group/u/Ruben)\
**Post date:** [October 4, 2021, 10:18am UTC](https://openvidu.discourse.group/t/publisher-connection-status/3455/1 "2021-10-04T10:18:00Z")

</div>

Hi guys,  
is there a way to know when the publisher is connected via webrtc on web browser?  
A listener on switching connection events would be useful.  
I tried with:  
**publisher.stream.getRTCPeerConnection().oniceconnectionstatechange = …**  
but the openvidu SDK no longer works because I assume you use that method too.

Thanks

---

<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:** [October 4, 2021, 11:54am UTC](https://openvidu.discourse.group/t/publisher-connection-status/3455/2 "2021-10-04T11:54:45Z")

</div>

OpenVidu Browser SDK does not use this version of “adding listeners methods”. Web API provides 2 ways of adding listeners:

- Methods addEventListener(_ **EVENT** _): you can add as many listeners to the same event as you want. There will be no overwrite of pre-existing listeners.
- Methods on_ **EVENT** _: only one listener can be added. Will overwrite other listeners.

I think this StackOverflow anwer explains this concept very clearly with the “click” event: [javascript - addEventListener vs onclick - Stack Overflow](https://stackoverflow.com/a/6348533)

As a general rule it is now discourage to use the `on...` method version, as you could be getting unwanted side effects as you have come across. That being said, openvidu-browser library shouldn’t be broken after you add that listener, because as I have already stated, there is no `oniceconnectionstatechange` call in all of OpenVidu repository. So yours should be the only call to that method in your application. You can check it by yourself with this GitHub search: [Search · oniceconnectionstatechange · GitHub](https://github.com/OpenVidu/openvidu/search?q=oniceconnectionstatechange)

---

<div class="post-metadata">

**Author:** ![Ruben](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/ruben/32/396_2.png) [@Ruben](https://openvidu.discourse.group/u/Ruben)\
**Post date:** [October 7, 2021, 8:55am UTC](https://openvidu.discourse.group/t/publisher-connection-status/3455/3 "2021-10-07T08:55:51Z")

</div>

Ok thank you. I will try **addEventListener** and and I’ll let you know

---

<div class="post-metadata">

**Author:** ![Ruben](https://yyz2.discourse-cdn.com/free1/user_avatar/openvidu.discourse.group/ruben/32/396_2.png) [@Ruben](https://openvidu.discourse.group/u/Ruben)\
**Post date:** [October 13, 2021, 2:26pm UTC](https://openvidu.discourse.group/t/publisher-connection-status/3455/4 "2021-10-13T14:26:33Z")

</div>

I have tested this solution but is not working.  
If I comment the **addEventListener** method there is no error, otherwise the publisher goes into **accessDenied** error and I don’t know why.

```
publisher.once('accessAllowed', (event) => {
    session.publish(publisher);
    publisher.stream.getRTCPeerConnection().addEventListener("oniceconnectionstatechange", (ev) => {}); 
});

publisher.once('accessDenied', (event) => {
    console.warn('Publisher: Access Denied');
});
```
