Created
March 14, 2020 17:05
-
-
Save danielkcz/c71fecfd3e9749dedc5292d7209a8ba2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const audioStreamMachine = Machine({ | |
id: 'audioStream', | |
initial: 'idle', | |
context: { | |
stream: null, | |
streamError: null, | |
}, | |
states: { | |
idle: { | |
on: { | |
CLAIM_STREAM: 'claiming', | |
}, | |
}, | |
claiming: { | |
invoke: { | |
id: 'streamClaim', | |
src: () => getAudioStream(), | |
onDone: { | |
target: 'streaming', | |
actions: assign({ stream: (_, ev) => ev.data }), | |
}, | |
onError: { | |
target: 'failed', | |
actions: assign({ streamError: (_, ev) => ev.data }), | |
}, | |
}, | |
on: { | |
STOP_STREAM: 'idle', // <-- I need to wait for promise resolve | |
/* | |
stream.getTracks().forEach(function(track) { | |
track.stop() | |
}) | |
*/ | |
}, | |
}, | |
streaming: { | |
on: { | |
STOP_STREAM: 'idle', | |
/* | |
stream.getTracks().forEach(function(track) { | |
track.stop() | |
}) | |
*/ | |
}, | |
}, | |
failed: {}, | |
}, | |
}) | |
function getAudioStream() { | |
return navigator.mediaDevices.getUserMedia({ | |
audio: true, | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment