MOBILE-4420 scorm: Unload current SCO before loading next one

main
Dani Palou 2023-09-26 13:55:21 +02:00
parent cbfc866af4
commit 1f05729cb0
3 changed files with 12 additions and 26 deletions

View File

@ -21,8 +21,8 @@
</ion-header> </ion-header>
<ion-content> <ion-content>
<core-loading [hideUntil]="loaded"> <core-loading [hideUntil]="loaded">
<core-iframe *ngIf="loaded && src" [src]="src" [iframeWidth]="scormWidth" [iframeHeight]="scormHeight" <core-iframe *ngIf="loaded" [src]="src" [iframeWidth]="scormWidth" [iframeHeight]="scormHeight" [showFullscreenOnToolbar]="true"
[showFullscreenOnToolbar]="true" [autoFullscreenOnRotate]="true"> [autoFullscreenOnRotate]="true">
</core-iframe> </core-iframe>
<p *ngIf="!src && errorMessage">{{ errorMessage | translate }}</p> <p *ngIf="!src && errorMessage">{{ errorMessage | translate }}</p>

View File

@ -426,6 +426,11 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
(<any> window).API = this.dataModel; (<any> window).API = this.dataModel;
} else { } else {
// Changing SCO. First unload the existing SCO to make sure the callback to send the data has been called.
this.src = '';
await CoreUtils.nextTick();
// Load the SCO in the existing model. // Load the SCO in the existing model.
this.dataModel.loadSco(sco.id); this.dataModel.loadSco(sco.id);
} }
@ -436,7 +441,7 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
this.calculateNavigationItems(sco.id); this.calculateNavigationItems(sco.id);
// Load the SCO source. // Load the SCO source.
this.loadScoSrc(sco); this.src = await AddonModScorm.getScoSrc(this.scorm, sco);
if (sco.scormtype == 'asset') { if (sco.scormtype == 'asset') {
// Mark the asset as completed. // Mark the asset as completed.
@ -446,25 +451,6 @@ export class AddonModScormPlayerPage implements OnInit, OnDestroy {
this.logEvent(sco.id); this.logEvent(sco.id);
} }
/**
* Load SCO src.
*
* @param sco SCO to load.
* @returns Promise resolved when done.
*/
protected async loadScoSrc(sco: AddonModScormScoWithData): Promise<void> {
const src = await AddonModScorm.getScoSrc(this.scorm, sco);
if (src == this.src) {
// Re-loading same page. Set it to empty and then re-set the src in the next digest so it detects it has changed.
this.src = '';
await CoreUtils.nextTick();
}
this.src = src;
}
/** /**
* Given an SCO, mark it as completed. * Given an SCO, mark it as completed.
* *

View File

@ -160,10 +160,10 @@ export class CoreIframeComponent implements OnChanges, OnDestroy {
return; return;
} }
let url = changes.src.currentValue; let url = this.src;
if (!CoreUrlUtils.isLocalFileUrl(url)) { if (url && !CoreUrlUtils.isLocalFileUrl(url)) {
url = CoreUrlUtils.getYoutubeEmbedUrl(changes.src.currentValue) || changes.src.currentValue; url = CoreUrlUtils.getYoutubeEmbedUrl(url) || url;
this.displayHelp = CoreIframeUtils.shouldDisplayHelpForUrl(url); this.displayHelp = CoreIframeUtils.shouldDisplayHelpForUrl(url);
const currentSite = CoreSites.getCurrentSite(); const currentSite = CoreSites.getCurrentSite();
@ -181,7 +181,7 @@ export class CoreIframeComponent implements OnChanges, OnDestroy {
await CoreIframeUtils.fixIframeCookies(url); await CoreIframeUtils.fixIframeCookies(url);
} }
this.safeUrl = DomSanitizer.bypassSecurityTrustResourceUrl(CoreFile.convertFileSrc(url)); this.safeUrl = DomSanitizer.bypassSecurityTrustResourceUrl(url ? CoreFile.convertFileSrc(url) : '');
// Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM. // Now that the URL has been set, initialize the iframe. Wait for the iframe to the added to the DOM.
setTimeout(() => { setTimeout(() => {