Skip to content

Instantly share code, notes, and snippets.

@kellyjandrews
Last active June 26, 2020 21:40
Show Gist options
  • Save kellyjandrews/06496059c816b94afff35c66c007cd9c to your computer and use it in GitHub Desktop.
Save kellyjandrews/06496059c816b94afff35c66c007cd9c to your computer and use it in GitHub Desktop.

Revisions

  1. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 15 additions and 14 deletions.
    29 changes: 15 additions & 14 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    let promise = new Promise(function(resolve, reject) {
    return setTimeout(() => resolve("done"), 1000);
    const promise = (ctx, e) => new Promise((resolve, reject) => {
    console.log('got called')
    resolve('done');
    });

    const opentokMachine = Machine({
    @@ -14,26 +15,25 @@ const opentokMachine = Machine({
    initial: 'init',
    states: {
    init: {
    entry: [
    'initSession',
    'initPublisher'
    ],
    invoke: {
    id: 'getToken',
    src: 'getToken',
    src: 'invokeGetToken',
    onDone: {
    actions: () => console.log('get token')
    target: "ready",
    actions: 'logToken'
    }
    }
    },
    entry: [
    'initSession',
    'initPublisher'
    ]
    },
    ready: {
    on: {
    'JOIN': '#connected'
    }
    },
    teardown: {

    }
    teardown: {}
    }
    },
    connected: {
    @@ -45,11 +45,12 @@ const opentokMachine = Machine({
    }
    }, {
    actions:{
    logToken: (ctx, e) => console.log('get token'),
    initSession: (ctx, e) => console.log('initSession'),
    initPublisher: (ctx, e) => console.log('initPublisher')
    },
    service: {
    getToken: async (ctx, e) => await promise()
    services: {
    invokeGetToken: async (ctx, e) => await promise()
    }
    }
    );
  2. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 13 additions and 5 deletions.
    18 changes: 13 additions & 5 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    const getToken = (ctx, e) => new Promise((res, rej) => {
    return setTimeout(res(console.log('getToken')), 500);
    let promise = new Promise(function(resolve, reject) {
    return setTimeout(() => resolve("done"), 1000);
    });

    const opentokMachine = Machine({
    @@ -15,10 +15,16 @@ const opentokMachine = Machine({
    states: {
    init: {
    entry: [
    'getToken',
    'initSession',
    'initPublisher'
    ]
    ],
    invoke: {
    id: 'getToken',
    src: 'getToken',
    onDone: {
    actions: () => console.log('get token')
    }
    }
    },
    ready: {
    on: {
    @@ -39,9 +45,11 @@ const opentokMachine = Machine({
    }
    }, {
    actions:{
    getToken: getToken,
    initSession: (ctx, e) => console.log('initSession'),
    initPublisher: (ctx, e) => console.log('initPublisher')
    },
    service: {
    getToken: async (ctx, e) => await promise()
    }
    }
    );
  3. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion machine.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    const getToken = (ctx, e) => new Promise((res, rej) => {
    return setTimeout(res(console.log('getToken')), 500);
    });

    const opentokMachine = Machine({
    id: 'opentok',
    @@ -36,7 +39,7 @@ const opentokMachine = Machine({
    }
    }, {
    actions:{
    getToken: (ctx, e) => console.log('getting token'),
    getToken: getToken,
    initSession: (ctx, e) => console.log('initSession'),
    initPublisher: (ctx, e) => console.log('initPublisher')
    }
  4. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,11 @@ const opentokMachine = Machine({
    initial: 'init',
    states: {
    init: {
    entry: ['getToken']
    entry: [
    'getToken',
    'initSession',
    'initPublisher'
    ]
    },
    ready: {
    on: {
    @@ -32,7 +36,9 @@ const opentokMachine = Machine({
    }
    }, {
    actions:{
    getToken: (ctx, e) => console.log('getting token')
    getToken: (ctx, e) => console.log('getting token'),
    initSession: (ctx, e) => console.log('initSession'),
    initPublisher: (ctx, e) => console.log('initPublisher')
    }
    }
    );
  5. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 11 additions and 7 deletions.
    18 changes: 11 additions & 7 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -2,33 +2,37 @@
    const opentokMachine = Machine({
    id: 'opentok',
    initial: 'disconnected',
    context: {},
    context: {
    sessionId: null
    },
    states: {
    disconnected: {
    id: 'disconnected',
    initial: 'ready',
    initial: 'init',
    states: {
    coming: {

    init: {
    entry: ['getToken']
    },
    ready: {
    on: {
    'JOIN': '#connected'
    }
    },
    going: {
    teardown: {

    }
    }
    },
    connected: {
    id: 'connected',
    on: {
    'DISCONNECT': '#disconnected.going'
    'DISCONNECT': '#disconnected.teardown'
    }
    }
    }
    }, {
    actions:{}
    actions:{
    getToken: (ctx, e) => console.log('getting token')
    }
    }
    );
  6. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 18 additions and 4 deletions.
    22 changes: 18 additions & 4 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,31 @@

    const opentokMachine = Machine({
    id: 'openTok',
    id: 'opentok',
    initial: 'disconnected',
    context: {},
    states: {
    disconnected: {
    id: 'disconnected',
    on: {
    "CONNECT": 'connected'
    initial: 'ready',
    states: {
    coming: {

    },
    ready: {
    on: {
    'JOIN': '#connected'
    }
    },
    going: {

    }
    }
    },
    connected: {
    id: 'connected'
    id: 'connected',
    on: {
    'DISCONNECT': '#disconnected.going'
    }
    }
    }
    }, {
  7. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -6,11 +6,6 @@ const opentokMachine = Machine({
    states: {
    disconnected: {
    id: 'disconnected',
    initial: 'idle',
    states: {
    idle: {},
    ready: {}
    },
    on: {
    "CONNECT": 'connected'
    }
  8. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -6,6 +6,11 @@ const opentokMachine = Machine({
    states: {
    disconnected: {
    id: 'disconnected',
    initial: 'idle',
    states: {
    idle: {},
    ready: {}
    },
    on: {
    "CONNECT": 'connected'
    }
  9. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 6 additions and 11 deletions.
    17 changes: 6 additions & 11 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -2,22 +2,17 @@
    const opentokMachine = Machine({
    id: 'openTok',
    initial: 'disconnected',
    context: {
    sessionId: null,
    name: null,
    token: null,
    session: null,
    publisher: null,
    streams: null
    },
    context: {},
    states: {
    disconnected: {
    id: 'disconnected',
    on: {
    "CREATE": 'create',
    "JOIN": 'join'
    "CONNECT": 'connected'
    }
    },
    connected: {}
    connected: {
    id: 'connected'
    }
    }
    }, {
    actions:{}
  10. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 4 additions and 22 deletions.
    26 changes: 4 additions & 22 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@

    const opentokMachine = Machine({
    id: 'meeting',
    id: 'openTok',
    initial: 'disconnected',
    context: {
    sessionId: null,
    @@ -17,27 +17,9 @@ const opentokMachine = Machine({
    "JOIN": 'join'
    }
    },
    create: {
    initial: 'pending',
    states: {
    pending: {
    invoke: {
    id: 'createSession',
    src: (ctx, e) => createSession(),
    onDone: {
    target: '#meeting.join'
    },
    onError: {
    target: 'failure'
    }
    }
    },
    failure: {}
    }
    },
    join: {},
    connected: {}
    }
    }, {
    actions:{}
    }
    );

    );
  11. kellyjandrews revised this gist Jun 26, 2020. No changes.
  12. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -22,6 +22,7 @@ const opentokMachine = Machine({
    states: {
    pending: {
    invoke: {
    id: 'createSession',
    src: (ctx, e) => createSession(),
    onDone: {
    target: '#meeting.join'
  13. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 8 additions and 6 deletions.
    14 changes: 8 additions & 6 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -21,12 +21,14 @@ const opentokMachine = Machine({
    initial: 'pending',
    states: {
    pending: {
    invoke: (ctx, e) => createSession(),
    onDone: {
    target: '#meeting.join'
    },
    onError: {
    target: 'failure'
    invoke: {
    src: (ctx, e) => createSession(),
    onDone: {
    target: '#meeting.join'
    },
    onError: {
    target: 'failure'
    }
    }
    },
    failure: {}
  14. kellyjandrews revised this gist Jun 26, 2020. 1 changed file with 17 additions and 3 deletions.
    20 changes: 17 additions & 3 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@

    const opentokMachine = Machine({
    id: 'meeting',
    initial: 'idle',
    initial: 'disconnected',
    context: {
    sessionId: null,
    name: null,
    @@ -11,13 +11,27 @@ const opentokMachine = Machine({
    streams: null
    },
    states: {
    idle: {
    disconnected: {
    on: {
    "CREATE": 'create',
    "JOIN": 'join'
    }
    },
    create: {},
    create: {
    initial: 'pending',
    states: {
    pending: {
    invoke: (ctx, e) => createSession(),
    onDone: {
    target: '#meeting.join'
    },
    onError: {
    target: 'failure'
    }
    },
    failure: {}
    }
    },
    join: {},
    connected: {}
    }
  15. kellyjandrews created this gist Jun 26, 2020.
    26 changes: 26 additions & 0 deletions machine.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@

    const opentokMachine = Machine({
    id: 'meeting',
    initial: 'idle',
    context: {
    sessionId: null,
    name: null,
    token: null,
    session: null,
    publisher: null,
    streams: null
    },
    states: {
    idle: {
    on: {
    "CREATE": 'create',
    "JOIN": 'join'
    }
    },
    create: {},
    join: {},
    connected: {}
    }
    }
    );