diff --git a/.gitignore b/.gitignore index b38069d..6167f22 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ build/Release # Dependency directory # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git node_modules + +config.json \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..59e18e4 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible Node.js debug attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceRoot}\\Bezerk.js", + "cwd": "${workspaceRoot}", + "env": { + "DEBUG": "bezerk*" + } + }, + { + "type": "node", + "request": "attach", + "name": "Attach to Process", + "port": 5858 + } + ] +} \ No newline at end of file diff --git a/Bezerk.js b/Bezerk.js index aef0525..a39ce81 100644 --- a/Bezerk.js +++ b/Bezerk.js @@ -20,9 +20,10 @@ BezerkWS.on('connection', (socket) => { function process (socket, message) { Logger('Attempting to process a message.') + Logger(message) let msg try { - JSON.parse(message) + msg = JSON.parse(message) } catch (e) { socket.close() Logger('Closing socket, invalid data received.') @@ -105,9 +106,9 @@ function process (socket, message) { } else { Logger('Request accepted, attempting to send data to subscribed listeners.') for (let listener of receivers) { - if (listener.indexOf(msg.c) > -1) { + if (listener.subscriptions.indexOf(msg.op) > -1 && listener.readyState === 1) { Logger('Sending data.') - listener.send(msg) + listener.send(JSON.stringify(msg)) } } } diff --git a/README.md b/README.md index 551e8e3..f4c31b5 100644 --- a/README.md +++ b/README.md @@ -11,5 +11,4 @@ ---