【问题标题】:Scorm files, Ruby on RailsScorm 文件,Ruby on Rails
【发布时间】:2022-01-03 20:47:35
【问题描述】:

我在我的平台 (LMS) 中实现了一个 scorm api,为此我使用了 Ruby on rails、Scorm gem 和 javascript api。 一切正常,scorm 内容显示满意。我对 Scorm 内容没有太多经验,但是他们发给我一个 scorm 类型的 zip 文件,当它上传到我正在使用的平台时,加载和执行需要很长时间。当我在 Scorm 云上测试这个文件时,内容运行正常。问题是平台不会产生任何错误。

为什么会发生这种情况? 我的代码中的错误?或 Scorm zip 文件的优化? 其他scorm内容正常工作,但是这个特定的,我不知道为什么。我什么都想不出来

有什么想法吗?谢谢

这是de api js:

<html>
<head>

<title>VS SCORM - RTE API</title>

<script language="javascript">

function createRequest() {

  // this is the object that we're going to (try to) create
  var request;

  // does the browser have native support for
  // the XMLHttpRequest object
  try {
    request = new XMLHttpRequest();
  }

  // it failed so it's likely to be Internet Explorer which
  // uses a different way to do this
  catch (tryIE) {

    // try to see if it's a newer version of Internet Explorer
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    }

    // that didn't work so ...
    catch (tryOlderIE) {

      // maybe it's an older version of Internet Explorer
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      }

      // even that didn't work (sigh)
      catch (failed) {
        alert("Error creating XMLHttpRequest");
      }

    }
  }

  return request;

}

//var debug = true;
var debug = false;

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

// ------------------------------------------
//   SCORM RTE Functions - Initialization
// ------------------------------------------

function LMSInitialize(dummyString) {
    // create request object
    var req = createRequest();

    // code to prevent caching
    var d = new Date();

    // set up request parameters - uses GET method
    req.open('GET','/scorm/initializesco?code='+d.getTime(),false);

    // submit to the server for processing
    req.send(null);

    // process returned data - error condition
    if (req.status != 200) {
        alert('Problem with Request');
        return "";
    }

    // process returned data - OK
    else {
        return "true";
    }
}

// ------------------------------------------
//   SCORM RTE Functions - Getting and Setting Values
// ------------------------------------------
//function LMSGetValue(varname) {
//  if (debug) {
//    alert('*** LMSGetValue varname='+varname
//                          +' varvalue=value ***');
//  }
//  return "value";
//}
function LMSGetValue(varname) {
  // create request object
  var req = createRequest();

  // set up request parameters - uses GET method
  req.open('GET','/scorm/getValue?varname='+urlencode(varname)
          +'&code='+Math.random(),false);

  // submit to the server for processing
  req.send(null);

  //alert('LMSGetValue() - ' + req.responseText);

  // process returned data - error condition
  if (req.status != 200) {
    alert('LMSGetValue() - Problem with Request');
    return "";
  }

  // process returned data - OK
  else {
    return req.responseText.replace("\n","");
  }
}
/*
function LMSSetValue(varname,varvalue) {
  if (debug) {
    alert('*** LMSSetValue varname='+varname
                          +' varvalue='+varvalue+' ***');
  }
  return "true";
}
*/

function LMSSetValue(varname,varvalue) {

  // create request object
  var req = createRequest();

  // set up request parameters - uses combined GET and POST
  //req.open('POST','nav/setValue?varname='+urlencode(varname)
  //      +'&code='+Math.random(),false);

  // set up request parameters - uses combined GET and POST
  req.open('POST','/scorm/setValue?varname='+urlencode(varname)
        +'&code='+Math.random(),false);

  // send header information along with the POST data
  var params = 'varvalue='+urlencode(varvalue);
  req.setRequestHeader("Content-type",
             "application/x-www-form-urlencoded");
  //req.setRequestHeader("Content-length", params.length);
  //req.setRequestHeader("Connection", "close");

  // submit to the server for processing
  req.send(params);

  // process returned data - error condition
  if (req.status != 200) {
    alert('LMSSetValue() - Problem with Request');
    return "false";
  }

  // process returned data - OK
  else {
    return "true";
  }

}

function LMSCommit(dummyString) {
    LMSGetValue('');
    if (debug)
    {
        //alert('*** LMSCommit ***');
    }
    return "true";
}

function LMSFinish(dummyString) {
    // create request object
    var req = createRequest();

    // code to prevent caching
    var d = new Date();

    // set up request parameters - uses GET method
    req.open('GET','/scorm/finishsco?code='+d.getTime(),false);

    // submit to the server for processing
    req.send(null);

    // process returned data - error condition
    if (req.status != 200) {
        alert('Problem with Request');
        return "";
    }

    // process returned data - OK
    else {
        return "true";
    }
}

// ------------------------------------------
//   SCORM RTE Functions - Error Handling
// ------------------------------------------
function LMSGetLastError() {
  if (debug) { alert('*** LMSGetLastError ***'); }

  sleep(1000);

  return 0;
}

function LMSGetDiagnostic(errorCode) {
  if (debug) {
    alert('*** LMSGetDiagnostic errorCode='+errorCode+' ***');
  }
  return "diagnostic string";
}

function LMSGetErrorString(errorCode) {
  if (debug) {
    alert('*** LMSGetErrorString errorCode='+errorCode+' ***');
  }
  return "error string";
}


function urlencode( str ) {
  //
  // Ref: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
  //
    var histogram = {}, unicodeStr='', hexEscStr='';
    var ret = (str+'').toString();

    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };

    // The histogram is identical to the one in urldecode.
    histogram["'"]   = '%27';
    histogram['(']   = '%28';
    histogram[')']   = '%29';
    histogram['*']   = '%2A';
    histogram['~']   = '%7E';
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    histogram['\u00DC'] = '%DC';
    histogram['\u00FC'] = '%FC';
    histogram['\u00C4'] = '%D4';
    histogram['\u00E4'] = '%E4';
    histogram['\u00D6'] = '%D6';
    histogram['\u00F6'] = '%F6';
    histogram['\u00DF'] = '%DF';
    histogram['\u20AC'] = '%80';
    histogram['\u0081'] = '%81';
    histogram['\u201A'] = '%82';
    histogram['\u0192'] = '%83';
    histogram['\u201E'] = '%84';
    histogram['\u2026'] = '%85';
    histogram['\u2020'] = '%86';
    histogram['\u2021'] = '%87';
    histogram['\u02C6'] = '%88';
    histogram['\u2030'] = '%89';
    histogram['\u0160'] = '%8A';
    histogram['\u2039'] = '%8B';
    histogram['\u0152'] = '%8C';
    histogram['\u008D'] = '%8D';
    histogram['\u017D'] = '%8E';
    histogram['\u008F'] = '%8F';
    histogram['\u0090'] = '%90';
    histogram['\u2018'] = '%91';
    histogram['\u2019'] = '%92';
    histogram['\u201C'] = '%93';
    histogram['\u201D'] = '%94';
    histogram['\u2022'] = '%95';
    histogram['\u2013'] = '%96';
    histogram['\u2014'] = '%97';
    histogram['\u02DC'] = '%98';
    histogram['\u2122'] = '%99';
    histogram['\u0161'] = '%9A';
    histogram['\u203A'] = '%9B';
    histogram['\u0153'] = '%9C';
    histogram['\u009D'] = '%9D';
    histogram['\u017E'] = '%9E';
    histogram['\u0178'] = '%9F';

    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);

    for (unicodeStr in histogram) {
        hexEscStr = histogram[unicodeStr];
        ret = replacer(unicodeStr, hexEscStr, ret); // Custom replace. No regexing
    }

    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
}

</script>

</head>
<body>

<p>

</body>
</html>

【问题讨论】:

    标签: ruby-on-rails scorm


    【解决方案1】:

    对于每个 LMSGetValue 调用,您都在对后端使用阻塞 GET/SET 请求 (XHR async=false)。有些课程对他们在启动/初始化时获得和设置了多少东西更加激进。大多数 SCORM 实现在 JS 中完成繁重的工作(所有 GET 值处理从不接触服务器,最常见的是)并且只去后端存储用户状态,通常以提交或某些存储频率。如果这是问题所在,则没有办法解决它,不涉及重写您的界面以在客户端而不是服务器端执行所有 SCORM 逻辑,因为您无法切换到使用异步 GET 调用,因为 LMSGetValue 期望返回成为所需的值。

    【讨论】:

      猜你喜欢
      • 2014-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2016-12-15
      • 1970-01-01
      • 2011-12-08
      • 2012-07-20
      相关资源
      最近更新 更多