Last active
October 28, 2021 02:41
-
-
Save m-revetria/cbed96eaf4a2cdddd246e17359ec599a to your computer and use it in GitHub Desktop.
Revisions
-
m-revetria revised this gist
Oct 28, 2021 . 1 changed file with 10 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -27,9 +27,12 @@ const browserStates = { PAUSE: 'paused', SWITCH_CAM: { target: 'streaming', actions: ['assignSwitchCamera'], }, SWITCHED_CAM: { target: 'streaming', actions: ['unassignSwitchCamera'], }, CAM_COUNT: { target: 'streaming', actions: ['assignCamerasCount'] @@ -134,8 +137,11 @@ const livestreamMachine = Machine( camerasCount: (_context, event) => event.camerasCount }), assignCurrentCamera: assign({ switchCamera: (_context, _event) => true, }), unassignSwitchCamera: assign({ switchCamera: (_context, _event) => undefined, }), }, }, ); -
m-revetria revised this gist
Oct 28, 2021 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,10 +25,11 @@ const browserStates = { streaming: { on: { PAUSE: 'paused', SWITCH_CAM: { target: 'streaming', actions: ['assignCurrentCamera'] }, SWITCHED_CAM: 'streaming', CAM_COUNT: { target: 'streaming', actions: ['assignCamerasCount'] -
m-revetria revised this gist
Oct 27, 2021 . 1 changed file with 14 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,10 @@ const browserStates = { streaming: { on: { PAUSE: 'paused', SWAP_CAM: { target: 'streaming', actions: ['assignCurrentCamera'] }, CAM_COUNT: { target: 'streaming', actions: ['assignCamerasCount'] @@ -55,6 +58,7 @@ const livestreamMachine = Machine( type: 'parallel', context: { camerasCount: undefined, currentCamera: undefined, error: undefined, }, states: { @@ -122,8 +126,15 @@ const livestreamMachine = Machine( }, { actions: { assignError: assign({ error: (_context, event) => event.error, }), assignCamerasCount: assign({ camerasCount: (_context, event) => event.camerasCount }), assignCurrentCamera: assign({ currentCamera: (context, _event) => (context.currentCamera || 0) + 1, }) }, }, ); -
m-revetria revised this gist
Oct 27, 2021 . 1 changed file with 125 additions and 42 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,46 +1,129 @@ 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', SWAP_CAM: 'streaming', CAM_COUNT: { target: 'streaming', actions: ['assignCamerasCount'] }, ERROR: { target: 'error', actions: ['assignError'], }, }, }, paused: { on: { GO_LIVE: 'streaming', }, }, error: { on: { GO_LIVE: 'streaming', }, }, }, }; const livestreamMachine = Machine( { id: 'livestream-hierarchical', type: 'parallel', context: { camerasCount: undefined, error: undefined, }, 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: { target: 'error', actions: ['assignError'], }, END: 'completed', }, ...encoderStates, }, browser: { on: { END: 'completed', }, ...browserStates, }, error: { type: 'final', }, completed: { type: 'final', }, }, }, type: { initial: 'test', states: { test: { on: { EVENT: 'event', }, }, event: { type: 'final', }, }, }, }, }, { actions: { assignError: (_context, event) => event.error, assignCamerasCount: (_context, event) => event.camerasCount, }, }, ); -
m-revetria created this gist
Oct 27, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ // Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: 'fetch', initial: 'idle', context: { retries: 0 }, states: { idle: { on: { FETCH: 'loading' } }, loading: { on: { RESOLVE: 'success', REJECT: 'failure' } }, success: { type: 'final' }, failure: { on: { RETRY: { target: 'loading', actions: assign({ retries: (context, event) => context.retries + 1 }) } } } } });