fix(runtime): hear the statements content sends as it starts
Summary
Closes #343. The frame's boot script listened for xAPI only after H5P.init(), so a statement content sends as it starts never reached the page: Accordion's consumed, the attempted the core's setActivityStarted() sends, and the completed a Course Presentation resumed on its summary slide says again. The listener is now attached before init, as the core's own relay is.
finished does not change. H5P's core starts listening for a result only once the content is attached, and so does finished: a result said during the start is an xapi statement only. Without that, reopening a finished deck would raise finished on load and the SCORM bridge would write its score and status again.
Changes
packages/runtime/src/frame-boot.ts: thexAPIlistener moves aboveH5P.init(), and postsfinishedonly onceinithas returned. Statements from the start reach the element before itsreadyevent. The element already relays a statement in any state, and holds it until the revision is known.design/frame.md: a rule, The frame hears the content from its start.design/results.mdanddocs/api.md: a result said while the content attaches is a statement and nofinished.- Journeys:
- Accordion checks that its
consumed(completion: true, no score) arrives, and nothing more. - Course Presentation, new case: a learner who comes back to the summary slide hears
attempted,progressed,completed, and nofinished. - Drag and Drop, Course Presentation and Interactive Video list
attemptedwhere they list every verb. Course Presentation finds itsprogressedstatement by verb.
- Accordion checks that its
- Rides along: the Column case requires the page's id to be an address (CodeRabbit's follow-up on #342, pushed after it merged).
Verification
-
pnpm testinapps/journeys(Chromium): 13 files, 95 passed. Before the fix, Accordion heard no statement. The new Course Presentation case fails both ways: no statement without the move, onefinishedwithout the hold. -
pnpm sweep --modes untrustedon this branch: 55 of 55 plays pass. 40 content types now deliver a statement beforeready(attemptedfor 37,consumefor Accordion and Collage,progressedfor Documentation Tool); none sends a result there from a fresh start. -
pnpm test:browserinpackages/player(Chromium, both projects): 32 files, 219 passed. -
pnpm --filter @missing-elements/h5p-runtime --filter @missing-elements/h5p-journeys typecheck,pnpm lint,node scripts/comments.mjs: pass. -
Tests added or updated where behavior changed
-
Documentation updated where public behavior or deployment changed
-
Relevant type checks, tests, and builds pass
-
No security-sensitive details or credentials are included
Screenshots or reproduction
Play an Accordion and listen for xapi on the element: before, no event; after, one consumed as it starts.
Summary by cubic
The frame's boot script now attaches its xAPI listener before H5P.init(), so statements content sends as it starts — Accordion's consumed and the core's attempted from setActivityStarted() — reach the page instead of being lost. A result said while the content attaches is still posted, but only as an xapi statement, not as finished, matching the core's own behavior.
- The
xAPIlistener inpackages/runtime/src/frame-boot.tsnow attaches beforeH5P.init(), andfinishedis gated until init returns: a Course Presentation resumed on its summary slide repeatscompletedas it is drawn, but raises nofinished. - Journey tests pin the new
consumedandattemptedstatements: Accordion expects onlyconsume, Drag and Drop, Course Presentation, and Interactive Video listattemptedalongside their other verbs, and Course Presentation resumes to a repeatedcompletedwith nofinished. - The Column test now parses the page id as a URL, requiring an HTTP(S) host so parent matches can't succeed vacuously.
design/frame.md,design/results.md, anddocs/api.mddocument that the frame hears the content from its start and that a result repeated as the content attaches is anxapistatement only.