Events
Copy as Markdownplayer.on(type, listener) returns a function that removes the listener. The listener gets
{ type, player, state, fatal?, error? }.
const off = player.on("statechange", ({ state }) => console.log("now", state));player.on("complete", ({ state }) => console.log(state, "ended"));off();Click the card, or pick a state: the log shows each event as the player sends it.
Halcyon
•••• •••• •••• 4291
CARD HOLDER
MAYA CHEN
EXPIRES
09/29
CVV 382
Issued by Halcyon Bank. Valid only when signed.
import { mount } from "@rupamotion/player";
const player = mount(document.querySelector(".card-flip"));
player.play("flip"); | Event | When |
|---|---|
statechange |
A state starts: a trigger, play(state), a loop back. While paused it is sent after play. |
complete |
A state with a finite end has ended. Again after a seek back in it; never for an endless one. |
play |
paused changed to false, whatever changed it. |
pause |
paused changed to true, whatever changed it. |
error |
{ fatal: true, error }: an internal error made the player inert (see errors). |
Rules for listeners
Section titled “Rules for listeners”- A listener that throws is reported the way an
EventTargetreports one (reportError). The other listeners and the player go on. - An API call made while an event is sent (for example
playinsidestatechange) is queued and runs right after, in a task of its own. A listener that plays on everystatechangecannot hang the page. The argument is still checked at once. destroyis not queued: the root is let go at once.
DOM events
Section titled “DOM events”The root sends rupastatechange with detail.state. The <rupa-player> element sends rupaready and rupaerror;
see the element reference.