| 200 | } |
| 201 | |
| 202 | _sendMessage(message) { |
| 203 | const msg = JSON.parse(JSON.stringify(message)); // Clone! |
| 204 | msg.id = this._nextId++; |
| 205 | if (DEBUG) |
| 206 | console.log('[sent]', JSON.stringify(msg)); |
| 207 | |
| 208 | const responsePromise = new Promise((resolve, reject) => { |
| 209 | this._commandResponsePromises.set(msg.id, { resolve, reject }); |
| 210 | }); |
| 211 | |
| 212 | return new Promise( |
| 213 | (resolve) => this._socket.write(formatWSFrame(msg), resolve)) |
| 214 | .then(() => responsePromise); |
| 215 | } |
| 216 | |
| 217 | send(commands) { |
| 218 | if (Array.isArray(commands)) { |