Skip to content

Instantly share code, notes, and snippets.

@cadesalaberry
Created May 25, 2020 14:43
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 cadesalaberry/8e9e070503c523aa3c62680f8b427473 to your computer and use it in GitHub Desktop.
Save cadesalaberry/8e9e070503c523aa3c62680f8b427473 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const connectedStates = {
ready_to_call: {
on: {
JOIN: {
target: 'in_waiting_room',
cond: 'isEmployee',
},
START_CALL: {
target: 'in_call',
cond: 'isMedicalMember',
},
OTHER_TAB_STARTED_CALL: 'frozen',
},
},
frozen: {
on: {
OTHER_TAB_HANG_UP: 'ready_to_call',
},
},
in_waiting_room: {
on: {
DOCTOR_STARTS_CALL: {
target: 'in_call',
cond: 'isEmployee',
},
LEAVE_WAITING_ROOM: 'ready_to_call',
},
},
in_call: {
on: {
HANG_UP: 'ready_to_call',
CALL_ERROR: [
{
target: 'ready_to_call',
cond: 'isMedicalMember',
},
{
target: 'in_waiting_room',
cond: 'isEmployee',
},
],
},
},
};
const devicesState = {
initial: 'idle',
states: {
idle: {
on: {
DEVICES_REQUEST: 'devices_pending',
},
},
devices_success: {
type: 'final',
},
devices_error: {
type: 'final',
},
devices_pending: {
on: {
DEVICES_SUCCESS: 'devices_success',
DEVICES_FAILURE: [{
target: 'devices_blocked',
cond: 'isTutoAvailable',
}, {
target: 'devices_error',
}],
},
},
devices_blocked: {
on: {
DEVICES_RETRY: 'devices_pending',
},
},
},
};
const devicesStateMachine = Machine(devicesState);
const visioStateMachine = Machine({
id: 'visioState',
initial: 'off',
context: {
connectionAttempts: 0,
isMed: false,
isTutoAvailable: true,
},
states: {
off: {
on: {
INIT: 'idle',
},
},
idle: {
on: {
CONNECT: 'connecting',
},
},
connecting: {
on: {
CONNECT_SUCCESS: 'connected',
CONNECT_FAILURE: {
target: 'idle',
actions: assign({
connectionAttempts: (context) => context.connectionAttempts + 1,
}),
},
},
},
connected: {
on: {
DISCONNECT: 'idle',
},
initial: 'devicesState',
states: {
devicesState,
...connectedStates,
},
},
},
},
{
guards: {
isMedicalMember: (context) => context.isMed,
isEmployee: (context) => !context.isMed,
isTutoAvailable: (context) => !context.isTutoAvailable,
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment