From 7ece8e44162f88de85c81c4a6777541e5882bc31 Mon Sep 17 00:00:00 2001 From: Lamp Date: Fri, 9 Nov 2018 12:45:35 -0800 Subject: [PATCH] improve MPP client websocket message tapping method to potentially fix datacollector not working --- src/lib/Client.js | 2 +- src/mppbridger/datacollector.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/lib/Client.js b/src/lib/Client.js index bcbb3c7..34f6d66 100755 --- a/src/lib/Client.js +++ b/src/lib/Client.js @@ -85,7 +85,6 @@ Client.prototype.connect = function() { this.ws = new WebSocket(this.uri); } this.ws.binaryType = "arraybuffer"; - this.emit("ws created"); var self = this; this.ws.addEventListener("close", function(evt) { self.user = undefined; @@ -138,6 +137,7 @@ Client.prototype.connect = function() { self.emit("status", "Joining channel..."); }); this.ws.addEventListener("message", function(evt) { + self.emit("message", evt); if(typeof evt.data !== 'string') return; var transmission = JSON.parse(evt.data); for(var i = 0; i < transmission.length; i++) { diff --git a/src/mppbridger/datacollector.js b/src/mppbridger/datacollector.js index f6ee822..fd82367 100644 --- a/src/mppbridger/datacollector.js +++ b/src/mppbridger/datacollector.js @@ -4,15 +4,13 @@ module.exports = async function(gClient, site, room, DiscordChannel) { var filepath = path + "/" + filename; var size = 0; var startDate = new Date(); - gClient.on('ws created', function(){ - gClient.ws.addEventListener('message', msg => { - var data = msg.data; - if (data instanceof ArrayBuffer) data = Buffer.from(data).toString('base64'); - var line = `${Date.now()} ${data}\n`; - size += line.length; - fs.appendFile(filepath, line, ()=>{}); - if (size > 8000000) {save(); size = 0;} - }); + gClient.on('message', function(){ + var data = msg.data; + if (data instanceof ArrayBuffer) data = Buffer.from(data).toString('base64'); + var line = `${Date.now()} ${data}\n`; + size += line.length; + fs.appendFile(filepath, line, ()=>{}); + if (size > 8000000) {save(); size = 0;} }); async function save(callback){ console.log(`saving data recording`, filename)