Skip to content

Plugins/WebGL

RevLearning.jslib — the JavaScript half of the bridge, and the only file in the package that talks to the LMS API directly. Its managed counterpart is Runtime/WebGL.

Unity compiles a .jslib into the Emscripten output, so these functions are callable from C# via DllImport.

Exports

Function Maps to
RevLearning_Init LMSInitialize / Initialize, plus finding the API
RevLearning_Commit LMSCommit / Commit
RevLearning_Finish LMSFinish / Terminate
RevLearning_SetString LMSSetValue / SetValue
RevLearning_GetStringLen sizes a GetValue result
RevLearning_GetStringFill copies it into a caller-owned buffer
RevLearning_GetLastError LMSGetLastError / GetLastError

Two calls for a read because Emscripten returns strings awkwardly: the managed side has to own the buffer. Sizing then filling avoids allocating in the JS heap and freeing from C#, which is the arrangement that leaks when an exception lands between the two.

Both calls work in bytes, via lengthBytesUTF8 and stringToUTF8. A learner name with an accent makes the byte and character counts differ, and the buffer is sized in bytes.

Finding the API

The SCORM API object is never in the SCO's own window. The LMS puts the SCO in an iframe, so the search walks up window.parent with a hop limit, then tries window.opener — a popup player is the other common arrangement. Both the 1.2 names (API, LMS* methods) and the 2004 names (API_1484_11, bare methods) are recognized.

If the walk finds nothing, Init returns false, RevLearningRuntime hands back the stub, and the course runs offline rather than throwing. That is the same path the Editor takes.

Why this file has a test suite

It is the one part of the package no C# test can reach, and it is the part standing between a course and the LMS. Tests~/js/ runs it under Node with fake API objects — including deliberately awkward ones that keep state on this or behind a WeakMap — because the bug that made ILmsRuntime.LastError report "no error" for a whole live session was invisible to a fake whose state was reachable through the prototype chain.