Skip to content

Latest commit

 

History

History
146 lines (111 loc) · 8.01 KB

libraries.md

File metadata and controls

146 lines (111 loc) · 8.01 KB

Libraries: packages without them, and older than the pack

Exports from h5p.com and h5p.org often hold only content/. By default the player takes every package's libraries from libraries, the pack if unset, so such a package plays with nothing to set:

<h5p-player src="stripped.h5p"></h5p-player>

With trusted, a package that carries its libraries plays as it is, and one that lacks them is refused, naming what is missing, unless libraries tells the player where to look: libraries="pack".

The pack

pack is @missing-elements/h5p-libraries: the H5P hub's runtime libraries for every content type it serves, each at the newest minor of its major, as one archive per library, 13.8 MB in all. The player downloads only the archives a package needs (for the demo's packages, 0.04 to 4 MB) and checks each against the SHA-256 in the pack's index. An archive is kept on the device and shared by every package that uses it; once kept, it is used with no request, online or offline.

Each player release pins one version of the pack, carries its index, and fetches its archives from jsDelivr. The pack is rebuilt from the hub weekly.

Newer versions of the libraries a package carries

For a trusted package with libraries="pack", a library it carries plays at the pack's version when the pack has the same major at a higher minor, or the same minor at a higher patch. An H5P site gets there by moving content to a newer minor with H5P's content upgrade, which an administrator starts. An old export then plays with the fixes and the look of current H5P. Untrusted, the default, a package's own libraries are ignored and the pack's always play.

  • Equal or older in the pack, or only another major there: the package's own copy, and nothing is downloaded.
  • A library the pack does not have keeps the package's own copy, and runs against the pack's newer versions of the libraries it shares: H5P's rule is that a minor does not break what depends on it.
  • A library the package carries that its content never plays (an editor library, or an older minor kept for an H5P site's upload check) stays as it is, and nothing is downloaded for it.

Content written for an older minor is upgraded before it starts: the player runs the steps each library ships in its upgrades.js on the content's parameters, as the H5P plugins do. A Question Set written for 1.20 keeps its background image under 1.21, which reads it from a new place. If a step fails, the content plays as written and the console says so.

With trusted, refresh-libraries="off" plays the libraries a package carries as exported, and the pack only supplies what is missing: for content that has to show exactly what its author tested. libraryBundle.refreshed and the ready event's detail list what played at the pack's version.

A refreshed package is another build: its revision names the archives of the pack it played with (Which build a learner completed), and a learner's state saved against the build before starts over, once, with H5P's own "content has changed" dialog. A pack release that changes none of a package's libraries changes nothing for it.

Content newer than the pack

h5p.com gets a library's new minor version before the H5P hub serves it, and the pack follows the hub, so for a few weeks content made on h5p.com can name a version no source has. The player then plays it at the newest older minor of the same major that a source has: Question Set 1.21 for content made with 1.22, Multiple Choice 1.16 for a question in it made with 1.17. It does so only after every source in libraries has been tried for the version named, so a later source that has it wins over an earlier one with an older version, and never across a major.

Most minor versions only add fields, which the older code ignores, so the content plays without what the newer version added. Some move or rename fields (of the 469 minor bumps in the history of the pack's libraries, 119 came with an upgrade step, which is how H5P marks such a change), and after such a change a part can be missing or drawn wrong. Played untrusted, the content is still checked against the older version's fields.

downgradedLibraries, on the element and in the ready event's detail, lists each library played older, { library, from, to }, and the console says so. downgrade-libraries="off" refuses such a package instead, naming the version it needs. A package that carries the newer version itself plays it, trusted, and needs none of this.

On your own hosting

The pack is found in one of three places:

  • libraries="pack" alone: jsDelivr, at the version the release pins.

  • pack-base, the folder of a copy of the package's parts/ on your site. Its index.json is read from there, and kept, so a package can be planned for with no network:

    <h5p-player src="stripped.h5p" libraries="pack" pack-base="/h5p-libraries/"></h5p-player>
  • With a bundler, the pack property, which the bundler fills with each archive as an asset of your site:

    import { pack } from '@missing-elements/h5p-libraries'
    
    player.pack = pack
    player.setAttribute('libraries', 'pack')

Serve libraries.txt beside it: each library's licence and authors, which those licences ask to travel with the code. The package also carries the whole pack as one file, libraries.h5p (15.5 MB, 1.9 MB of it libraries an H5P site's upload check wants and a player never reads). A .h5p URL in libraries takes it like any bundle, downloaded whole, with no refresh. A bundle is read only from the origin its address names: one that redirects to another origin is refused.

Several sources

libraries takes several sources separated by spaces, tried in order, each asked only for what the ones before it lack. The pack refreshes wherever it is in the list, and supplies what is missing once the sources before it have been tried. A .h5p URL only supplies what is missing.

The H5P hub itself is not asked: the only hub host that answers a browser serves an outdated catalogue. hub was read as pack up to player 0.10; it is now a URL relative to the page.

When a source cannot be reached

Archives of the pack kept before are used with no request, and a pack-base index is kept as last read. A refresh that cannot be had (an archive that will not download, or does not match its hash) is given up, and a trusted package plays with its own libraries, as exported. A .h5p bundle downloaded whole from the same URL before is used when that URL cannot be reached, so a stripped export plays offline once it has played online.

Packages that are still refused

A package that needs a library no source carries is refused, with the missing libraries named: usually a library newer than the pack, which the next pack release will carry. The check follows each library's own dependencies too, as the runtime does, so an old export whose libraries ask for a version it does not carry gets that version from the sources as well.

Addons

The pack also carries H5P.MathDisplay, the addon the H5P plugins add to content whose text holds LaTeX (\(…\), \[…\] or $$…$$) once an administrator has installed it. The pack stands in for a site's installed libraries: the player adds the addon whenever the pack refreshes (the default) or supplies anything, and from an attached .h5p bundle that has it, to the content its library.json names. MathDisplay renders with MathJax from its own folder, so formulas work offline. Played untrusted, a package that lists it among its dependencies needs the source to have it.

Untrusted, the default

Unless the page sets trusted, a package's own library folders are ignored and its libraries come only from libraries, pack when that is not set: the archives it needs, nothing it carries. A package that needs a library the sources lack is refused, and the content is checked against the semantics.json of the libraries the sources serve. Packages you did not make has the rest, including missingLibraries.carried.