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, });