diff --git a/README.md b/README.md index 6b60bc7..65862b2 100644 --- a/README.md +++ b/README.md @@ -55,13 +55,18 @@ Here are some commands which can be sent to Kameleon Agent. #### cmd:list * `callback`: `` + * `err` : `` * `devices` : `>` Request a list of available devices (ready to open -- _already plugged to USB or discovered wirelessly_) connected via serial ports. ```js -socket_client.emit('cmd:list', (deviceObjects) => { - console.log(deviceObjects) +socket_client.emit('cmd:list', (err, deviceObjects) => { + if (err) { + // handle error + } else { + console.log(deviceObjects) + } }) ``` diff --git a/lib/session.js b/lib/session.js index c0d71ab..cf7978e 100644 --- a/lib/session.js +++ b/lib/session.js @@ -160,16 +160,18 @@ class Session extends EventEmitter { /** * List all available devices + * @param {(err: Error, devices) => void} cb */ list (cb) { SerialPort.list((err, portInfos) => { if (err) { + if (cb) cb(err); this.socket.emit('event:error', err) } else { this.portInfoArray = portInfos .filter(p => isSupported(p)) .map(p => toDeviceObject(p)) - if (cb) cb(this.portInfoArray) + if (cb) cb(null, this.portInfoArray) this.portInfoArray.forEach(p => { logger.info(` [cmd:list] ${p.comName}`) }) diff --git a/package.json b/package.json index 14ef5da..3b5e9fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kameleon-agent", - "version": "0.8.0", + "version": "0.8.1", "author": "Minkyu Lee", "engines": { "node": "10.15.3"