From a3814e6de02bb6deaced3e13c2fb9541a221db8e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 23 Jul 2023 09:10:01 +0700 Subject: [PATCH] code output --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 9988598..0808592 100644 --- a/index.js +++ b/index.js @@ -31,7 +31,16 @@ io.on('connection', (socket) => { functions = {} for (const eachFuntion of parsed) { - functions[eachFuntion] = (...args) => socket.emit(BRIDGE_PREFIX + eachFuntion, ...args) + functions[eachFuntion] = (...args) => { + socket.emit(BRIDGE_PREFIX + eachFuntion, ...args) + + return new Promise((resolve) => { + socket.once(`functionOutput:${eachFuntion}`, (message, parseJSON) => { + if (parseJSON) resolve(JSON.parse(message)) + else resolve(message) + }) + }) + } } proxy = new Proxy(functions, handler)