From 7686b11731ca02cf2caefa08db44e512c72c3067 Mon Sep 17 00:00:00 2001 From: Sam Smucker Date: Tue, 3 Mar 2026 11:46:00 -0600 Subject: [PATCH] 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. --- public/mod/scorm/lang/en/scorm.php | 6 +- public/mod/scorm/player.php | 4 +- .../tests/behat/unstable_network.feature | 69 +++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 public/mod/scorm/tests/behat/unstable_network.feature diff --git a/public/mod/scorm/lang/en/scorm.php b/public/mod/scorm/lang/en/scorm.php index d97ef9d00a6..7ff6019e12a 100644 --- a/public/mod/scorm/lang/en/scorm.php +++ b/public/mod/scorm/lang/en/scorm.php @@ -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.
-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'; diff --git a/public/mod/scorm/player.php b/public/mod/scorm/player.php index 28b5fe66056..2f3e7f52eae 100644 --- a/public/mod/scorm/player.php +++ b/public/mod/scorm/player.php @@ -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(); diff --git a/public/mod/scorm/tests/behat/unstable_network.feature b/public/mod/scorm/tests/behat/unstable_network.feature new file mode 100644 index 00000000000..0e528683c6b --- /dev/null +++ b/public/mod/scorm/tests/behat/unstable_network.feature @@ -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"