or at least a separate file, that can be required within a module. This would help unify the code of the many different Proxy types currently available, and remove about 100 lines of code from each.
[x] Parser module create
[x] websocketserverproxy
[ ] websocketclientproxy
[ ] webserverproxy
[ ] webclientproxy
[ ] proxy
[ ] Nexus
[ ] Genesis
[ ] xgraphadapter
const EventEmitter = require('events').EventEmitter;
module.exports.StreamParser = class StreamParser extends EventEmitter{
constructor(stream) {
super();
this._stream = stream;
let buffer = '';
this._stream.on('data', async (data) => {
let parts = data.toString().split(/([\x02\x03])/g);
for (let part of parts) {
if (part === '\x02') {
buffer = '';
} else if (part === '\x03') {
try {
let cmd = JSON.parse(buffer);
this.emit('message', cmd)
} catch(e) {
console.log('Command Parse Error:\n', buffer);
}
} else {
buffer += part;
}
}
});
}
}
or at least a separate file, that can be required within a module. This would help unify the code of the many different Proxy types currently available, and remove about 100 lines of code from each.