Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utilities/HiFiUtilities

This Module contains a number of useful utility functions that API users can use in their applications if they wish. Some of them are also used internally in API code.

Index

Functions

getBestAudioConstraints

  • getBestAudioConstraints(): any
  • Returns any

    The "best" audio constraints supported by the client. In this case, "best" is defined as "the constraints that will produce the highest-quality audio." That means disabling Echo Cancellation, disabling Noise Suppression, and disabling Automatic Gain Control.

preciseInterval

  • preciseInterval(callback: Function, intervalMS: number): any
  • preciseInterval() is a version of setInterval() for NodeJS that does not spin CPUs nor drift. The returned value is an object with a clear() methods that stops the interval. In the browser context, preciseInterval() is simply a wrapper for setInterval().

    We do three things:

    1. Keep a running counter of when the next call should be, to avoid drift.
    2. Compute the time to the next call and give that to setTimeout().
    3. Our average error with the above is about 1ms (so half the intervals are off by more). So in #2, shoot for 2 ms less than that, and spin with setImmediate (allowing other stuff to run) until we've reached the expected time.

    For a 10ms interval, we measured an average error per interval of:

    • 1.67 ms for setInterval() (so SOMETHING is ticking at 60 Hz).
    • ~1 ms for this code WITHOUT #3, using Date.getTime()
    • ~1 ms for this code WITHOUT #3, using perf_hooks.performance.now()
    • 0.86 ms for this code using Date.getTime()
    • 0.03 ms for this code using perf_hooks.performance.now()

    Parameters

    • callback: Function

      The function to call when the precise interval expires.

    • intervalMS: number

      The number of milliseconds to wait between each interval.

    Returns any

recursivelyDiffObjects

  • recursivelyDiffObjects(obj1: any, obj2: any): any
  • Returns a JS Object containing the differences between the two passed objects.

    This function was adapted from this very helpful document on GoMakeThings. The original function is licensed under the MIT license.

    Parameters

    • obj1: any
    • obj2: any

    Returns any