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
| Parameter | Type | Default | Description |
|---|---|---|---|
debug | boolean | required | true 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
debugin the configuration, the same option you can pass to the constructor.getConfigshows the new value. - Logs from the constructor (the initial configuration, spatial audio setup) only appear if you pass
debug: trueto the constructor. By the time you can callsetDebugModethey 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
SoundHubConfig: thedebugoption for the constructor.getLastError: the last error the hub caught.getConfig: read the current configuration.