Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions node-nut.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ class Nut extends EventEmitter {
this._client.on('data', data => {
this.dataInBuff += data;

if (this.dataInBuff.slice(-1) !== '\n') {
return;
if (this.list) {
if (this.dataInBuff.indexOf('END LIST') === -1) {
return;
}
} else {
if (this.dataInBuff.slice(-1) !== '\n') {
return;
}
}

if (typeof (this.parseFunc) === 'undefined') {
Expand All @@ -26,6 +32,7 @@ class Nut extends EventEmitter {
this.parseFunc(this.dataInBuff);
this.dataInBuff = '';
}
this.list = false;
});

this._client.on('error', err => {
Expand All @@ -47,6 +54,9 @@ class Nut extends EventEmitter {

send(cmd, parseFunc) {
if (this.status === 'idle') {
if (cmd.startsWith('LIST')) {
this.list = true;
}
this.status = 'waiting';
this.parseFunc = parseFunc;
this._client.write(cmd + '\n');
Expand Down Expand Up @@ -87,14 +97,15 @@ class Nut extends EventEmitter {
}

const dataArray = data.split('\n');

const vars = {};
for (const line of dataArray) {
if (line.indexOf('BEGIN LIST ' + listType) === 0) {
// ...
} else if (line.indexOf(listType + ' ') === 0) {
const matches = re.exec(line);
vars[matches[1]] = matches[2];
if (matches) {
vars[matches[1]] = matches[2];
}
} else if (line.indexOf('END LIST ' + listType) === 0) {
callback(vars, null);
break;
Expand Down Expand Up @@ -409,7 +420,6 @@ class Nut extends EventEmitter {
}

const dataArray = data.split('\n');

const re = /^CLIENT\s+.+\s+(.+)/;
const clients = [];
for (const line of dataArray) {
Expand Down
Loading