简体   繁体   English

Javascript SCORM API提交 - 异步还是同步?

[英]Javascript SCORM API commit - async or sync?

We are currently facing a design problem implementing a SCORM LMS System. 我们目前正面临实施SCORM LMS系统的设计问题。 For example, the API defined a function LMSCommit which must return either 'true' or 'false'. 例如,API定义了一个函数LMSCommit,它必须返回'true'或'false'。 Within that method, our LMS has to make an asynchronous call to a server side service, using a callback function containing the success or failure message in its argument. 在该方法中,我们的LMS必须使用包含其参数中的成功或失败消息的回调函数对服务器端服务进行异步调用。 We claim, that this is simply not possible! 我们声称,这根本不可能! Yet we think its worthwhile to ask some pros whether there is something we are missing here. 然而,我们认为值得向一些专业人士询问我们是否遗漏了一些东西。

The SCO (no influence on our part) calls the method like this: SCO(对我们没有影响)调用这样的方法:

var result = LMSCommit('');

Our LMS (influence on our part) we implement something like this: 我们的LMS(对我们的影响)我们实现这样的事情:

function LMSCommit(useless) {
  callOurServiceFunction(function(Status) {
    // what am I supposed to do here in order to put status into
    // the return value of the outer function???
  }

  // fake true as the callourServiceFunction returned immediatly,
  // no idea how I can use Status to create a return value
  return 'true';
}

Are we missing some fancy trick here or is the SCORM Standard simply "disputable"? 我们在这里错过了一些花哨的技巧,还是SCORM标准只是“有争议”?

It's normally implemented using asynchronous code with a fairly worthless "true" value returned. 它通常使用异步代码实现,返回一个相当无价值的“true”值。 This is well-known by SCORM course developers, who have learned not to rely on the Commit return value for anything important. 这是SCORM课程开发人员所熟知的,他们已经学会了不依赖于Commit返回值来处理任何重要的事情。 In this case, all the return value means is that an ajax request was fired. 在这种情况下,所有返回值均意味着触发了ajax请求。

If you implement Commit using the synchronous approach, the course will appear to lag and stall while waiting for the return value, which will guarantee a ton of complaints and claims that your SCORM engine is broken. 如果使用同步方法实现Commit,则在等待返回值时,该过程似乎会滞后并停止,这将保证大量投诉并声称您的SCORM引擎已损坏。

Very frustrating for people in your shoes, but unfortunately, there's nothing you can really do about it. 穿着鞋子的人非常沮丧,但遗憾的是,你真的无能为力。

A little background for those less familiar with SCORM: 那些不熟悉SCORM的人有一点背景知识:

SCORM, which is a compilation of specs, not a true standard, received its last major update in 2004. (The updates since then have been minor, no major architectural changes.) This means it's ten years old. SCORM是规范的汇编,而不是真正的标准,它在2004年收到了它的最后一次重大更新。(从那时起的更新很小,没有重大的架构变化。)这意味着它已经十年了。 SCORM 1.2 is even older. SCORM 1.2甚至更老了。 The ADL has announced they are not going to be updating SCORM anymore -- the lid is closed, as they say. ADL已经宣布他们不会再更新SCORM了 - 正如他们所说,盖子已关闭。

To put things in perspective, the last major SCORM update was released when IE6 was the dominant browser, Google Chrome and the iPhone didn't exist, Yahoo and RealPlayer were relevant, Facebook was a dorm room project, and everyone thought Adobe Flex and RIAs were the way of the future. 为了正确看待,最近的主要SCORM更新发布时,IE6是主流浏览器,谷歌Chrome和iPhone不存在,雅虎和RealPlayer相关,Facebook是一个宿舍室项目,每个人都想到Adobe Flex和RIAs是未来的方式。 It's a different world now... if they were to start over, I'm sure they would have gone a different route. 现在这是一个不同的世界......如果他们重新开始,我相信他们会走另一条路。 This is where xAPI (aka Tin Can) picks up; 这就是xAPI(又名Tin Can)的选择; it uses a different communication model (RESTful API), and can be used to replace SCORM in LMSs that support xAPI. 它使用不同的通信模型(RESTful API),可用于替换支持xAPI的LMS中的SCORM。 (Note xAPI is still not widely supported yet.) (注意xAPI尚未得到广泛支持。)

xAPI links if anyone reading this is interested: xAPI链接是否有人对此感兴趣:

I had to write out a AJAX queue system as I tried to keep async calls until the browser exits and switch to sync. 我不得不写出一个AJAX队列系统,因为我试图保持异步调用,直到浏览器退出并切换到同步。

But you have several scenarios to check - 但是你有几种情况需要检查 -

  1. Is the session initialized 会话是否已初始化
  2. Is the session terminated 会话终止了吗?
  3. And the "No Argument was expected" aka your 'useless' remark haha. 并且“没有预期的争论”也就是你的“无用”评论哈哈。
  4. Now you can tally up total time, and manage anything else that may need to be by the LMS (progress) etc ... LMSCommit sounds like SCORM 1.2 though so from memory you may not have to do that. 现在你可以计算总时间,并管理LMS可能需要的任何其他内容(进度)等... LMSCommit听起来像SCORM 1.2,尽管如此,从内存中你可能不必这样做。
  5. Send your student attempt to the sever 将学生尝试发送到服务器

Now keep in mind HTTP requests get tricky. 现在记住HTTP请求变得棘手。 Past Commit calls can arrive later than a current submission. 过去提交呼叫可以晚于当前提交到达。 I time stamp mine so I don't end up with a collision. 我给我的时间戳,所以我不会发生碰撞。 Also this queue allows me to submit in order as you don't want prior Commit spam to arrive after the exit thus overwriting cmi.exit and anything see that happened in those milliseconds/seconds. 此队列也允许我按顺序提交,因为您不希望先前的Commit垃圾邮件在退出后到达,从而覆盖cmi.exit,任何事情都会看到发生在那些毫秒/秒内。

There are LMS's out there that behave in a non-cached way. LMS存在于非缓存方式中。 Ever get/set is a round trip to the server. 曾经/设置是到服务器的往返。 Hence, you see a 50-400ms lag per request which equates to 3-6 seconds of a stuck user experience for the student. 因此,您看到每个请求的延迟时间为50-400ms,这相当于学生卡住用户体验3-6秒。

If you've cached the student attempt and are just committing it, then your sending say 5-12KB of data over to the server. 如果您已经缓存了学生尝试并且只是提交了它,那么您的发送将5-12KB的数据发送到服务器。 And if you've taken a cached-hybrid approach your only sending whats changed. 如果你采用了缓存混合方法,你唯一的发送方式会发生变化。

This all falls in line with the power going out, internet connection loss and in general how you want your Runtime to behave. 这一切都与电力输出,互联网连接丢失以及您希望运行时的行为方式一致。

So per the above 'list' if I'm able to add it to the queue I respond 'true' and if it meets any of the other criteria 'false'. 因此,根据上面的“列表”,如果我能够将它添加到队列中,我会回答'true',如果它符合任何其他标准'false'。

GL, Mark GL,马克

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM