Skip to content

Instantly share code, notes, and snippets.

@kellyjandrews
Last active June 26, 2020 13:28
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 kellyjandrews/fe2594ef509e7af16229b10d2456ed93 to your computer and use it in GitHub Desktop.
Save kellyjandrews/fe2594ef509e7af16229b10d2456ed93 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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