Skip to content

Instantly share code, notes, and snippets.

@karkowg
Last active February 24, 2021 19:30
Show Gist options
  • Select an option

  • Save karkowg/00d72c743c649562af20c6de7b362592 to your computer and use it in GitHub Desktop.

Select an option

Save karkowg/00d72c743c649562af20c6de7b362592 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const makeVideoPlayerMachine = ({ mode, inactivityTimeout }) => Machine({
initial: 'paused',
context: {
mode,
inactivityTimeout,
},
states: {
paused: {
on: {
PLAY: 'playing',
},
},
playing: {
on: {
PAUSE: 'paused',
},
after: {
INACTIVITY_DELAY: { target: 'inactive', cond: 'isVod' },
},
},
inactive: {
on: {
STILL_WATCHING: 'playing',
FELL_ASLEEP: 'paused',
},
},
},
}, {
delays: {
INACTIVITY_DELAY: ctx => ctx.inactivityTimeout * 1000,
},
guards: {
isVod: ctx => ctx.mode === 'vod',
},
});
makeVideoPlayerMachine({
mode: 'live',
inactivityTimeout: 5,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment