MDL-83243 mod_scorm: Redirect user when network is unstable

When a user is on a SCORM player page and has a persistently
unstable network connection, their Moodle session can expire
and/or the SCORM package can fail to save their progress.
This change will force the user to exit the SCORM player page
to avoid losing unsaved progress.
This commit is contained in:
Sam Smucker
2026-03-03 11:46:00 -06:00
parent 51c7facb42
commit 7686b11731
3 changed files with 76 additions and 3 deletions
+4 -2
View File
@@ -263,6 +263,7 @@ $string['lastattempt'] = 'Last completed attempt';
$string['lastattemptlock'] = 'Lock after final attempt';
$string['lastattemptlock_help'] = 'If enabled, a student is prevented from launching the SCORM player after using up all their allocated attempts.';
$string['lastattemptlockdesc'] = 'If enabled, a student is prevented from launching the SCORM player after using up all their allocated attempts.';
$string['leavepage'] = 'Leave page';
$string['location'] = 'Show the location bar';
$string['max'] = 'Max score';
$string['maximumattempts'] = 'Number of attempts';
@@ -299,8 +300,8 @@ There are 3 options:
$string['navdesc'] = 'This setting specifies whether to show or hide navigation buttons and their position.';
$string['navpositionleft'] = 'Position of navigation buttons from left in pixels.';
$string['navpositiontop'] = 'Position of navigation buttons from top in pixels.';
$string['networkdropped'] = 'The SCORM player has determined that your Internet connection is unreliable or has been interrupted. If you continue in this SCORM activity, your progress may not be saved.<br />
You should exit the activity now, and return when you have a dependable Internet connection.';
$string['networkdropped'] = 'It looks like you have an unstable internet connection or your session has timed out. Your progress may not be saved. Please exit and relaunch this activity.';
$string['networkdroppedmobile'] = 'It looks like you have an unstable internet connection or your session has timed out. Your progress may not be saved. Please exit and relaunch this activity. You may wish to return to this activity in the mobile app for a more stable connection.';
$string['newattempt'] = 'Start a new attempt';
$string['next'] = 'Continue';
$string['noactivity'] = 'Nothing to report';
@@ -439,6 +440,7 @@ $string['typeexternal'] = 'External SCORM manifest';
$string['typelocal'] = 'Uploaded package';
$string['typelocalsync'] = 'Downloaded package';
$string['undercontent'] = 'Under content';
$string['unstablenetwork'] = 'Unstable network';
$string['unziperror'] = 'An error occurs during package unzip';
$string['updatefreq'] = 'Auto-update frequency';
$string['updatefreq_error'] = 'Auto-update frequency can only be set when the package file is hosted externally';
+3 -1
View File
@@ -309,7 +309,9 @@ if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.php'))
}
// Add the keepalive system to keep checking for a connection.
\core\session\manager::keepalive('networkdropped', 'mod_scorm', 30, 10);
$redirecturl = new moodle_url('/mod/scorm/view.php', ['id' => $cm->id]);
$stringname = get_config('core', 'enablemobilewebservice') ? 'networkdroppedmobile' : 'networkdropped';
\core\session\manager::keepalive($stringname, 'mod_scorm', 30, 10, $redirecturl);
echo $OUTPUT->footer();
@@ -0,0 +1,69 @@
@mod @mod_scorm
Feature: Unstable network
In order to avoid losing progress in a SCORM package
As a learner
I need to be notified if my network is unstable
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | name | popup |
| scorm | C1 | Same window SCORM | 0 |
| scorm | C1 | New window SCORM | 1 |
@javascript
Scenario: The unstable network modal renders on the SCORM player page when network is unstable
When I am on the "Same window SCORM" "scorm activity" page logged in as "student1"
And I press "Enter"
And my network is unstable
Then I should see "It looks like you have an unstable internet connection or your session has timed out"
And I should see "Cancel" in the "Unstable network" "dialogue"
@javascript
Scenario: The unstable network modal can be closed without a redirect the first time it is shown
When I am on the "Same window SCORM" "scorm activity" page logged in as "student1"
And I press "Enter"
And my network is unstable
And I click on "Cancel" "button" in the "Unstable network" "dialogue"
Then I should not see "It looks like you have an unstable internet connection or your session has timed out"
And I should not see "Enter"
@javascript
Scenario: The unstable network modal cannot be closed without a redirect the second time it is shown
When I am on the "Same window SCORM" "scorm activity" page logged in as "student1"
And I press "Enter"
And my network is unstable
And my network is unstable
Then I should not see "Cancel" in the "Unstable network" "dialogue"
And I click on "Leave page" "button" in the "Unstable network" "dialogue"
And I should see "Enter"
@javascript
Scenario: Unstable network must be detected twice consecutively before a user must leave the SCORM activity
When I am on the "Same window SCORM" "scorm activity" page logged in as "student1"
And I press "Enter"
And my network is unstable
And I click on "Cancel" "button" in the "Unstable network" "dialogue"
And the session is touched
And my network is unstable
Then I should see "Cancel" in the "Unstable network" "dialogue"
And my network is unstable
And I should not see "Cancel" in the "Unstable network" "dialogue"
@javascript @_switch_window
Scenario: Unstable network modal redirects correctly when SCORM opens in new window
When I am on the "New window SCORM" "scorm activity" page logged in as "student1"
And I press "Enter"
And I switch to a second window
And my network is unstable
And I click on "Leave page" "button" in the "Unstable network" "dialogue"
Then I should see "Enter"
And I should see "New window SCORM"