From 5bf6ff6c790a08e91ddcb546bc284f863e769751 Mon Sep 17 00:00:00 2001 From: himyu Date: Thu, 14 Dec 2023 00:40:20 +0100 Subject: [PATCH] add namespace to functions to better accommodate more modules adn functions --- frontend/frontend.js | 28 +++++++++++++++++----------- frontend/index.html | 11 +++++++++++ plugin.ts | 7 ++++--- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/frontend/frontend.js b/frontend/frontend.js index 53850e9..bbf6807 100644 --- a/frontend/frontend.js +++ b/frontend/frontend.js @@ -11,7 +11,8 @@ document.querySelector('#addFunction').addEventListener('submit', (e) => { version: 1 }, function: document.querySelector('#function').value, - listener: document.querySelector('#listener').value + listener: document.querySelector('#listener').value, + namespace: document.querySelector('#namespace').value, }) }) @@ -34,19 +35,20 @@ function initSettings(settings) { document.querySelector('#port').value = settings.port } -function deleteFunction(id) { +function deleteFunction(id, namespace, listener) { window.LPTE.emit({ meta: { namespace: 'module-vmix', type: 'delete', version: 1 }, - id + id, + namespace, + listener }) } -function displayFucntionTable(data) { - console.log(data) +function displayFunctionTable(data) { if (data.functions === undefined) return functions.innerHTML = '' @@ -54,9 +56,13 @@ function displayFucntionTable(data) { data.functions.forEach((f) => { const row = document.createElement('tr') - const nameTd = document.createElement('td') - nameTd.innerText = f.listener - row.appendChild(nameTd) + const namespaceTd = document.createElement('td') + namespaceTd.innerText = f.namespace + row.appendChild(namespaceTd) + + const listenerTd = document.createElement('td') + listenerTd.innerText = f.listener + row.appendChild(listenerTd) const handleTd = document.createElement('td') handleTd.innerText = f.function @@ -67,7 +73,7 @@ function displayFucntionTable(data) { deleteBtn.classList.add('btn', 'btn-danger') deleteBtn.innerHTML = '' deleteBtn.onclick = () => { - deleteFunction(f.id) + deleteFunction(f.id, f.namespace, f.listener) } deleteTd.appendChild(deleteBtn) row.appendChild(deleteTd) @@ -84,9 +90,9 @@ window.LPTE.onready(async () => { version: 1 } }) - displayFucntionTable(data) + displayFunctionTable(data) - window.LPTE.on('module-vmix', 'update-vmix-set', displayFucntionTable) + window.LPTE.on('module-vmix', 'update-vmix-set', displayFunctionTable) const settings = await LPTE.request({ meta: { diff --git a/frontend/index.html b/frontend/index.html index 2e67236..0a7ee97 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -3,6 +3,7 @@

vMix

+ @@ -13,6 +14,16 @@

vMix

+
+ + +
{ id: e.id }) - ctx.LPTE.unregister(namespace, e.listener) + ctx.LPTE.unregister(e.namespace, e.listener) const res = await ctx.LPTE.request({ meta: { @@ -126,12 +126,13 @@ module.exports = async (ctx: PluginContext) => { }, collection: 'vmix', data: { + namespace: e.namespace, listener: e.listener, function: e.function } }) - ctx.LPTE.on(namespace, e.listener, async () => { + ctx.LPTE.on(e.namespace, e.listener, async () => { await executeFunc(e.function) }) @@ -209,7 +210,7 @@ module.exports = async (ctx: PluginContext) => { } res.data.forEach((f: any) => { - ctx.LPTE.on(namespace, f.listener, async () => { + ctx.LPTE.on(f.namespace, f.listener, async () => { await executeFunc(f.function) }) })
Namespace Listener Function