Last active
December 3, 2020 16:14
-
-
Save karkowg/58e6769261451a5d656e9854c497dacc to your computer and use it in GitHub Desktop.
Revisions
-
karkowg revised this gist
Dec 3, 2020 . 1 changed file with 24 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -71,7 +71,7 @@ const webcastMachine = { on: { '': [ { target: 'starting', cond: 'isStarting' }, { target: 'pre', cond: 'isPre' }, { target: 'preparing', cond: 'isPreparing' }, { target: 'idle' }, ], @@ -111,23 +111,29 @@ const webcastMachine = { } }, }, mediaLive: { initial: 'default', states: { default: { on: { '': [ { target: 'ready', cond: 'isMediaLiveReady' }, { target: 'preparing', cond: 'isPreparingMediaLive' }, { target: 'idle' }, ], }, }, idle: { on: { PREPARE_WEBCAST: 'preparing', }, }, preparing: { on: { ML_CHANNEL_READY: { target: 'ready', actions: assign({ isMediaLiveReady: true, }), }, }, @@ -140,12 +146,12 @@ const webcastMachine = { }, on: { READY: { target: 'pre', cond: ctx => [ctx.isPexipReady, ctx.isMediaLiveReady].every(Boolean), }, }, }, pre: { on: { GO_LIVE: 'starting', }, @@ -229,11 +235,12 @@ const makeControlRoomMachine = event => Machine({ countdownCounter: undefined, elapsed: undefined, hasFinished: event.event_mode === 'after', isLive: event.event_mode === 'live', isMediaLiveReady: event.media_live_state === 'ready', isPexipReady: event.pexip_state === 'ready', isPreparing: event.event_mode === 'preparing', isPreparingMediaLive: event.media_live_state === 'preparing', isPre: event.event_mode === 'pre', isStarting: event.event_mode === 'starting', startedAt: event.start_timecode ?? null, uid: event.uid, @@ -275,17 +282,18 @@ const makeControlRoomMachine = event => Machine({ guards: { hasFinished: ctx => ctx.hasFinished, isLive: ctx => ctx.isLive, isMediaLiveReady: ctx => ctx.isMediaLiveReady, isPexipReady: ctx => ctx.isPexipReady, isPreparing: ctx => ctx.isPreparing, isPreparingMediaLive: ctx => ctx.isPreparingMediaLive, isPre: ctx => ctx.isPre, isStarting: ctx => ctx.isStarting, }, }); makeControlRoomMachine({ uid: 'abc123', event_mode: 'preparing', pexip_state: 'ready', media_live_state: 'idle', }); -
karkowg revised this gist
Dec 2, 2020 . 1 changed file with 71 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -83,8 +83,66 @@ const webcastMachine = { }, }, preparing: { type: 'parallel', states: { pexip: { initial: 'default', states: { default: { on: { '': [ { target: 'ready', cond: 'isPexipReady' }, { target: 'preparing' }, ], }, }, preparing: { on: { PEXIP_VA_READY: { target: 'ready', actions: assign({ isPexipReady: true, }), }, }, }, ready: { type: 'final', } }, }, medialive: { initial: 'default', states: { default: { on: { '': [ { target: 'ready', cond: 'isMLReady' }, { target: 'preparing' }, ], }, }, preparing: { on: { ML_CHANNEL_READY: { target: 'ready', actions: assign({ isMLReady: true, }), }, }, }, ready: { type: 'final', }, }, }, }, on: { READY: { target: 'ready', cond: ctx => [ctx.isPexipReady, ctx.isMLReady].every(Boolean), }, }, }, ready: { @@ -100,11 +158,12 @@ const webcastMachine = { on: { COUNTDOWN: { actions: 'setLiveContext', target: '#countdown', }, }, }, countdown: { id: 'countdown', invoke: { id: 'countdown', src: (ctx) => makeCountdownMachine(ctx.countdownCounter), @@ -170,6 +229,8 @@ const makeControlRoomMachine = event => Machine({ countdownCounter: undefined, elapsed: undefined, hasFinished: event.event_mode === 'after', isPexipReady: event.isPexipReady, isMLReady: event.isMLReady, isLive: event.event_mode === 'live', isReady: event.event_mode === 'ready', isPreparing: event.event_mode === 'preparing', @@ -215,9 +276,16 @@ const makeControlRoomMachine = event => Machine({ hasFinished: ctx => ctx.hasFinished, isLive: ctx => ctx.isLive, isPreparing: ctx => ctx.isPreparing, isPexipReady: ctx => ctx.isPexipReady, isMLReady: ctx => ctx.isMLReady, isStarting: ctx => ctx.isStarting, isReady: ctx => ctx.isReady, }, }); makeControlRoomMachine({ uid: 'abc123', event_mode: 'preparing', isPexipReady: false, isMLReady: false, }); -
karkowg revised this gist
Dec 1, 2020 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -100,12 +100,11 @@ const webcastMachine = { on: { COUNTDOWN: { actions: 'setLiveContext', target: 'countdown', }, }, }, countdown: { invoke: { id: 'countdown', src: (ctx) => makeCountdownMachine(ctx.countdownCounter), -
karkowg revised this gist
Dec 1, 2020 . 1 changed file with 63 additions and 104 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -54,43 +54,68 @@ const makeCountdownMachine = counter => Machine({ const webcastMachine = { id: 'webcast', initial: 'default', states: { default: { on: { '': [ { target: 'live', cond: 'isLive' }, { target: 'upcoming' }, ], }, }, upcoming: { initial: 'default', states: { default: { on: { '': [ { target: 'starting', cond: 'isStarting' }, { target: 'ready', cond: 'isReady' }, { target: 'preparing', cond: 'isPreparing' }, { target: 'idle' }, ], }, }, idle: { on: { PREPARE: 'preparing', }, }, preparing: { on: { READY: 'ready', }, }, ready: { on: { GO_LIVE: 'starting', }, }, starting: { invoke: { id: 'goLive', src: ctx => goLive(ctx.uid), }, on: { COUNTDOWN: { actions: 'setLiveContext', target: '#countdown', }, }, }, countdown: { id: 'countdown', invoke: { id: 'countdown', src: (ctx) => makeCountdownMachine(ctx.countdownCounter), onDone: '#live', }, on: { 'COUNTDOWN.UPDATE': { actions: 'setCountdownCounter', }, }, }, }, }, @@ -105,7 +130,6 @@ const webcastMachine = { actions: 'setViewingSessionStats', }, STOP_LIVE: 'after', }, invoke: [ // { id: 'elapsed', src: ctx => makeElapsedMachine(ctx.startedAt) }, @@ -136,100 +160,21 @@ const webcastMachine = { target: '#controlRoom.done', }, }, }, }, }; const makeControlRoomMachine = event => Machine({ id: 'controlRoom', initial: 'default', context: { countdownCounter: undefined, elapsed: undefined, hasFinished: event.event_mode === 'after', isLive: event.event_mode === 'live', isReady: event.event_mode === 'ready', isPreparing: event.event_mode === 'preparing', isStarting: event.event_mode === 'starting', startedAt: event.start_timecode ?? null, uid: event.uid, viewingSessions: { @@ -239,10 +184,17 @@ const makeControlRoomMachine = event => Machine({ }, }, states: { default: { on: { '': [ { target: 'done', cond: 'hasFinished' }, { target: 'interactive' }, ], }, }, interactive: { type: 'parallel', states: { webcast: { ...webcastMachine }, }, }, @@ -252,14 +204,21 @@ const makeControlRoomMachine = event => Machine({ }, }, { actions: { setCountdownCounter: assign({ countdownCounter: (ctx, event) => event.counter }), setElapsed: assign({ elapsed: (ctx, event) => event.elapsed }), setLiveContext: assign({ startedAt: (ctx, event) => dayjs(event.starts_at), countdownCounter: (ctx, event) => event?.countdown ?? 10, }), setViewingSessionStats: assign({ viewingSessions: (ctx, event) => event.viewingSessions }), }, guards: { hasFinished: ctx => ctx.hasFinished, isLive: ctx => ctx.isLive, isPreparing: ctx => ctx.isPreparing, isStarting: ctx => ctx.isStarting, isReady: ctx => ctx.isReady, }, }); makeControlRoomMachine({ uid: 'abc123', event_mode: 'pre' }); -
karkowg revised this gist
Nov 27, 2020 . 1 changed file with 75 additions and 74 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,31 +2,56 @@ function dayjs() { return new Date(); } function goLive(uid) { return Promise.resolve({ startedAt: dayjs() }); } function stopLive(uid) { return Promise.resolve(); } const makeCountdownMachine = counter => Machine({ id: 'countdown', initial: 'running', context: { counter, }, states: { running: { invoke: { id: 'countdownInterval', src: () => callback => { const intervalId = setInterval(() => { callback('TICK'); }, 1000); return () => clearInterval(intervalId); }, }, on: { '': { target: 'done', cond: ctx => ctx.counter <= 0, }, TICK: { actions: ['decrement', 'notify'], }, }, }, done: { type: 'final', }, }, }, { actions: { decrement: assign({ counter: ctx => ctx.counter - 1 }), notify: sendParent(ctx => ({ type: 'COUNTDOWN.UPDATE', counter: ctx.counter, })), }, }); const webcastMachine = { id: 'webcast', initial: 'pre', @@ -41,41 +66,51 @@ const webcastMachine = { }, preparingInfra: { on: { INFRA_READY: 'ready', }, }, ready: { entry: 'setInfraReady', on: { GO_LIVE: 'preparingLive', }, }, preparingLive: { invoke: { id: 'goLive', src: ctx => goLive(ctx.uid), onDone: { actions: 'setLiveContext', target: 'countdown', }, }, }, countdown: { invoke: { id: 'countdown', src: () => makeCountdownMachine(10), onDone: '#live', }, }, }, }, live: { id: 'live', initial: 'streaming', on: { 'ELAPSED.UPDATE': { actions: 'setElapsed', }, 'STATS.UPDATE': { actions: 'setViewingSessionStats', }, STOP_LIVE: 'after', PING: '#live', }, invoke: [ // { id: 'elapsed', src: ctx => makeElapsedMachine(ctx.startedAt) }, // { id: 'stats', src: ctx => makeStatsMachine(ctx.uid) }, ], states: { playback: { on: { @@ -90,7 +125,10 @@ const webcastMachine = { }, }, after: { actions: [ send('DONE', { to: 'elapsed' }), send('DONE', { to: 'stats' }), ], invoke: { id: 'stopLive', src: ctx => stopLive(ctx.uid), @@ -186,52 +224,14 @@ const userMachine = { }, }; const makeControlRoomMachine = event => Machine({ id: 'controlRoom', initial: 'interactive', context: { elapsed: undefined, isInfraReady: false, startedAt: event.start_timecode ?? null, uid: event.uid, viewingSessions: { online: 0, peak: 0, @@ -252,13 +252,14 @@ const createControlRoomMachine = ({ uid }) => Machine({ }, }, { actions: { setElapsed: assign({ elapsed: (ctx, event) => event.elapsed }), setInfraReady: assign({ isInfraReady: true }), setLiveContext: assign({ startedAt: (ctx, event) => dayjs(event.data.start_timecode) }), setViewingSessionStats: assign({ viewingSessions: (ctx, event) => event.viewingSessions }), }, guards: { isInfraReady: ctx => ctx.isInfraReady, }, }); makeControlRoomMachine({ uid: 'abc123' }); -
karkowg revised this gist
Nov 25, 2020 . 1 changed file with 78 additions and 16 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,13 +2,28 @@ function dayjs() { return new Date(); } function randomInt(max) { return Math.floor(Math.random() * Math.floor(max)); } function getViewingSessionsStats(uid) { console.log('getViewingSessionsStats', { uid }); return Promise.resolve({ data: { online: randomInt(100), total: randomInt(100), peak: randomInt(100), }, }); } function goLive(uid) { console.log('goLive', { uid }); return Promise.resolve({ startedAt: dayjs() }); } function stopLive(uid) { console.log('stopLive', { uid }); return Promise.resolve(); } @@ -52,30 +67,38 @@ const webcastMachine = { id: 'live', initial: 'streaming', on: { SET_VIEWING_SESSION_STATS: { actions: ['setViewingSessionStats'], }, STOP_LIVE: 'after', }, invoke: { id: 'stats', src: ctx => createViewingSessionsStatsMachine(ctx.uid), }, states: { playback: { on: { STOP_VIDEO: 'streaming', }, }, streaming: { on: { PLAY_VIDEO: 'playback', }, }, }, }, after: { actions: send('DONE', { to: 'stats' }), invoke: { id: 'stopLive', src: ctx => stopLive(ctx.uid), onDone: { target: '#controlRoom.done', }, }, type: 'final', }, }, }; @@ -163,24 +186,64 @@ const userMachine = { }, }; const createViewingSessionsStatsMachine = uid => Machine({ id: 'stats', initial: 'idle', context: { uid }, states: { idle: { after: { TIMER: 'fetching', }, on: { DONE: 'done', }, }, fetching: { on: { DONE: 'done', }, invoke: { id: 'refreshStats', src: ctx => getViewingSessionsStats(ctx.uid), onDone: { target: 'idle', actions: 'sendStats', }, }, }, done: { type: 'final', }, } }, { actions: { sendStats: sendParent((ctx, event) => ({ type: 'SET_VIEWING_SESSION_STATS', viewingSessions: event.data.data })), }, delays: { TIMER: 10 * 1000, }, }); const createControlRoomMachine = ({ uid }) => Machine({ id: 'controlRoom', initial: 'interactive', context: { uid, isInfraReady: false, startedAt: null, viewingSessions: { online: 0, peak: 0, total: 0, }, }, states: { interactive: { type: 'parallel', states: { user: { ...userMachine }, webcast: { ...webcastMachine }, }, }, done: { @@ -190,9 +253,8 @@ const createControlRoomMachine = ({ uid }) => Machine({ }, { actions: { setInfraReady: assign({ isInfraReady: true }), setLiveContext: assign({ startedAt: (ctx, event) => event.data.startedAt }), setViewingSessionStats: assign({ viewingSessions: (ctx, event) => event.viewingSessions }), }, guards: { isInfraReady: ctx => ctx.isInfraReady, -
karkowg revised this gist
Nov 24, 2020 . 1 changed file with 42 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,17 @@ function dayjs() { return new Date(); } // TODO function goLive(uid) { return Promise.resolve({ startedAt: dayjs() }); } // TODO function stopLive(uid) { return Promise.resolve(); } const webcastMachine = { id: 'webcast', initial: 'pre', @@ -16,10 +30,20 @@ const webcastMachine = { }, }, ready: { entry: ['setInfraReady'], on: { GO_LIVE: 'goingLive', }, }, goingLive: { type: 'final', invoke: { id: 'goLive', src: ctx => goLive(ctx.uid), onDone: { target: '#live', actions: 'setLiveContext', }, }, }, }, @@ -45,8 +69,12 @@ const webcastMachine = { }, after: { type: 'final', invoke: { id: 'stopLive', src: ctx => stopLive(ctx.uid), onDone: { target: '#controlRoom.done', }, }, }, }, @@ -135,11 +163,13 @@ const userMachine = { }, }; const createControlRoomMachine = ({ uid }) => Machine({ id: 'controlRoom', initial: 'interactive', context: { uid, isInfraReady: false, startedAt: null, }, states: { interactive: { @@ -159,11 +189,14 @@ const controlRoomMachine = Machine({ }, }, { actions: { setInfraReady: assign({ isInfraReady: true }), setLiveContext: assign({ startedAt: (ctx, event) => event.data.startedAt, }), }, guards: { isInfraReady: ctx => ctx.isInfraReady, }, }); createControlRoomMachine({ uid: 'abc123' }); -
karkowg revised this gist
Nov 20, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -145,12 +145,12 @@ const controlRoomMachine = Machine({ interactive: { type: 'parallel', states: { user: { ...userMachine, }, webcast: { ...webcastMachine, }, }, }, done: { -
karkowg created this gist
Nov 20, 2020 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,169 @@ const webcastMachine = { id: 'webcast', initial: 'pre', states: { pre: { initial: 'idle', states: { idle: { on: { PREPARE_INFRA: 'preparingInfra', }, }, preparingInfra: { on: { INFRA_READY: 'ready' }, }, ready: { type: 'final', entry: ['setInfraReady'], on: { GO_LIVE: '#live', }, }, }, }, live: { id: 'live', initial: 'streaming', on: { STOP_LIVE: 'after', }, states: { streaming: { on: { PLAY_VIDEO: 'playback', }, }, playback: { on: { STOP_VIDEO: 'streaming', }, }, }, }, after: { type: 'final', on: { '': '#controlRoom.done', }, }, }, }; const userMachine = { initial: 'disconnected', states: { disconnected: { on: { CONNECT: { target: 'connected', cond: 'isInfraReady', }, }, }, connected: { type: 'parallel', on: { DISCONNECT: 'disconnected', }, states: { audio: { initial: 'disabled', states: { enabled: { on: { TOGGLE_AUDIO: 'disabled', MUTE: 'disabled', }, }, disabled: { on: { TOGGLE_AUDIO: 'enabled', }, }, }, }, video: { initial: 'disabled', states: { enabled: { on: { TOGGLE_VIDEO: 'disabled', }, }, disabled: { on: { TOGGLE_VIDEO: 'enabled', }, }, }, }, screenSharing: { initial: 'inactive', states: { active: { on: { TOGGLE_SCREEN_SHARING: 'inactive', }, }, inactive: { on: { TOGGLE_SCREEN_SHARING: 'active', }, }, }, }, spotlight: { initial: 'inactive', states: { active: { on: { TOGGLE_SPOTLIGHT: 'inactive', }, }, inactive: { on: { TOGGLE_SPOTLIGHT: 'active', }, }, }, }, }, }, }, }; const controlRoomMachine = Machine({ id: 'controlRoom', initial: 'interactive', context: { isInfraReady: false, }, states: { interactive: { type: 'parallel', states: { webcast: { ...webcastMachine, }, user: { ...userMachine, }, }, }, done: { type: 'final', }, }, }, { actions: { setInfraReady: assign({ isInfraReady: true, }), }, guards: { isInfraReady: context => context.isInfraReady, }, });