import { Box } from '../../classes/display/box.js'; import { Scene } from '../../classes/display/scene.js'; import { Actor } from '../../classes/display/actor.js'; import { Action } from '../../classes/display/action.js'; const rootElement = document.getElementById('basic'); const rootBox = new Box('rootBox', rootElement).flex(); function randomDelay(min, max) { const delayMs = min + Math.random() * max; return delayMs; } (function run() { const scene = new Scene('Scene 1', rootBox).withSequenceDiagram(); const webClientStatus = scene.addDisplayValue('WebClient Status'); const node1Status = scene.addDisplayValue('Node 1 Status'); const blockchainStatus = scene.addDisplayValue('Blockchain Status'); const webClient = new Actor('web client', scene); const node1 = new Actor('node 1', scene); const blockchain = new Actor('blockchain', scene); const requestForumPage = new Action('requestForumPage', scene); const readBlockchainData = new Action('readBlockchainData', scene); const blockchainData = new Action('blockchainData', scene); const forumPage = new Action('forumPage', scene); webClientStatus.set('Initialized'); node1Status.set('Idle'); blockchainStatus.set('Idle'); node1.on(requestForumPage, (src, detail) => { node1Status.set('Processing request'); node1.on(blockchainData, (_src, data) => { node1Status.set('Processing response'); setTimeout(() => { node1.send(src, forumPage, data); node1Status.set('Idle'); }, randomDelay(500, 1000)); }); setTimeout(() => { node1.send(blockchain, readBlockchainData, detail); }, randomDelay(500, 1500)); }); blockchain.on(readBlockchainData, (src, _detail) => { blockchainStatus.set('Processing request'); setTimeout(() => { blockchain.send(src, blockchainData, {}); blockchainStatus.set('Idle'); }, randomDelay(500, 1500)); }); webClient.on(forumPage, (_src, _detail) => { webClientStatus.set('Received forum page'); }); setTimeout(() => { webClient.send(node1, requestForumPage); webClientStatus.set('Requested forum page'); }, randomDelay(500, 1500)); setInterval(() => { webClient.send(node1, requestForumPage); webClientStatus.set('Requested forum page'); }, randomDelay(6000, 12000)); }());