Skip to main content

setDebugMode

Turn debug logging on or off. With debug on, the hub logs what it is doing to the console, each line prefixed with [SoundHub]. Handy while you work out why a sound does not play.

setDebugMode(debug: boolean): void;

Parameters​

ParameterTypeDefaultDescription
debugbooleanrequiredtrue to log, false to stop.

Returns​

Nothing.

Example​

import { SoundHub } from 'soundhub';

const soundHub = new SoundHub();

if (location.hostname === 'localhost') {
soundHub.setDebugMode(true);
}

await soundHub.loadSound('click', '/audio/click.mp3');
soundHub.play('click'); // logs what play() does

Good to know​

  • It sets debug in the configuration, the same option you can pass to the constructor. getConfig shows the new value.
  • Logs from the constructor (the initial configuration, spatial audio setup) only appear if you pass debug: true to the constructor. By the time you can call setDebugMode they have already run.
  • Errors are always logged with console.error, debug or not. With debug on, the line also includes the original error object.
  • The version banner the hub prints when it is created is not affected.
  • No event is dispatched.

See also​