diff --git a/js/XAPI.js b/js/XAPI.js index 137270e..1dd4bfa 100644 --- a/js/XAPI.js +++ b/js/XAPI.js @@ -253,13 +253,22 @@ class XAPI extends Backbone.Model { } async onLanguageChanged(newLanguage) { - // Update the language. + // Remove existing event listeners + this.removeEventListeners(); + + // Update the language this.set({ displayLang: newLanguage }); - // Since a language change counts as a new attempt, reset the state. + // Since a language change counts as a new attempt, reset the state await this.deleteState(); - // Send a statement to track the (new) course. - await this.sendStatement(this.getCourseStatement(window.ADL.verbs.launched)); + + // Re-add event listeners for the new language/session + this.setupListeners(); + + // Send a statement to track the (new) course + await this.sendStatement( + this.getCourseStatement(window.ADL.verbs.launched) + ); } /** @@ -452,6 +461,11 @@ class XAPI extends Backbone.Model { }); } + removeEventListeners() { + // Stop listening to all events + this.stopListening(); + } + /** * Gets an xAPI Activity (with an 'id of the activityId) representing the course. * @returns {window.ADL.XAPIStatement.Activity} Activity representing the course.