useAudioLevel CPU optimization priority

Options
oponder
oponder Member

Hi I found this thread looking for some info on the CPU usage of the useAudioLevel hook because I noticed it had quite an impact on my app, especially on mobile devices.

Christian mentioned that "It will eventually be replaced or migrated by a hook that incorporates the audio level observers, but it's currently not high on the priority list."

I was wondering if there is any indication of when it would be picked up.

I will probably refactor to use startRemoteParticipantsAudioLevelObserver and startLocalAudioLevelObserver

Best Answer

  • christian
    christian Dailynista
    Answer ✓
    Options

    Hey @oponder,

    technically the new useAudioLevelObserver hook will mostly be an abstraction around this code:

    useDailyEvent(
      'remote-participants-audio-level',
      useCallback((ev) ⇒ {
        if (sessionId in ev.participantsAudioLevel) {
          // onVolumeChange prop similar to as in useAudioLevel
          onVolumeChange(ev.participantsAudioLevel[sessionId]);
        }
      }, [onVolumeChange, sessionId])
    );
    

    You can totally build this yourself already as all required bits and pieces are available. The hook will just reduce your own code a bit and remove some complexity around local vs. remote audio levels.

    Hope this points you into the right direction!

Answers

  • oponder
    Options

    Thanks, this was very helpful and I implemented it already. Seems to be working smoothly 👍🙌