Publisher Connection status

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: = …
but the openvidu SDK no longer works because I assume you use that method too.


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 onEVENT: 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

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

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

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);"oniceconnectionstatechange", (ev) => {}); 

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