Make the speaker retain its last spoken message
This commit is contained in:
parent
5036259d75
commit
8161b80081
1 changed files with 5 additions and 1 deletions
|
@ -2,16 +2,20 @@ class Speaker {
|
||||||
#callbacks = new Set()
|
#callbacks = new Set()
|
||||||
#immediate
|
#immediate
|
||||||
#scheduled = []
|
#scheduled = []
|
||||||
|
#current
|
||||||
|
|
||||||
constructor(immediate) {
|
constructor(immediate, current=[]) {
|
||||||
this.#immediate = immediate
|
this.#immediate = immediate
|
||||||
|
this.#current = current
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(callback) {
|
listen(callback) {
|
||||||
this.#callbacks.add(callback)
|
this.#callbacks.add(callback)
|
||||||
|
return this.#current
|
||||||
}
|
}
|
||||||
|
|
||||||
speak(...args) {
|
speak(...args) {
|
||||||
|
this.#current = args
|
||||||
if (this.#immediate) {
|
if (this.#immediate) {
|
||||||
for (let callback of this.#callbacks) {
|
for (let callback of this.#callbacks) {
|
||||||
callback(...args)
|
callback(...args)
|
||||||
|
|
Loading…
Reference in a new issue