Skip to content

Commit 2844b67

Browse files
committed
added commanderror event and updated readme
1 parent eb5eb70 commit 2844b67

2 files changed

Lines changed: 14 additions & 6 deletions

File tree

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ server.systemUpdate('subsystem');
4444
#### Server
4545

4646
##### Methods
47+
48+
- **constructor** *(cmdHandler)*
49+
50+
Constructor of hte mpd server. The command handler function is responsible to handle all [commands](https://www.musicpd.org/doc/html/protocol.html#command-reference) send by the clients. The only exception here is the `idle`. This command is handled internally. This function must return a promise which resolves to the response for the client.
51+
4752
- **listen** *(options)*
4853

4954
Start listening for clients. The options are passed to the [server listen](https://nodejs.org/api/net.html#net_server_listen_options_callback).
@@ -68,13 +73,20 @@ Notify a subsystem update.
6873
- **disconnect** *(connection)*
6974
- **idle** *(connection)*
7075

71-
Emitted when the connection is going in to idle mode as describe [here](https://www.musicpd.org/doc/protocol/command_reference.html).
76+
Emitted when the connection is going in to idle mode as describe [here](https://www.musicpd.org/doc/html/protocol.html#querying-mpd-s-status).
7277

7378
- **noidle** *(connection)*
7479

7580
Emitted when the connection exits the idle mode.
7681

7782
- **error** *(error, connection)*
83+
84+
Emitted on socket error event.
85+
86+
- **commanderror** *(error, connection, errorAck)*
87+
88+
Emitted when a command handler failed. The third parameter is the error response as described in the [protocol](https://www.musicpd.org/doc/html/protocol.html#failure-responses).
89+
7890
- **system** *(subsystem, connection)*
7991

8092
Emitted when a subsytem update is send.

connection.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@ module.exports = function (socket, cmdHandler) {
9393
let errorCode = err.code || 5;
9494
let errorMsg = err.msg || err;
9595
let resp = `ACK [${errorCode}@${i}] {${command}} ${errorMsg}\n`;
96-
console.log(resp);
9796
socket.write(resp);
9897

99-
socket.on('error', err => {
100-
con.emit('error', err, con);
101-
});
102-
98+
con.emit('commanderror', err, con, resp);
10399
return; // stop proccesing other commands from list
104100
}
105101
}

0 commit comments

Comments
 (0)