summaryrefslogtreecommitdiff
path: root/ext/bg/js/backend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 14:10:43 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-03-07 21:43:51 -0500
commita8eb50d96f50ae20033ccc05094caaedbae81936 (patch)
tree21e603c0a8986301dab7d3ad0522153de232ed0a /ext/bg/js/backend.js
parent75eac153d625c54892a6f7194d0cfa4160ffe722 (diff)
Use dependency injection for getAudioUri implementation
Diffstat (limited to 'ext/bg/js/backend.js')
-rw-r--r--ext/bg/js/backend.js12
1 files changed, 11 insertions, 1 deletions
diff --git a/ext/bg/js/backend.js b/ext/bg/js/backend.js
index abf4c673..60a87916 100644
--- a/ext/bg/js/backend.js
+++ b/ext/bg/js/backend.js
@@ -34,7 +34,7 @@ class Backend {
this.options = null;
this.optionsSchema = null;
this.defaultAnkiFieldTemplates = null;
- this.audioSystem = new AudioSystem();
+ this.audioSystem = new AudioSystem({getAudioUri: this._getAudioUri.bind(this)});
this.optionsContext = {
depth: 0,
url: window.location.href
@@ -764,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)) {