Skip to content

Commit

Permalink
Formatting mpd.js
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanBurunkov committed Dec 8, 2020
1 parent 1b76960 commit e3bd4ac
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/mpd.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = class MPD extends EventEmitter {
}

seek(songId, time) {
return this._sendCommand(`seek`, songId, time).then(r => this._answerCallbackError(r));
return this._sendCommand('seek', songId, time).then(r => this._answerCallbackError(r));
}

searchAdd(search) {
Expand Down Expand Up @@ -170,9 +170,9 @@ module.exports = class MPD extends EventEmitter {
this.playlist = [];
let songLines = [];
let pos;
for(let i = 0; i < lines.length - 1; i++) {
for (let i = 0; i < lines.length - 1; i += 1) {
let line = lines[i];
if (i !== 0 && line.startsWith('file:')) {
if (i !== 0 && line.startsWith(CONST_FILE_LINE_START)) {
this.playlist[pos] = new Song(songLines);
songLines = [];
pos = -1;
Expand All @@ -197,9 +197,9 @@ module.exports = class MPD extends EventEmitter {
let lines = message.split("\n");
this.songs = [];
let songLines = [];
for(let i = 0; i < lines.length - 1; i++) {
for (let i = 0; i < lines.length - 1; i += 1) {
let line = lines[i];
if(i !== 0 && line.startsWith(CONST_FILE_LINE_START)) {
if (i !== 0 && line.startsWith(CONST_FILE_LINE_START)) {
this.songs.push(new Song(songLines));
songLines = [];
}
Expand All @@ -216,15 +216,13 @@ module.exports = class MPD extends EventEmitter {
parseStatusResponse(message) {
let array = message.split("\n");
for (let i in array) {
let keyValue = array[i].split(":");
let keyValue = array[i].split(':');
if (keyValue.length < 2) {
if(array[i] !== "OK") {
if (array[i] !== 'OK') {
this.restoreConnection();
throw new Error("Unknown response while fetching status.");
}
else {
continue;
}
continue;
}
let key = keyValue[0].trim();
let value = keyValue[1].trim();
Expand Down Expand Up @@ -255,8 +253,8 @@ module.exports = class MPD extends EventEmitter {
break;
case "time":
this.status.time = {
elapsed : parseInt(keyValue[1]),
length : parseInt(keyValue[2])
elapsed: parseInt(keyValue[1]),
length: parseInt(keyValue[2])
};
break;
case "bitrate":
Expand All @@ -275,15 +273,15 @@ module.exports = class MPD extends EventEmitter {
* Idle handling
*/
_onMessage(message) {
try{
let match;
if(!(match = message.match(/changed:\s*(.*?)\s+OK/))) {
try {
const match = message.match(/changed:\s*(.*?)\s+OK/);
if (!match) {
this.restoreConnection();
throw new Error('Received unknown message during idle: ' + message);
}
this._enterIdle();
let updated = match[1];
let afterUpdate = () => {
const updated = match[1];
const afterUpdate = () => {
this.emit('update', updated);
this.emit('status', updated);
};
Expand Down Expand Up @@ -357,7 +355,7 @@ module.exports = class MPD extends EventEmitter {
this.buffer = this.buffer.substring(index, this.buffer.length);
if (this.idling) {
this._onMessage(string);
} else if(this.commanding) {
} else if (this.commanding) {
this._handleResponse(string);
}
}
Expand All @@ -368,7 +366,7 @@ module.exports = class MPD extends EventEmitter {
_enterIdle() {
this.idling = true;
this.commanding = false;
this._write("idle");
this._write('idle');
}

_leaveIdle(callback) {
Expand All @@ -377,7 +375,7 @@ module.exports = class MPD extends EventEmitter {
this.commanding = true;
callback();
});
this._write("noidle");
this._write('noidle');
}

_checkIdle() {
Expand Down

0 comments on commit e3bd4ac

Please sign in to comment.