improve MPP client websocket message tapping method
to potentially fix datacollector not working
This commit is contained in:
parent
982f187f6b
commit
7ece8e4416
|
@ -85,7 +85,6 @@ Client.prototype.connect = function() {
|
||||||
this.ws = new WebSocket(this.uri);
|
this.ws = new WebSocket(this.uri);
|
||||||
}
|
}
|
||||||
this.ws.binaryType = "arraybuffer";
|
this.ws.binaryType = "arraybuffer";
|
||||||
this.emit("ws created");
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.ws.addEventListener("close", function(evt) {
|
this.ws.addEventListener("close", function(evt) {
|
||||||
self.user = undefined;
|
self.user = undefined;
|
||||||
|
@ -138,6 +137,7 @@ Client.prototype.connect = function() {
|
||||||
self.emit("status", "Joining channel...");
|
self.emit("status", "Joining channel...");
|
||||||
});
|
});
|
||||||
this.ws.addEventListener("message", function(evt) {
|
this.ws.addEventListener("message", function(evt) {
|
||||||
|
self.emit("message", evt);
|
||||||
if(typeof evt.data !== 'string') return;
|
if(typeof evt.data !== 'string') return;
|
||||||
var transmission = JSON.parse(evt.data);
|
var transmission = JSON.parse(evt.data);
|
||||||
for(var i = 0; i < transmission.length; i++) {
|
for(var i = 0; i < transmission.length; i++) {
|
||||||
|
|
|
@ -4,15 +4,13 @@ module.exports = async function(gClient, site, room, DiscordChannel) {
|
||||||
var filepath = path + "/" + filename;
|
var filepath = path + "/" + filename;
|
||||||
var size = 0;
|
var size = 0;
|
||||||
var startDate = new Date();
|
var startDate = new Date();
|
||||||
gClient.on('ws created', function(){
|
gClient.on('message', function(){
|
||||||
gClient.ws.addEventListener('message', msg => {
|
var data = msg.data;
|
||||||
var data = msg.data;
|
if (data instanceof ArrayBuffer) data = Buffer.from(data).toString('base64');
|
||||||
if (data instanceof ArrayBuffer) data = Buffer.from(data).toString('base64');
|
var line = `${Date.now()} ${data}\n`;
|
||||||
var line = `${Date.now()} ${data}\n`;
|
size += line.length;
|
||||||
size += line.length;
|
fs.appendFile(filepath, line, ()=>{});
|
||||||
fs.appendFile(filepath, line, ()=>{});
|
if (size > 8000000) {save(); size = 0;}
|
||||||
if (size > 8000000) {save(); size = 0;}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
async function save(callback){
|
async function save(callback){
|
||||||
console.log(`saving data recording`, filename)
|
console.log(`saving data recording`, filename)
|
||||||
|
|
Loading…
Reference in New Issue