cybercussion / SCOBot

SCORM API for Content. JavaScript library, QUnit tests and examples.
https://cybercussion.com
156 stars 34 forks source link

happyEnding not working when closing SCO via browser exit button #4

Closed drakni closed 8 years ago

drakni commented 8 years ago

Hi,

We're experiencing a problem with the completion status when leaving an SCO. Our SCO is made of a web page where we add an exit button. When we use this button to leave the course, the "happy ending" is well sent to the LMS (with success as "passed", status as "completed" and score as "100%"), but if we leave the course by closing the window, only the "passed" is correctly returned, while the status is set as "incomplete" and score as "unknown".

Here is the custom integration we're using:

<script type="text/javascript">
    var scorm = new SCOBotBase({
        debug: true,
        exit_type: 'finish',
        success_status: 'passed',
        completion_status: 'completed'
    });
    var SB = new SCOBot({
        happyEnding: true,
        initiate_timer: false,
        scorm_strict: true,
        base64: false,
        useJSONSuspendData: false,
        doNotStatusUntilFinish: false,
        sequencing: {
            nav: {
                request: 'exitAll'
            }
        }
    });

    SCOBotUtil.addEvent(SB, 'load', function(e) {
        player = new SCOPlayer();
        SB.happyEnding();
        SB.commit();
        return false;
    });

    SCOBotUtil.addEvent(SB, 'unload', function(e) {
        player.exit();
        scorm.setvalue('adl.nav.request', 'exitAll');
        SB.happyEnding();
        SB.finish();
        return false;
    });

    (function () {
        var doneBtns = document.getElementsByClassName('lms-finish'),
            printBtns = document.getElementsByClassName('do-print');

        var i;
        for (i in doneBtns) {
            doneBtns[i].onclick = function () {
                scorm.setvalue('adl.nav.request', 'exitAll');
                SB.happyEnding();
                SB.finish();
            };
        }

        for (i in printBtns) {
            printBtns[i].onclick = function () {
                window.print();
            };
        }
    })();
</script>

We've set the nav.request value to exitAll because we have only one SCO per course, and using any other value caused some LMS to relaunch the same SCO when close it via the custom exit button.

I've tried forcing the datas to be commited on launch, but it does not seem to work either.

Any idea of what could be wrong here?

Thanks for your help!

cybercussion commented 8 years ago

Hi, Apologies, I didn't catch a notification from github that this was opened. Reading through your code, it looks like we need to take a closer look at the 'unload' event stack. Although, I do see happyEnding is set and committed on the 'load' function. This would imply something else is interfering on exit.

player.exit(); isn't known in the code here, so I'm not sure what its doing, but knowing what SCOBot does I'll itemize here to hopefully help you isolate.

'unload' event gets triggered and SCOBot internally will call exitSCO(). You'll see a trace like "SCO is being unloaded, forcing exit...". After that, you should see a completion and success status trace. If the connection is active, it will internally trigger the 'unload' event your listening to above. This means -

  1. Your player.exit() is called
  2. SB.happyEnding();
  3. SB.finish(); Then, SCOBot will look at your default exit type can call finish based on your settings. Worst case, this is just doubling up calls, but shouldn't trigger any scoring/status changes.

Exit issues are hard to trace down unless you can persist the console tracing. You could also try the bookmarklet - https://www.cybercussion.com/bookmarklets/SCORM/. This would monitor the LMS API while you interact with it.

General Button behavior tip:

I've seen cases where a button click needs to return false, or it changes the DOM and causes a refresh of your whole SCO due to placing a '#" in the URL (http://stackoverflow.com/questions/1878264/how-do-i-make-an-html-button-not-reload-the-page). This would essentially reload the page and re-initialize SCOBot as the browser is exiting. Since exit type is 'finish' the LMS behavior is to start a new attempt which could be erasing your prior attempt with the proper status/scoring. In SCORM 2004 a 'cmi.exit' of normal will end the attempt.

I suspect this may be why your having to do the exitAll call to force the LMS to stop your SCO from reloading.

drakni commented 8 years ago

Hey,

We did further investigations, and it seems SB.happyEnding(); isn't working for us. We solved our problem by replacing this call with cmi.complete_status, cmi.success_status, etc. on the exit button click event, as we just needed to set a complete status when a user launches a course:

We added a self.close() function to force the window to shut down in some cases.

cybercussion commented 8 years ago

Hi, Ok, I did a quick test with https://dl.dropboxusercontent.com/u/3459294/HPPYENDTST-2004-4th-Edition.zip on cloud.scorm.com, and things seemed to work ok. But, at least you found a workaround for your situation.

With a SB.finish call it will actually set the 'adl.nav.request' for you if it doesn't equal 'none' by default too; since you have set that up in the default parameters instantiating SCOBot.