summaryrefslogtreecommitdiff
path: root/ext/js/media/audio-system.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-04-10 23:55:11 -0400
committerGitHub <noreply@github.com>2021-04-10 23:55:11 -0400
commit20d60a2ba79c065586805806ea703a8057839f75 (patch)
tree3043090e118e03a8e276d2a7f1557e525ac23239 /ext/js/media/audio-system.js
parentb23c4bff4bf319ea79eea0d025e21eb19e6dcd68 (diff)
Initial safari compatibility (#1609)
* Update environment info to return the 'safari' browser * Fix popup display on Safari * Update environment assignment * Add data-loading-stalled property when loading takes longer than expected * Add notification when loading has stalled * Allow getDictionaryInfo invocation on non-privileged contexts * Update _validatePrivilegedMessageSender * Don't listen to 'voiceschanged' event unless addEventListener is present Also expose an event
Diffstat (limited to 'ext/js/media/audio-system.js')
-rw-r--r--ext/js/media/audio-system.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/ext/js/media/audio-system.js b/ext/js/media/audio-system.js
index cf63511f..cc2bcfc0 100644
--- a/ext/js/media/audio-system.js
+++ b/ext/js/media/audio-system.js
@@ -19,18 +19,20 @@
* TextToSpeechAudio
*/
-class AudioSystem {
+class AudioSystem extends EventDispatcher {
constructor() {
+ super();
this._fallbackAudio = null;
}
prepare() {
// speechSynthesis.getVoices() will not be populated unless some API call is made.
- if (typeof speechSynthesis === 'undefined') { return; }
-
- const eventListeners = new EventListenerCollection();
- const onVoicesChanged = () => { eventListeners.removeAllEventListeners(); };
- eventListeners.addEventListener(speechSynthesis, 'voiceschanged', onVoicesChanged, false);
+ if (
+ typeof speechSynthesis !== 'undefined' &&
+ typeof speechSynthesis.addEventListener === 'function'
+ ) {
+ speechSynthesis.addEventListener('voiceschanged', this._onVoicesChanged.bind(this), false);
+ }
}
getFallbackAudio() {
@@ -64,6 +66,10 @@ class AudioSystem {
// Private
+ _onVoicesChanged(e) {
+ this.trigger('voiceschanged', e);
+ }
+
_isAudioValid(audio, source) {
switch (source) {
case 'jpod101':