Last active
June 26, 2020 13:28
-
-
Save kellyjandrews/fe2594ef509e7af16229b10d2456ed93 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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 characters
const opentokMachine = Machine({ | |
id: 'meeting', | |
initial: 'entry', | |
context: { | |
sessionId: null, | |
name: null, | |
token: null, | |
session: null, | |
publisher: null, | |
streams: null | |
}, | |
states: { | |
entry: { | |
on: { | |
ADD_NAME: { | |
target: 'initialize', | |
actions: assign({ | |
name: (ctx, e) => e.name | |
}) | |
} | |
} | |
}, | |
initialize: { | |
initial: 'pending', | |
states: { | |
pending: { | |
invoke: { | |
id: 'createToken', | |
src: 'invokeCreateToken', | |
onDone: { | |
actions: 'assignToken' | |
} | |
}, | |
on: { | |
'': [ | |
{ actions: 'initPublisher', cond: (ctx) => !ctx.publisher }, | |
{ actions: 'initSession', cond: (ctx) => !ctx.session } | |
], | |
'PUBLISHER': { | |
target: '#meeting.connect', | |
actions: (ctx) => console.log("PULBISHER") | |
} | |
} | |
} | |
} | |
}, | |
connect: { | |
on: { | |
'' : {target: ''} | |
} | |
} | |
} | |
}, | |
{ | |
actions: { | |
assignToken: assign({ token: (ctx, e) => e.data.data.token }), | |
initPublisher: assign({ | |
publisher: ctx => { | |
let publisher = initPublisher({ insertDefaultUI: false, name: ctx.name }); | |
publisher.on('videoElementCreated', e => { | |
assign({ | |
publisherVideo: "123" | |
}) | |
}); | |
return publisher; | |
} | |
}), | |
initSession: assign({ | |
session: (ctx, e) => { | |
let session = initSession(REACT_APP_OPENTOK_APIKEY, ctx.sessionId); | |
session.on('streamCreated', e => { | |
// assign({ streams: ctx => ctx.push(session.subscribe(e.stream)) }); | |
}) | |
return session; | |
} | |
}) | |
}, | |
activities: {}, | |
services: { | |
invokeCreateToken: async (ctx) => await createToken(ctx.sessionId) | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment