cap:switchable-audio-feedback
- enable or disable audio feedback¶
The switchable-audio-feedback
-capability is an extension to the
audio-feedback-capability for things that can also
switch the audio feedback on or off.
if(thing.matches('cap:switchable-audio-feedback')) {
console.log('Feedback is on', await thing.audioFeedback());
// Disable the audio feedback
await thing.audioFeedback(false);
}
API¶
-
audioFeedback
([enabled])¶ Get or set if the audio feedback is enabled.
Arguments: - enabled (boolean) – Optional boolean to change audio feedback to.
Returns: Promise that resolves to the current audio feedback state.
Example:
// Getting returns a boolean const noisy = await thing.audioFeedback(); // Turn audio feedback on thing.audioFeedback(true) .then(on => ...) .catch(...);
-
setAudioFeedback
(enabled)¶ Set if audio feedback is enabled.
Arguments: - enabled (boolean) – The new audio feedback state as a boolean.
Returns: Promise that resolves to the new audio feedback state.
Example:
thing.setAudioFeedback(true) .then(on => ...) .catch(...);
-
toggleAudioFeedback
()¶ Toggle if audio feedback is enabled.
Returns: Promise that resolves to the new audio feedback state. Example:
thing.toggleAudioFeedback() .then(on => ...) .catch(...);
Implementing capability¶
The switchable-audio-feedback
-capability requires that the function
changeAudioFeedback
is implemented.
Example:
const { Thing, SwitchableAudioFeedback } = require('abstract-things');
class Example extends Thing.with(SwitchableAudioFeedback) {
constructor() {
super();
// Make sure to initialize the state via updateAudioFeedback
}
changeAudioFeedback(enabled) {
/*
* This method is called whenever a audio feedback change is requested.
*/
return switchWithPromise(enabled)
.then(() => this.updateAudioFeedback(enabled));
}
}