Created
September 14, 2020 15:05
-
-
Save rmnbrd/8f278af42c931af9d437153136d930a9 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 fetchMachine = Machine({ | |
id: 'call', | |
initial: 'idle', | |
context: { | |
direction: undefined, | |
path: '/history', | |
lastAllowedLocation: '/history', | |
mandatoryTagging: false, | |
communication: undefined | |
}, | |
states: { | |
idle: { | |
id: 'idle', | |
on: { | |
MAKE_OUTBOUND_CALL: 'ringing.outbound' | |
// RECEIVE_INCOMING_CALL_V2: { | |
// target: 'ringing.inbound', | |
// actions: ['initInboundFromV2'] | |
// }, | |
// /** | |
// * When we receive an inbound call from routing v1 (twilio), | |
// * twilio will handle for us start and stop ringing logic | |
// * so no need to do anything. | |
// */ | |
// RECEIVE_INCOMING_CALL_V1: { | |
// target: 'ringing.inbound', | |
// actions: ['initInboundFromV1'] | |
// } | |
} | |
}, | |
ringing: { | |
states: { | |
outbound: { | |
entry: ['startOutgoingTone'], | |
exit: ['stopOutgoingTone'], | |
invoke: { | |
id: 'initiateOutbound', | |
src: 'initiateOutbound', | |
onDone: { | |
actions: ['redirectToRingingView', 'logActiveConnection'] | |
} | |
}, | |
on: { | |
EXTERNAL_ACCEPT: '#incall', | |
// If the user makes an outbound call | |
// he'll not receive an external cancel | |
// instead he'll receive a CALL_DISCONNECT EVENT | |
CALL_DISCONNECT: '#disconnecting' | |
} | |
} | |
}, | |
on: { | |
AGENT_HANG_UP: { | |
target: 'idle', | |
actions: [ | |
'hangupFromRinging', | |
'resetCommunication', | |
'redirectToPreviousView', | |
'logActiveConnection' | |
] | |
} | |
} | |
}, | |
incall: { | |
id: 'incall', | |
entry: 'redirectToInCallView', | |
on: { | |
AGENT_HANG_UP: { | |
// This is a valid transition but which doesn't transition | |
// to any other state | |
target: undefined, | |
actions: ['stopCall', 'logActiveConnection'] | |
}, | |
CALL_DISCONNECT: 'disconnecting', | |
RECEIVE_INCOMING_CALL_V2: { | |
// This is not a valid transition | |
target: undefined, | |
actions: ['softDecline'] | |
} | |
} | |
}, | |
disconnecting: { | |
id: 'disconnecting', | |
exit: ['logActiveConnection'], | |
invoke: { | |
id: 'disconnecting', | |
src: 'disconnecting', | |
onDone: '#endcall', | |
onError: '#fail' | |
} | |
}, | |
endcall: { | |
id: 'endcall', | |
entry: ['redirectToCallEndedView', 'resetCommunication', 'logActiveConnection'], | |
after: { | |
5000: 'idle' | |
} | |
}, | |
fail: { | |
id: 'fail', | |
entry: [ | |
'hangupFromRinging', | |
'resetCommunication', | |
'redirectToPreviousView', | |
'logActiveConnection' | |
], | |
always: 'idle' | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment