xjs = require('xjs'); function log(str) { document.getElementById("log").insertAdjacentHTML('beforeend', escapeHTML(str) + "<br>\n"); } function range(to) { return Array(to).fill().map((_, i) => i); } function escapeHTML(str) { return str.replace(/[&<>'"]/g, tag => ({ '&': '&', '<': '<', '>': '>', "'": ''', '"': '"' }[tag])); } async function go() { log("Starting"); await xjs.ready(); log("Ready"); const ws = new WebSocket('ws://localhost:8080'); ws.onmessage = msg => { const data = JSON.parse(msg.data); log(JSON.stringify(data)); } ws.onopen = async () => { log("Socket open"); const sceneCount = await xjs.Scene.getSceneCount(); log(`Scenes: ${sceneCount}`); const scenes = await Promise.all(range(sceneCount).map(i => xjs.Scene.getBySceneIndex(i))); const sceneNames = await Promise.all(scenes.map(s => s.getName())); log(sceneNames); ws.send(JSON.stringify({scenes: sceneNames})); } } go();