Function
The lesson to mark
The two handlers a player binds to its lifecycle events
The finish rule itself lives in hasFinishedWatching; this hook is the
part that has to know when it is fair to act on it. Two refs carry that:
time-update at that
position, and writing then would record a completion the learner did not
earn on this visit. The lesson already reads as complete from its
position, so nothing is lost by waiting.time-update fires several times a second, and the
last fifteen seconds of a lesson would otherwise write the same mark
fifty times.The write goes through markLessonComplete — the same path the manual
button uses — so there is one stored notion of "done" rather than two. The
same "written" flag makes the celebration fire once: the burst belongs to
the moment the lesson is finished, not to every progress event after it.
Completion is never withdrawn here: rewinding a finished lesson leaves the
mark standing.
The lesson's own durationSeconds is preferred, and the provider's
reported duration is the fallback, so a lesson whose metadata is missing a
runtime can still be finished.
Marks a lesson complete once the learner has watched it to the end.