summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 21:44:51 -0500
committerGitHub <noreply@github.com>2020-03-07 21:44:51 -0500
commitd022d61b1a66614e1837585afcb53a25253b643a (patch)
tree40659359b076fed2ad57980f88e26d2ff95a12c5 /ext/bg/js/backend.js
parentb8eb5e6016834cc751c973239e1e4604fe9799ee (diff)
parentdceaa853098a465b2eaa1b90900b5c1832131f26 (diff)
Merge pull request #399 from toasted-nutbread/audio-system-refactor
Audio system refactor
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js16
1 files changed, 14 insertions, 2 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index 04bf240d..60a87916 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -23,7 +23,7 @@ requestText, requestJson, optionsLoad
dictConfigured, dictTermsSort, dictEnabledSet, dictNoteFormat
audioGetUrl, audioInject
jpConvertReading, jpDistributeFuriganaInflected, jpKatakanaToHiragana
-Translator, AnkiConnect, AnkiNull, Mecab, BackendApiForwarder, JsonSchema, ClipboardMonitor*/
+AudioSystem, Translator, AnkiConnect, AnkiNull, Mecab, BackendApiForwarder, JsonSchema, ClipboardMonitor*/
class Backend {
constructor() {
@@ -34,6 +34,7 @@ class Backend {
this.options = null;
this.optionsSchema = null;
this.defaultAnkiFieldTemplates = null;
+ this.audioSystem = new AudioSystem({getAudioUri: this._getAudioUri.bind(this)});
this.optionsContext = {
depth: 0,
url: window.location.href
@@ -436,7 +437,8 @@ class Backend {
definition,
options.anki.terms.fields,
options.audio.sources,
- optionsContext
+ optionsContext,
+ this.audioSystem
);
}
@@ -762,6 +764,16 @@ class Backend {
// Utilities
+ async _getAudioUri(definition, source, details) {
+ let optionsContext = (typeof details === 'object' && details !== null ? details.optionsContext : null);
+ if (!(typeof optionsContext === 'object' && optionsContext !== null)) {
+ optionsContext = this.optionsContext;
+ }
+
+ const options = this.getOptions(optionsContext);
+ return await audioGetUrl(definition, source, options);
+ }
+
async _injectScreenshot(definition, fields, screenshot) {
let usesScreenshot = false;
for (const fieldValue of Object.values(fields)) {