Last active
July 9, 2020 16:40
-
-
Save kellyjandrews/f6ef30ef3a1fdc3f43054213c4806f4d 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 stream = Machine( | |
{ | |
id: 'stream', | |
initial: 'connected', | |
context: { | |
stream: null, | |
hasAudio: true, | |
hasVideo: true, | |
videoSrcObject: null, | |
audioLevel: { | |
movingAvg: null, | |
logLevel: null, | |
}, | |
}, | |
states: { | |
connected: { | |
id: 'connected', | |
invoke: { | |
id: 'monitorStreamEvents', | |
src: 'monitorStreamEvents', | |
}, | |
on: { | |
AUDIO_LEVEL_UPDATED: { | |
actions: 'updateAudioLevel', | |
}, | |
VIDEO_ELEMENT_CREATED: { | |
actions: 'assignStream', | |
}, | |
TOGGLE_AUDIO_PUBLISH: { | |
actions: ['toggleAudioPublish', 'sendToggleAudioEvent'], | |
}, | |
TOGGLE_VIDEO_PUBLISH: { | |
actions: ['toggleVideoPublish', 'sendToggleVideoEvent'], | |
}, | |
TOGGLE_AUDIO: { actions: 'toggleAudio' }, | |
TOGGLE_VIDEO: { actions: 'toggleVideo' }, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
updateAudioLevel: assign({ audioLevel: (ctx, e) => e.audioLevel }), | |
assignStream: assign({ | |
stream: (_, e) => e.stream, | |
videoSrcObject: (_, e) => e.stream, | |
}), | |
sendToggleAudioEvent: send((ctx, e) => ({ | |
type: 'TOGGLE_AUDIO', | |
value: !ctx.hasAudio, | |
})), | |
sendToggleVideoEvent: send((ctx, e) => ({ | |
type: 'TOGGLE_VIDEO', | |
value: !ctx.hasVideo, | |
})), | |
toggleAudioPublish: (ctx) => !ctx.hasAudio, | |
toggleVideoPublish: (ctx) => !ctx.hasVideo, | |
toggleAudio: assign({ hasAudio: (ctx, e) => e.value }), | |
toggleVideo: assign({ hasVideo: (ctx, e) => e.value }), | |
}, | |
services: { | |
monitorStreamEvents: () => {} , | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment