0

I'm just trying to wrap my head around an event listener in Jitsi Meet API, I haven't run across something like this and I'm sure its the same concept in alot of api's - I'm not sure on approach.

Basically in the jitsi meet api you can use api.addEventListener(audioMuteStatusChanged, listener); to set up an event listener if mute is toggled. Basically, true if muted, false if not. I'm trying to get a value of if it to see when it's muted, or when it isn't muted.

It says "The listener parameter is a Function object with one argument that will be notified when the event occurs with data related to the event."

So how do I get the true false value when something is changed?

const result = api.addEventListener(audioMuteStatusChanged, return isitmuted);

Edit: Tried it with:

 if (audioChatApi) {
  audioChatApi.addEventListener(audioMuteStatusChanged, function(listener) {
   if (listener){
     console.log("True " + listener);
   } else {
     console.log("False");
   };
 });
 };

and didn't solve it, I think the event isn't for this task

JronCh
  • 163
  • 1
  • 3
  • 11
  • How is that even related @deceze – JronCh Aug 10 '18 at 08:37
  • It very much is. I've added a bunch of duplicates about callbacks. Read them to get familiar with the concept. – deceze Aug 10 '18 at 08:39
  • 1
    @RobStark — You're trying to put a `return` statement somewhere that a function is expected. You need to put a function there and you can't return from it (at least not to `result`). – Quentin Aug 10 '18 at 08:39
  • It's the same principle, you can't. You have to trigger whatever has to happen to the true/false value inside the event handler. – Shilly Aug 10 '18 at 08:40
  • 1
    In a simple nutshell: the *event* `audioMuteStatusChanged` will happen ***sometime later***, possibly multiple times, unpredictably. It makes no sense to want to return anything from it. No, you need to bind a `function` to that event so you can *do* something when that event happens. You don't `return` anything then, you *do* something then. – deceze Aug 10 '18 at 08:47
  • *"and didn't solve it, I think the event isn't for this task"* – What does that mean? What did it do, what didn't it do, what did you want it to do? – deceze Aug 10 '18 at 09:05
  • @deceze I tried to console.log it (made an edit above) and it wouldn't do anything - I'm guessing the eventlistener is not for this purpose. This is logged by default by jitsy whenever I mute the chat, it shows: [modules/API/API.js] : Audio toggle: API command received Logger.js:125 [modules/RTC/JitsiLocalTrack.js] : Mute LocalTrack[1,audio]: true Which would flip true and false accordingly, i thought this would be able to grab that true false value somehow – JronCh Aug 10 '18 at 09:07
  • It probably should. Though what is `audioMuteStatusChanged` exactly? It should be the name of an event, not a variable (unless that variable holds the name of the event, but that's odd). It should be something like `audioChatApi.addEventListener('audioMuteStatusChanged', function ...)`. – deceze Aug 10 '18 at 09:14
  • @deceze according to https://github.com/jitsi/jitsi-meet/blob/master/doc/api.md it says "audioMuteStatusChanged - event notifications about audio mute status changes." I just got it working by using something else on same list, api.isAudioMuted().then(function(muted) { – JronCh Aug 10 '18 at 09:19

1 Answers1

0

Wouldn't it be something like the following?

const result = api.addEventListener(audioMuteStatusChanged, function(isMuted) {
  if (isMuted){
    //some code here
  } else {
    //some code here
  }
});
andriusain
  • 1,211
  • 10
  • 18
  • I tried it with: if (audioChatApi) { audioChatApi.addEventListener(audioMuteStatusChanged, function(listener) { if (listener){ console.log("True " + listener); } else { console.log("False"); }; }); }; and looks like the event is just not for this job – JronCh Aug 10 '18 at 09:00