Skip to content

Instantly share code, notes, and snippets.

@DiegoYungh
Created February 11, 2022 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DiegoYungh/1353b12a1c6d7d1e297a348439b10eff to your computer and use it in GitHub Desktop.
Save DiegoYungh/1353b12a1c6d7d1e297a348439b10eff to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const encoderStates = {
initial: 'streaming',
states: {
streaming: {
on: {
ENCODER_STOPPED: 'paused',
},
},
paused: {
on: {
ENCODER_RESUMED: 'streaming',
},
},
},
};
const browserStates = {
initial: 'processing',
states: {
processing: {
on: {
PROCESSED: 'streaming',
},
},
streaming: {
on: {
PAUSE: 'paused',
ERROR: 'error',
},
},
paused: {
on: {
GO_LIVE: 'streaming',
},
},
error: {
on: {
GO_LIVE: 'streaming',
},
},
},
};
const livestreamMachine = Machine({
id: 'livestream-hierarchical',
type: 'parallel',
states: {
stage: {
initial: 'browserCanStream',
states: {
browserCanStream: {
on: {
GO_LIVE: 'browser',
FROM_ENCODER: 'encoderProcessing',
END: 'completed',
},
},
encoderProcessing: {
on: {
PROCESSED: 'encoderCanStream',
FROM_BROWSER: 'browserCanStream',
END: 'completed',
},
},
encoderCanStream: {
on: {
ENCODER_STARTED: 'encoder',
FROM_BROWSER: 'browserCanStream',
},
},
encoder: {
on: {
ERROR: 'error',
END: 'completed',
SWITCH: 'encoderCanStream',
},
...encoderStates,
},
browser: {
on: {
END: 'completed',
SWITCH: 'browserCanStream',
},
...browserStates,
},
error: {
type: 'final',
},
completed: {
type: 'final',
},
},
},
type: {
initial: 'test',
states: {
test: {
on: {
EVENT: 'event',
},
},
event: {
type: 'final',
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment