jcputney / scorm-again

A modern SCORM JavaScript runtime library.
https://jcputney.github.io/scorm-again/
MIT License
210 stars 50 forks source link

Bug when loading CMI data with learner_preferences, score #678

Open arashster opened 11 months ago

arashster commented 11 months ago

There seems to be a bug when loading the cmi data with existing data from the server.

                window.API_1484_11 = new Scorm2004API({
                    "autocommit" : false,
                    "lmsCommitUrl" : "/post/scorm",
                    "logLevel" : 1
                });

                var cmi_data = {        
                         "comments_from_learner": {},
                                          "comments_from_lms": {},
                                          "completion_status": "incomplete",
                                          "completion_threshold": "",
                                          "credit": "credit",
                                          "entry": "resume",
                                          "exit": "suspend",
                                          "interactions": {},
                                          "launch_data": "",
                                          "learner_id": "Test",
                                          "learner_name": "User,Sample",
                                          "learner_preference": {
                                              "audio_level": "1",
                                              "language": "",
                                              "delivery_speed": "1",
                                              "audio_captioning": "0"
                                          },
                                          "location": "1",
                                          "max_time_allowed": "",
                                          "mode": "normal",
                                          "objectives": {},
                                          "progress_measure": "",
                                          "scaled_passing_score": "",
                                          "score": {
                                              "scaled": "",
                                              "raw": "",
                                              "min": "",
                                              "max": ""
                                          },
                                          "session_time": "PT19.57S",
                                          "success_status": "unknown",
                                          "suspend_data": "",
                                          "time_limit_action": "continue,no message",
                                          "total_time": "PT19.57S"
                             };

                             window.API_1484_11.loadFromJSON(cmi_data);
                             ...
                             //later the SCORM package calls API_14841_11.Initialize("");

At this point, an exception is thrown:

_this$learner_prefere.initialize is not a function

Looking at scorm-again.js, it looks like the code tries to call _this$learner_prefere.initialize() but _this$learner_prefere is an undefined object.

I believe what is happening is that since learner_preferences are included in the CMI object, it for some reason tries to call initialize().

Are we not suppose to load back in the cmi_data with learner_preferences? If I remove learner_preferences from the cmi_data, the same thing happens with "score".

Any help would be appreciated

it looks like around lines 6477 in scorm-again.js

      (_this$learner_prefere = this.learner_preference) === null || _this$learner_prefere === void 0 ? void 0 : _this$learner_prefere.initialize();
      (_this$score = this.score) === null || _this$score === void 0 ? void 0 : _this$score.initialize();
arashster commented 11 months ago

Odd, just tried doing this and it seems to resolve this issue:

window.API_1484_11.loadFromJSON(JSON.parse(JSON.stringify(cmi_data)));