improve MPP client websocket message tapping method

to potentially fix datacollector not working
This commit is contained in:
Lamp 2018-11-09 12:45:35 -08:00
parent 982f187f6b
commit 7ece8e4416
No known key found for this signature in database
GPG Key ID: 0F1F8704BEDE369E
2 changed files with 8 additions and 10 deletions

View File

@ -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++) {

View File

@ -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)