WebGL¶
The managed half of the browser bridge. The other half is the jslib in Plugins/WebGL.
WebGlLmsBridge implements ILmsBridge by calling into the jslib. RevLearningWebGlBridge is the DllImport surface those calls go through.
This is the only folder in Runtime/ that knows it is in a browser. Everything above it talks to ILmsBridge, which is why the Editor can run the same course against a stub.
Reading strings out of JavaScript¶
Emscripten passes a string into JavaScript easily and returns one only awkwardly: the managed side has to own the buffer. So reads are two calls — one to size the string, one to copy it into a buffer the caller allocated. A single call returning a pointer would mean allocating in the JS heap and freeing it from C#, which is the arrangement that leaks when an exception lands in between.
It also means the two calls must agree about encoding. Both work in bytes rather than characters, via lengthBytesUTF8 and stringToUTF8, because a learner name with an accent in it makes those two numbers differ and the buffer is sized in bytes.
Where the API actually is¶
The SCORM API object is not in the page the player is in. The LMS puts the SCO in an iframe and the API lives on a parent or an opener, so finding it means walking up window.parent and then trying window.opener, with a hop limit. The jslib does that walk.
If it finds nothing, Init returns false and RevLearningRuntime hands back the stub — which is also exactly what happens when you press Play in the Editor.