diff --git a/src/adb/connection.ts b/src/adb/connection.ts index ada5a5a6..e2fa5326 100644 --- a/src/adb/connection.ts +++ b/src/adb/connection.ts @@ -78,8 +78,9 @@ export default class Connection extends EventEmitter { return this; } - public write(data: Buffer, callback?: (err?: Error) => void): boolean { - return this.socket.write(dump(data), callback); + public write(data: Buffer, callback?: (err?: Error) => void): this { + this.socket.write(dump(data), callback); + return this; } public startServer(): Bluebird { diff --git a/src/adb/sync.ts b/src/adb/sync.ts index bab6a434..fda1b4da 100644 --- a/src/adb/sync.ts +++ b/src/adb/sync.ts @@ -191,7 +191,7 @@ export default class Sync extends EventEmitter { if (!this.connection.socket.writableNeedDrain && (chunk = stream.read(DATA_MAX_LENGTH) || stream.read())) { this._sendCommandWithLength(Protocol.DATA, chunk.length); transfer.push(chunk.length); - if (this.connection.write(chunk, track)) { + if (!this.connection.write(chunk, track).socket.writableNeedDrain) { return writeNext(); } else { return waitForDrain().then(writeNext);