Cannot get number of participants

I am using the i-frame API and it works really well with great audio/video.
But in jitsi meet I cannot get the number in the room.
Here is my code:-
const numberOfParticipants = api.getNumberOfParticipants();
console.log("Members joined " + numberOfParticipants);
This always outputs 0.
Thanks for any help.

@stevewright welcome to the forum!

Can you share more of your code?

It’s hard to know what exactly could be wrong without seeing a little more. Maybe include the instantiation of api and the domain and other options for starting your meeting. (Remove any servers for privacy of course)

Also you may want to read this for future posts.

Hi, Yes for sure. Here is the whole JS module.

let sender = ‘<?php echo $_SESSION["whNickName"]; ?>’;
const domain = ‘meet.jit.si’;
const options = {
roomName: ‘xxxxxxxxxxx’,
height: 650,
userInfo: {
displayName: sender
},
configOverwrite: {
startWithAudioMuted: true, // changes to jitsi config
startWithVideoMuted: true,
disableInviteFunctions: true
},
parentNode: document.querySelector(’#meet’)
};
const api = new JitsiMeetExternalAPI(domain, options);

let myVar = setInterval(myTimer, 3000);

function myTimer() {
const numberOfParticipants = api.getNumberOfParticipants();
console.log("Members joined " + numberOfParticipants);
}

Thanks for any help.

I ran your code and every 3 seconds I see Members joined 1 - The only thing I can think of is your api variable is not defined in the right scope…

Try this:

...
let myVar = setInterval(function(){myTimer(api)}, 3000);

function myTimer(_api) 
{
  const numberOfParticipants = _api.getNumberOfParticipants();
  console.log("Members joined " + numberOfParticipants);
}
...

Hey thanks for the reply. I tried that and just got the same 0 every time.
Did you test using the meet.jit.si domain or your own domain?
I am wondering if its disabled on meet.jit.si?
Thanks for the help!

@stevewright
I just checked and participant count is working on meet.jit.si

instead of writting new function first, you can write “window.api = api” and do things from console to become more interactive.

** plot twist : you just wrote “const numberOfParticipants = …” , which means once 1/first member joined it will be 1 forever, just use var/let :shushing_face:

here is the full html file I wrote for the js , you can just copy+paste:

<html>
    <title>

    </title>
    <body>
        <div id="meet">

        </div>
    </body>
</html>
<script src='https://meet.jit.si/external_api.js'></script>
<script>
    const domain = 'meet.jit.si';
    const options = {
        roomName: 'sadroom',
        height: 650,
        userInfo: {
            displayName: 'sender'
        },
        configOverwrite: {
            startWithAudioMuted: true, // changes to jitsi config
            startWithVideoMuted: true,
            disableInviteFunctions: true
        },
        parentNode: document.querySelector('#meet'),
    };
    const api = new JitsiMeetExternalAPI(domain, options);
    window.api = api;

    function myTimer() {
    let numberOfParticipants = api.getNumberOfParticipants();
    console.log("Members joined " + numberOfParticipants);
    }

    let myVar = setInterval(myTimer, 3000);
</script>
1 Like

@stevewright Yes I tested exactly as you wrote it with the changes that I included in my response. It’s working on meet.jit.si

@Fuji const should be fine in this case because the scope is local to myTimer

Hey guys thanks for all the help but I have fixed it!
The problem was caused by me having the characters # and ^ in my room name.
No idea why this should be a problem but removing those 2 chars from my room names makes the number of participants read correctly.
Many thanks for all the help!

I don’t think this works. It always show 0 (unless actually joined the room). The number changes after joined room though.

1 Like