diff --git a/src/server.js b/src/server.js index 145b80c..ec1f1cc 100644 --- a/src/server.js +++ b/src/server.js @@ -112,8 +112,8 @@ export default class extends EventEmitter { const { buttons, timestamps, instance } = activity; - const metadata = { buttons_urls: [] }; - const extra = { buttons: [] }; + const metadata = { }; + const extra = { }; if (buttons) { metadata.buttons_urls = buttons.map((button) => button.url); diff --git a/src/transports/ws.js b/src/transports/ws.js index 9d72f85..a595d46 100644 --- a/src/transports/ws.js +++ b/src/transports/ws.js @@ -3,7 +3,7 @@ import { parse } from "node:querystring"; const portRange = [6463, 6472]; const checkIfOpen = async (port) => { - new Promise((resolve) => { + return new Promise((resolve) => { const ws = new WebSocket(`ws://localhost:${port}`); ws.onopen = () => { diff --git a/test.js b/test.js new file mode 100644 index 0000000..aa881b2 --- /dev/null +++ b/test.js @@ -0,0 +1,33 @@ + +const portRange = [6463, 6472]; + +const checkIfOpen = async (port) => { + return new Promise((resolve) => { + const ws = new WebSocket(`ws://localhost:${port}`); + + ws.onopen = () => {console.log(1) + ws.close(); + resolve(true); + }; + + ws.onerror = () => { + resolve(false); + }; + }); +}; + +const getPort = async () => { + let port = portRange[0]; + + while (port <= portRange[1]) { + if (await checkIfOpen(port)) { + port++; + } else { + break; + } + } + + return port; +}; + +console.log(await getPort()); \ No newline at end of file