如何在JavaScript中获取scorm事件?需要将所有事件保存在数据库中

问题描述 投票:0回答:1

我正在尝试使用 SCORM 创建 LMS 应用程序,并且我在 SCORM 网站上发现了复杂的文档。最后,我得到了一些示例代码并将它们与我的本地系统集成,但没有任何效果。 https://drive.google.com/drive/folders/1FsnCRSQ4uersEU7EX5tLyp65GI4mN2J6?usp=sharing此处提供了示例文档。只需下载此文件夹并从 res 文件夹中获取索引文件即可。接受 Angular 或 React 工作的 NPM。

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>Trivial SCORM Player Example</title>
  
    <script src="tsp.js"></script>
    <script>
    function supports_html5_storage() {
        try {
            return 'localStorage' in window && window['localStorage'] !== null;
        } catch (e) {
            return false;
        }
    }
    
    //users of old browsers will not be able to save their progress localy (but they will be able to store it server side)
    if (!supports_html5_storage()){
        window.localStorage = {};
    }
    
    tspInit(
            window,
            window.localStorage,
            //this has to be unique per each scorm you serve
            'SCORM_ID.',
            function(progress){
                //this will be called whenever student makes a progress in test.
                console.log(progress);
            });
     
    </script>
    
</head>
<body>
    <iframe 
        src="cb980550-6523-48ea-9825-23dca8bb0219/res/index.html"
        name="course" 
        frameborder="0" 
        style="overflow:hidden;overflow-x:hidden;overflow-y:hidden;height:600px;width:800px" 
        height="600"
        width="800">
    </iframe>
</body>

function tspInit(window, storage, prefix, callback){ 
    prefix = typeof prefix !== 'undefined' ? prefix : '';
    callback = typeof callback !== 'undefined' ? callback : console.log;
    debugger
    window.API = {};
    
    window.scormStatus = {
            lesson_status: '',
            score_raw: 0,
            score_max: 100,
            score_min: 0,
            session_time: 0,
            detailed_answers: {}
    }; 
    
    
    window.API.LMSInitialize = function(arg){
        var success = this.api.LMSInitialize(arg); 
        console.log(success, 'LMSInitialize');
    }
    window.API.LMSTerminate = function() {
        console.log('LMSTerminate');
    }
    
    window.API.LMSGetValue = function(varname) {
        varname = prefix + varname;
        var ret = storage.getItem(varname);
        if (ret == null && (varname.indexOf('_count', this.length - '_count'.length) !== -1)) {
            ret = 0;
            storage.setItem(varname, ret);
        }
        console.log('LMSGetValue', varname, '=', ret);
        return ret;
    }
    
    window.API.LMSSetValue = function(varname, varvalue) {
        varname = prefix + varname;
    
        var m = varname.match(/([0-9]+)\.cmi\.interactions\.([0-9]+)\.id/);
        if (m != null) {
            storage.setItem('{{scorm.id}}.cmi.interactions._count', parseInt(m[2]) + 1);
        }
    
        m = varname.match(/([0-9]+)\.cmi\.interactions\.([0-9]+)\.result/);
        if (m != null) {
            var key = storage.getItem(prefix + 'cmi.interactions.' + parseInt(m[2]) + '.id');
            window.scormStatus.detailed_answers[key] = varvalue;
        }
    
        if (varname == prefix + 'cmi.core.lesson_status')
            window.scormStatus.lesson_status = varvalue;
        if (varname == prefix + 'cmi.core.score.raw')
            window.scormStatus.score_raw = varvalue;
        if (varname == prefix + 'cmi.core.score.max')
            window.scormStatus.score_max = varvalue;
        if (varname == prefix + 'cmi.core.score.min')
            window.scormStatus.score_min = varvalue;
        if (varname == prefix + 'cmi.core.session_time')
            window.scormStatus.session_time = varvalue;
    
        storage.setItem(varname, varvalue); 
        console.log('LMSSetValue', varname, '=', varvalue);
    }
    
    window.API.LMSCommit = function() {
        console.log('LMSCommit');
        //saving to API
        callback(window.scormStatus);
        return true; 
    
    }
    
    window.API.LMSFinish = function() {
        console.log('LMSFinish');
    }
    
    window.API.LMSGetLastError = function() {
        console.log('LMSGetLastError');
    }
    
    window.API.LMSGetErrorString = function() {
        console.log('LMSGetErrorString');
    }
    
    window.API.LMSGetDiagnostic = function() {
        console.log('LMSGetDiagnostic');
    }
    
}

javascript scorm scorm2004
1个回答
0
投票

你有解决办法吗?我试图了解如何在 REACT 基础应用程序中捕获 SCORM 事件。任何指导都会有帮助

© www.soinside.com 2019 - 2024. All rights reserved.