Comparing version 0.3.1 to 0.3.2
16
app.js
@@ -15,16 +15,4 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return client | ||
.listDevicesWithPaths() | ||
.then(function (devicelist) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
client.shell(devicelist[0].id, 'ls') | ||
.then(xadb.adb.util.readAll) | ||
.then(function (output) { | ||
console.log(output.toString().trim()); | ||
}); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(err); | ||
}); | ||
let version = yield client.listDevices(); | ||
console.log(version); | ||
}); | ||
@@ -31,0 +19,0 @@ } |
27
app.ts
@@ -8,16 +8,19 @@ //测试 | ||
async function monitor() { | ||
return client | ||
.listDevicesWithPaths() | ||
.then(async function (devicelist) { | ||
client.shell(devicelist[0].id, 'ls') | ||
.then(xadb.adb.util.readAll) | ||
.then(function (output) { | ||
console.log(output.toString().trim()); | ||
}); | ||
}) | ||
.catch(function (err) { | ||
console.log(err) | ||
}) | ||
let version = await client.listDevices(); | ||
console.log(version); | ||
// return client | ||
// .listDevicesWithPaths() | ||
// .then(async function (devicelist) { | ||
// client.shell(devicelist[0].id, 'ls') | ||
// .then(xadb.adb.util.readAll) | ||
// .then(function (output) { | ||
// console.log(output.toString().trim()); | ||
// }); | ||
// }) | ||
// .catch(function (err) { | ||
// console.log(err) | ||
// }) | ||
} | ||
monitor(); |
{ | ||
"name": "xadb", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "./index", | ||
"scripts": { | ||
"tsc": "tsc" | ||
}, | ||
"dependencies": { | ||
@@ -6,0 +9,0 @@ "@types/debug": "0.0.31", |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const Client = require('./adb/client'); | ||
const Keycode = require("./adb/keycode"); | ||
const util = require("./adb/util"); | ||
const client_1 = require("./adb/client"); | ||
class adb { | ||
@@ -14,3 +14,3 @@ static createClient(options = {}) { | ||
} | ||
return new Client(options); | ||
return new client_1.Client(options); | ||
} | ||
@@ -17,0 +17,0 @@ } |
@@ -1,8 +0,8 @@ | ||
const Client = require('./adb/client') | ||
import Keycode = require('./adb/keycode'); | ||
import util = require('./adb/util'); | ||
import {Client} from "./adb/client"; | ||
export class adb { | ||
static createClient(options: any = {}) { | ||
static createClient(options: any = {}): Client { | ||
if (!options.host) { | ||
@@ -9,0 +9,0 @@ options.host = process.env.ADB_HOST |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const debug = require('debug')('adb:client'); | ||
const Promise = require("bluebird"); | ||
const Connection = require('./connection'); | ||
@@ -49,41 +56,37 @@ const Sync = require('./sync'); | ||
const TcpUsbServer = require('./tcpusb/server'); | ||
var Client = (function () { | ||
let NoUserOptionError = undefined; | ||
Client = class Client { | ||
constructor(options) { | ||
this.options = { port: 5037, bin: 'adb' }; | ||
this.options = options; | ||
if (!this.options.port) { | ||
this.options.port = 5037; | ||
} | ||
if (!this.options.bin) { | ||
this.options.bin = 'adb'; | ||
} | ||
class Client { | ||
constructor(options) { | ||
this.NoUserOptionError = undefined; | ||
this.options = { port: 5037, bin: 'adb' }; | ||
this.NoUserOptionError = err => err.message.indexOf('--user') !== -1; | ||
this.options = options; | ||
if (!this.options.port) { | ||
this.options.port = 5037; | ||
} | ||
static initClass() { | ||
NoUserOptionError = err => err.message.indexOf('--user') !== -1; | ||
if (!this.options.bin) { | ||
this.options.bin = 'adb'; | ||
} | ||
createTcpUsbBridge(serial, options) { | ||
return new TcpUsbServer(this, serial, options); | ||
} | ||
connection() { | ||
let connectListener, errorListener; | ||
const resolver = Promise.defer(); | ||
var conn = new Connection(this.options) | ||
.on('error', (errorListener = err => resolver.reject(err))).on('connect', (connectListener = () => resolver.resolve(conn))).connect(); | ||
return resolver.promise.finally(function () { | ||
conn.removeListener('error', errorListener); | ||
return conn.removeListener('connect', connectListener); | ||
} | ||
createTcpUsbBridge(serial, options) { | ||
return new TcpUsbServer(this, serial, options); | ||
} | ||
connection() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let conn = yield new Promise((resolve, reject) => { | ||
let my_conn = new Connection(this.options) | ||
.on('error', (err => reject(err))).on('connect', (() => resolve(my_conn))).connect(); | ||
}); | ||
} | ||
version(callback) { | ||
conn.removeAllListeners(); | ||
return conn; | ||
}); | ||
} | ||
version() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostVersionCommand(conn) | ||
.execute()).nodeify(callback); | ||
} | ||
connect(host, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port; | ||
port = 5555; | ||
} | ||
.execute()); | ||
}); | ||
} | ||
connect(host, port = 5555) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (host.indexOf(':') !== -1) { | ||
@@ -94,9 +97,7 @@ [host, port] = Array.from(host.split(':', 2)); | ||
.then(conn => new HostConnectCommand(conn) | ||
.execute(host, port)).nodeify(callback); | ||
} | ||
disconnect(host, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port; | ||
port = 5555; | ||
} | ||
.execute(host, port)); | ||
}); | ||
} | ||
disconnect(host, port = 5555) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (host.indexOf(':') !== -1) { | ||
@@ -107,55 +108,77 @@ [host, port] = Array.from(host.split(':', 2)); | ||
.then(conn => new HostDisconnectCommand(conn) | ||
.execute(host, port)).nodeify(callback); | ||
} | ||
listDevices(callback) { | ||
.execute(host, port)); | ||
}); | ||
} | ||
listDevices() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostDevicesCommand(conn) | ||
.execute()).nodeify(callback); | ||
} | ||
listDevicesWithPaths(callback) { | ||
.execute()); | ||
}); | ||
} | ||
listDevicesWithPaths() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostDevicesWithPathsCommand(conn) | ||
.execute()).nodeify(callback); | ||
} | ||
trackDevices(callback) { | ||
.execute()); | ||
}); | ||
} | ||
trackDevices() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostTrackDevicesCommand(conn) | ||
.execute()).nodeify(callback); | ||
} | ||
kill(callback) { | ||
.execute()); | ||
}); | ||
} | ||
kill() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostKillCommand(conn) | ||
.execute()).nodeify(callback); | ||
} | ||
getSerialNo(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
getSerialNo(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new GetSerialNoCommand(conn) | ||
.execute(serial)).nodeify(callback); | ||
} | ||
getDevicePath(serial, callback) { | ||
.execute(serial)); | ||
}); | ||
} | ||
getDevicePath(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new GetDevicePathCommand(conn) | ||
.execute(serial)).nodeify(callback); | ||
} | ||
getState(serial, callback) { | ||
.execute(serial)); | ||
}); | ||
} | ||
getState(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new GetStateCommand(conn) | ||
.execute(serial)).nodeify(callback); | ||
} | ||
getProperties(serial, callback) { | ||
.execute(serial)); | ||
}); | ||
} | ||
getProperties(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new GetPropertiesCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
getFeatures(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
getFeatures(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new GetFeaturesCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
getPackages(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
getPackages(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new GetPackagesCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
getDHCPIpAddress(serial, iface = 'wlan0', callback) { | ||
.execute()); | ||
}); | ||
} | ||
getDHCPIpAddress(serial, iface = 'wlan0', callback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (typeof iface === 'function') { | ||
@@ -173,14 +196,20 @@ callback = iface; | ||
}); | ||
} | ||
forward(serial, local, remote, callback) { | ||
}); | ||
} | ||
forward(serial, local, remote) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new ForwardCommand(conn) | ||
.execute(serial, local, remote)).nodeify(callback); | ||
} | ||
listForwards(serial, callback) { | ||
.execute(serial, local, remote)); | ||
}); | ||
} | ||
listForwards(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new ListForwardsCommand(conn) | ||
.execute(serial)).nodeify(callback); | ||
} | ||
reverse(serial, remote, local, callback) { | ||
.execute(serial)); | ||
}); | ||
} | ||
reverse(serial, remote, local, callback) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
@@ -190,49 +219,63 @@ .then(transport => new ReverseCommand(transport) | ||
.nodeify(callback)); | ||
} | ||
listReverses(serial, callback) { | ||
}); | ||
} | ||
listReverses(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new ListReversesCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
transport(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
transport(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new HostTransportCommand(conn) | ||
.execute(serial) | ||
.return(conn)).nodeify(callback); | ||
} | ||
shell(serial, command, callback) { | ||
.return(conn)); | ||
}); | ||
} | ||
shell(serial, command) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new ShellCommand(transport) | ||
.execute(command)).nodeify(callback); | ||
} | ||
reboot(serial, callback) { | ||
.execute(command)); | ||
}); | ||
} | ||
reboot(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new RebootCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
remount(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
remount(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new RemountCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
root(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
root(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new RootCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
trackJdwp(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
trackJdwp(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new TrackJdwpCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
framebuffer(serial, format = 'raw', callback) { | ||
if (typeof format === 'function') { | ||
callback = format; | ||
format = 'raw'; | ||
} | ||
.execute()); | ||
}); | ||
} | ||
framebuffer(serial, format = 'raw') { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new FrameBufferCommand(transport) | ||
.execute(format)).nodeify(callback); | ||
} | ||
screencap(serial, callback) { | ||
.execute(format)); | ||
}); | ||
} | ||
screencap(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
@@ -246,49 +289,53 @@ .then(transport => { | ||
}); | ||
}).nodeify(callback); | ||
} | ||
openLocal(serial, path, callback) { | ||
}); | ||
}); | ||
} | ||
openLocal(serial, path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new LocalCommand(transport) | ||
.execute(path)).nodeify(callback); | ||
} | ||
openLog(serial, name, callback) { | ||
.execute(path)); | ||
}); | ||
} | ||
openLog(serial, name) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new LogCommand(transport) | ||
.execute(name)).nodeify(callback); | ||
} | ||
openTcp(serial, port, host, callback) { | ||
if (typeof host === 'function') { | ||
callback = host; | ||
host = undefined; | ||
} | ||
.execute(name)); | ||
}); | ||
} | ||
openTcp(serial, port, host) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new TcpCommand(transport) | ||
.execute(port, host)).nodeify(callback); | ||
} | ||
openProcStat(serial, callback) { | ||
.execute(port, host)); | ||
}); | ||
} | ||
openProcStat(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.syncService(serial) | ||
.then(sync => new ProcStat(sync)).nodeify(callback); | ||
} | ||
clear(serial, pkg, callback) { | ||
.then(sync => new ProcStat(sync)); | ||
}); | ||
} | ||
clear(serial, pkg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new ClearCommand(transport) | ||
.execute(pkg)).nodeify(callback); | ||
} | ||
install(serial, apk, callback) { | ||
const temp = Sync.temp(typeof apk === 'string' ? apk : '_stream.apk'); | ||
return this.push(serial, apk, temp) | ||
.then(transfer => { | ||
let endListener, errorListener; | ||
const resolver = Promise.defer(); | ||
transfer.on('error', (errorListener = err => resolver.reject(err))); | ||
transfer.on('end', (endListener = () => { | ||
return resolver.resolve(this.installRemote(serial, temp)); | ||
})); | ||
return resolver.promise.finally(function () { | ||
transfer.removeListener('error', errorListener); | ||
return transfer.removeListener('end', endListener); | ||
}); | ||
}).nodeify(callback); | ||
} | ||
installRemote(serial, apk, callback) { | ||
.execute(pkg)); | ||
}); | ||
} | ||
install(serial, apk) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
let temp = Sync.temp(typeof apk === 'string' ? apk : '_stream.apk'); | ||
let work = yield new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
let transfer = yield this.push(serial, apk, temp); | ||
transfer.on('error', (err => reject(err))); | ||
transfer.on('end', (() => resolve(this.installRemote(serial, temp)))); | ||
})); | ||
work.removeAllListeners(); | ||
return work; | ||
}); | ||
} | ||
installRemote(serial, apk) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
@@ -303,93 +350,115 @@ .then(transport => { | ||
.readAll()).then(out => true); | ||
}).nodeify(callback); | ||
} | ||
uninstall(serial, pkg, callback) { | ||
}); | ||
}); | ||
} | ||
uninstall(serial, pkg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new UninstallCommand(transport) | ||
.execute(pkg)).nodeify(callback); | ||
} | ||
isInstalled(serial, pkg, callback) { | ||
.execute(pkg)); | ||
}); | ||
} | ||
isInstalled(serial, pkg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new IsInstalledCommand(transport) | ||
.execute(pkg)).nodeify(callback); | ||
} | ||
startActivity(serial, options, callback) { | ||
return this.transport(serial) | ||
.then(transport => new StartActivityCommand(transport) | ||
.execute(options)).catch(NoUserOptionError, () => { | ||
.execute(pkg)); | ||
}); | ||
} | ||
startActivity(serial, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return this.transport(serial) | ||
.then(transport => new StartActivityCommand(transport) | ||
.execute(options)); | ||
} | ||
catch (e) { | ||
options.user = null; | ||
return this.startActivity(serial, options); | ||
}).nodeify(callback); | ||
} | ||
startService(serial, options, callback) { | ||
return this.transport(serial) | ||
.then(function (transport) { | ||
if (!options.user && (options.user !== null)) { | ||
options.user = 0; | ||
} | ||
return new StartServiceCommand(transport) | ||
.execute(options); | ||
}).catch(NoUserOptionError, () => { | ||
} | ||
}); | ||
} | ||
startService(serial, options) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
return this.transport(serial) | ||
.then(function (transport) { | ||
if (!options.user && (options.user !== null)) { | ||
options.user = 0; | ||
} | ||
return new StartServiceCommand(transport) | ||
.execute(options); | ||
}); | ||
} | ||
catch (e) { | ||
options.user = null; | ||
return this.startService(serial, options); | ||
}).nodeify(callback); | ||
} | ||
syncService(serial, callback) { | ||
} | ||
}); | ||
} | ||
syncService(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new SyncCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
stat(serial, path, callback) { | ||
.execute()); | ||
}); | ||
} | ||
stat(serial, path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.syncService(serial) | ||
.then(sync => sync.stat(path) | ||
.finally(() => sync.end())).nodeify(callback); | ||
} | ||
readdir(serial, path, callback) { | ||
.finally(() => sync.end())); | ||
}); | ||
} | ||
readdir(serial, path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.syncService(serial) | ||
.then(sync => sync.readdir(path) | ||
.finally(() => sync.end())).nodeify(callback); | ||
} | ||
pull(serial, path, callback) { | ||
.finally(() => sync.end())); | ||
}); | ||
} | ||
pull(serial, path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.syncService(serial) | ||
.then(sync => sync.pull(path) | ||
.on('end', () => sync.end())).nodeify(callback); | ||
} | ||
push(serial, contents, path, mode, callback) { | ||
if (typeof mode === 'function') { | ||
callback = mode; | ||
mode = undefined; | ||
} | ||
.on('end', () => sync.end())); | ||
}); | ||
} | ||
push(serial, contents, path, mode) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.syncService(serial) | ||
.then(sync => sync.push(contents, path, mode) | ||
.on('end', () => sync.end())).nodeify(callback); | ||
} | ||
tcpip(serial, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port; | ||
port = 5555; | ||
} | ||
.on('end', () => sync.end())); | ||
}); | ||
} | ||
tcpip(serial, port = 5555) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new TcpIpCommand(transport) | ||
.execute(port)).nodeify(callback); | ||
} | ||
usb(serial, callback) { | ||
.execute(port)); | ||
}); | ||
} | ||
usb(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new UsbCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
waitBootComplete(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
waitBootComplete(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.transport(serial) | ||
.then(transport => new WaitBootCompleteCommand(transport) | ||
.execute()).nodeify(callback); | ||
} | ||
waitForDevice(serial, callback) { | ||
.execute()); | ||
}); | ||
} | ||
waitForDevice(serial) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.connection() | ||
.then(conn => new WaitForDeviceCommand(conn) | ||
.execute(serial)).nodeify(callback); | ||
} | ||
}; | ||
Client.initClass(); | ||
return Client; | ||
})(); | ||
module.exports = Client; | ||
.execute(serial)); | ||
}); | ||
} | ||
} | ||
exports.Client = Client; | ||
//# sourceMappingURL=client.js.map |
@@ -1,404 +0,381 @@ | ||
const debug = require('debug')('adb:client') | ||
// @ts-ignore | ||
import Promise = require('bluebird'); | ||
const debug = require('debug')('adb:client'); | ||
const Connection = require('./connection') | ||
const Sync = require('./sync') | ||
const Parser = require('./parser') | ||
const ProcStat = require('./proc/stat') | ||
const HostVersionCommand = require('./command/host/version') | ||
const HostConnectCommand = require('./command/host/connect') | ||
const HostDevicesCommand = require('./command/host/devices') | ||
const HostDevicesWithPathsCommand = require('./command/host/deviceswithpaths') | ||
const HostDisconnectCommand = require('./command/host/disconnect') | ||
const HostTrackDevicesCommand = require('./command/host/trackdevices') | ||
const HostKillCommand = require('./command/host/kill') | ||
const HostTransportCommand = require('./command/host/transport') | ||
const Connection = require('./connection'); | ||
const Sync = require('./sync'); | ||
const Parser = require('./parser'); | ||
const ProcStat = require('./proc/stat'); | ||
const ClearCommand = require('./command/host-transport/clear') | ||
const FrameBufferCommand = require('./command/host-transport/framebuffer') | ||
const GetFeaturesCommand = require('./command/host-transport/getfeatures') | ||
const GetPackagesCommand = require('./command/host-transport/getpackages') | ||
const GetPropertiesCommand = require('./command/host-transport/getproperties') | ||
const InstallCommand = require('./command/host-transport/install') | ||
const IsInstalledCommand = require('./command/host-transport/isinstalled') | ||
const ListReversesCommand = require('./command/host-transport/listreverses') | ||
const LocalCommand = require('./command/host-transport/local') | ||
const LogCommand = require('./command/host-transport/log') | ||
const RebootCommand = require('./command/host-transport/reboot') | ||
const RemountCommand = require('./command/host-transport/remount') | ||
const RootCommand = require('./command/host-transport/root') | ||
const ReverseCommand = require('./command/host-transport/reverse') | ||
const ScreencapCommand = require('./command/host-transport/screencap') | ||
const ShellCommand = require('./command/host-transport/shell') | ||
const StartActivityCommand = require('./command/host-transport/startactivity') | ||
const StartServiceCommand = require('./command/host-transport/startservice') | ||
const SyncCommand = require('./command/host-transport/sync') | ||
const TcpCommand = require('./command/host-transport/tcp') | ||
const TcpIpCommand = require('./command/host-transport/tcpip') | ||
const TrackJdwpCommand = require('./command/host-transport/trackjdwp') | ||
const UninstallCommand = require('./command/host-transport/uninstall') | ||
const UsbCommand = require('./command/host-transport/usb') | ||
const WaitBootCompleteCommand = require('./command/host-transport/waitbootcomplete') | ||
const HostVersionCommand = require('./command/host/version'); | ||
const HostConnectCommand = require('./command/host/connect'); | ||
const HostDevicesCommand = require('./command/host/devices'); | ||
const HostDevicesWithPathsCommand = require('./command/host/deviceswithpaths'); | ||
const HostDisconnectCommand = require('./command/host/disconnect'); | ||
const HostTrackDevicesCommand = require('./command/host/trackdevices'); | ||
const HostKillCommand = require('./command/host/kill'); | ||
const HostTransportCommand = require('./command/host/transport'); | ||
const ForwardCommand = require('./command/host-serial/forward') | ||
const GetDevicePathCommand = require('./command/host-serial/getdevicepath') | ||
const GetSerialNoCommand = require('./command/host-serial/getserialno') | ||
const GetStateCommand = require('./command/host-serial/getstate') | ||
const ListForwardsCommand = require('./command/host-serial/listforwards') | ||
const WaitForDeviceCommand = require('./command/host-serial/waitfordevice') | ||
const ClearCommand = require('./command/host-transport/clear'); | ||
const FrameBufferCommand = require('./command/host-transport/framebuffer'); | ||
const GetFeaturesCommand = require('./command/host-transport/getfeatures'); | ||
const GetPackagesCommand = require('./command/host-transport/getpackages'); | ||
const GetPropertiesCommand = require('./command/host-transport/getproperties'); | ||
const InstallCommand = require('./command/host-transport/install'); | ||
const IsInstalledCommand = require('./command/host-transport/isinstalled'); | ||
const ListReversesCommand = require('./command/host-transport/listreverses'); | ||
const LocalCommand = require('./command/host-transport/local'); | ||
const LogCommand = require('./command/host-transport/log'); | ||
const RebootCommand = require('./command/host-transport/reboot'); | ||
const RemountCommand = require('./command/host-transport/remount'); | ||
const RootCommand = require('./command/host-transport/root'); | ||
const ReverseCommand = require('./command/host-transport/reverse'); | ||
const ScreencapCommand = require('./command/host-transport/screencap'); | ||
const ShellCommand = require('./command/host-transport/shell'); | ||
const StartActivityCommand = require('./command/host-transport/startactivity'); | ||
const StartServiceCommand = require('./command/host-transport/startservice'); | ||
const SyncCommand = require('./command/host-transport/sync'); | ||
const TcpCommand = require('./command/host-transport/tcp'); | ||
const TcpIpCommand = require('./command/host-transport/tcpip'); | ||
const TrackJdwpCommand = require('./command/host-transport/trackjdwp'); | ||
const UninstallCommand = require('./command/host-transport/uninstall'); | ||
const UsbCommand = require('./command/host-transport/usb'); | ||
const WaitBootCompleteCommand = require('./command/host-transport/waitbootcomplete'); | ||
const TcpUsbServer = require('./tcpusb/server') | ||
const ForwardCommand = require('./command/host-serial/forward'); | ||
const GetDevicePathCommand = require('./command/host-serial/getdevicepath'); | ||
const GetSerialNoCommand = require('./command/host-serial/getserialno'); | ||
const GetStateCommand = require('./command/host-serial/getstate'); | ||
const ListForwardsCommand = require('./command/host-serial/listforwards'); | ||
const WaitForDeviceCommand = require('./command/host-serial/waitfordevice'); | ||
var Client: any = (function () { | ||
let NoUserOptionError = undefined | ||
Client = class Client { | ||
static initClass() { | ||
const TcpUsbServer = require('./tcpusb/server'); | ||
NoUserOptionError = err => err.message.indexOf('--user') !== -1 | ||
} | ||
options = {port: 5037, bin: 'adb'}; | ||
export class Client { | ||
constructor(options) { | ||
this.options = options | ||
if (!this.options.port) { | ||
this.options.port = 5037 | ||
} | ||
if (!this.options.bin) { | ||
this.options.bin = 'adb' | ||
} | ||
} | ||
private NoUserOptionError = undefined; | ||
private options = {port: 5037, bin: 'adb'}; | ||
createTcpUsbBridge(serial, options) { | ||
return new TcpUsbServer(this, serial, options) | ||
constructor(options) { | ||
this.NoUserOptionError = err => err.message.indexOf('--user') !== -1; | ||
this.options = options; | ||
if (!this.options.port) { | ||
this.options.port = 5037 | ||
} | ||
connection() { | ||
let connectListener, errorListener | ||
const resolver = Promise.defer(); | ||
var conn = new Connection(this.options) | ||
.on('error', (errorListener = err => resolver.reject(err))).on('connect', (connectListener = () => resolver.resolve(conn))).connect() | ||
return resolver.promise.finally(function () { | ||
conn.removeListener('error', errorListener) | ||
return conn.removeListener('connect', connectListener) | ||
}) | ||
if (!this.options.bin) { | ||
this.options.bin = 'adb' | ||
} | ||
} | ||
version(callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostVersionCommand(conn) | ||
.execute()).nodeify(callback) | ||
} | ||
createTcpUsbBridge(serial: string, options) { | ||
return new TcpUsbServer(this, serial, options) | ||
} | ||
connect(host, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port | ||
port = 5555 | ||
} | ||
if (host.indexOf(':') !== -1) { | ||
[host, port] = Array.from(host.split(':', 2)) | ||
} | ||
return this.connection() | ||
.then(conn => | ||
new HostConnectCommand(conn) | ||
.execute(host, port)).nodeify(callback) | ||
} | ||
disconnect(host, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port | ||
port = 5555 | ||
} | ||
if (host.indexOf(':') !== -1) { | ||
[host, port] = Array.from(host.split(':', 2)) | ||
} | ||
return this.connection() | ||
.then(conn => | ||
new HostDisconnectCommand(conn) | ||
.execute(host, port)).nodeify(callback) | ||
} | ||
public async connection() { | ||
let conn: any = await new Promise((resolve, reject) => { | ||
let my_conn = new Connection(this.options) | ||
.on('error', (err => reject(err))).on('connect', (() => resolve(my_conn))).connect(); | ||
}); | ||
//移除所有监听器,避免内存泄露 | ||
conn.removeAllListeners(); | ||
return conn; | ||
} | ||
listDevices(callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostDevicesCommand(conn) | ||
.execute()).nodeify(callback) | ||
} | ||
public async version() { | ||
return this.connection() | ||
.then(conn => | ||
new HostVersionCommand(conn) | ||
.execute()); | ||
} | ||
listDevicesWithPaths(callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostDevicesWithPathsCommand(conn) | ||
.execute()).nodeify(callback) | ||
public async connect(host, port = 5555) { | ||
if (host.indexOf(':') !== -1) { | ||
[host, port] = Array.from(host.split(':', 2)) | ||
} | ||
return this.connection() | ||
.then(conn => | ||
new HostConnectCommand(conn) | ||
.execute(host, port)); | ||
} | ||
trackDevices(callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostTrackDevicesCommand(conn) | ||
.execute()).nodeify(callback) | ||
public async disconnect(host, port = 5555) { | ||
if (host.indexOf(':') !== -1) { | ||
[host, port] = Array.from(host.split(':', 2)) | ||
} | ||
return this.connection() | ||
.then(conn => | ||
new HostDisconnectCommand(conn) | ||
.execute(host, port)); | ||
} | ||
kill(callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostKillCommand(conn) | ||
.execute()).nodeify(callback) | ||
} | ||
public async listDevices() { | ||
return this.connection() | ||
.then(conn => | ||
new HostDevicesCommand(conn) | ||
.execute()); | ||
} | ||
getSerialNo(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new GetSerialNoCommand(conn) | ||
.execute(serial)).nodeify(callback) | ||
} | ||
public async listDevicesWithPaths() { | ||
return this.connection() | ||
.then(conn => | ||
new HostDevicesWithPathsCommand(conn) | ||
.execute()); | ||
} | ||
getDevicePath(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new GetDevicePathCommand(conn) | ||
.execute(serial)).nodeify(callback) | ||
} | ||
public async trackDevices() { | ||
return this.connection() | ||
.then(conn => | ||
new HostTrackDevicesCommand(conn) | ||
.execute()); | ||
} | ||
getState(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new GetStateCommand(conn) | ||
.execute(serial)).nodeify(callback) | ||
} | ||
public async kill() { | ||
return this.connection() | ||
.then(conn => | ||
new HostKillCommand(conn) | ||
.execute()); | ||
} | ||
getProperties(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetPropertiesCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async getSerialNo(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new GetSerialNoCommand(conn) | ||
.execute(serial)); | ||
} | ||
getFeatures(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetFeaturesCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async getDevicePath(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new GetDevicePathCommand(conn) | ||
.execute(serial)); | ||
} | ||
getPackages(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetPackagesCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async getState(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new GetStateCommand(conn) | ||
.execute(serial)); | ||
} | ||
getDHCPIpAddress(serial, iface = 'wlan0', callback) { | ||
if (typeof iface === 'function') { | ||
callback = iface | ||
iface = 'wlan0' | ||
} | ||
return this.getProperties(serial) | ||
.then(function (properties) { | ||
let ip | ||
if (ip = properties[`dhcp.${iface}.ipaddress`]) { | ||
return ip | ||
} | ||
throw new Error(`Unable to find ipaddress for '${iface}'`) | ||
}) | ||
} | ||
public async getProperties(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetPropertiesCommand(transport) | ||
.execute()); | ||
} | ||
forward(serial, local, remote, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new ForwardCommand(conn) | ||
.execute(serial, local, remote)).nodeify(callback) | ||
} | ||
public async getFeatures(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetFeaturesCommand(transport) | ||
.execute()); | ||
} | ||
listForwards(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new ListForwardsCommand(conn) | ||
.execute(serial)).nodeify(callback) | ||
} | ||
public async getPackages(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new GetPackagesCommand(transport) | ||
.execute()); | ||
} | ||
reverse(serial, remote, local, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ReverseCommand(transport) | ||
.execute(remote, local) | ||
.nodeify(callback) | ||
) | ||
public async getDHCPIpAddress(serial: string, iface = 'wlan0', callback) { | ||
if (typeof iface === 'function') { | ||
callback = iface; | ||
iface = 'wlan0' | ||
} | ||
return this.getProperties(serial) | ||
.then(function (properties) { | ||
let ip; | ||
if (ip = properties[`dhcp.${iface}.ipaddress`]) { | ||
return ip | ||
} | ||
throw new Error(`Unable to find ipaddress for '${iface}'`) | ||
}) | ||
} | ||
listReverses(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ListReversesCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async forward(serial: string, local, remote) { | ||
return this.connection() | ||
.then(conn => | ||
new ForwardCommand(conn) | ||
.execute(serial, local, remote)); | ||
} | ||
transport(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new HostTransportCommand(conn) | ||
.execute(serial) | ||
.return(conn)).nodeify(callback) | ||
} | ||
public async listForwards(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new ListForwardsCommand(conn) | ||
.execute(serial)); | ||
} | ||
shell(serial, command, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ShellCommand(transport) | ||
.execute(command)).nodeify(callback) | ||
} | ||
public async reverse(serial: string, remote, local, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ReverseCommand(transport) | ||
.execute(remote, local) | ||
.nodeify(callback) | ||
) | ||
} | ||
reboot(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RebootCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async listReverses(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ListReversesCommand(transport) | ||
.execute()); | ||
} | ||
remount(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RemountCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async transport(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new HostTransportCommand(conn) | ||
.execute(serial) | ||
.return(conn)); | ||
} | ||
root(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RootCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async shell(serial: string, command) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ShellCommand(transport) | ||
.execute(command)); | ||
} | ||
trackJdwp(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new TrackJdwpCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async reboot(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RebootCommand(transport) | ||
.execute()); | ||
} | ||
framebuffer(serial, format = 'raw', callback) { | ||
if (typeof format === 'function') { | ||
callback = format | ||
format = 'raw' | ||
} | ||
return this.transport(serial) | ||
.then(transport => | ||
new FrameBufferCommand(transport) | ||
.execute(format)).nodeify(callback) | ||
} | ||
public async remount(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RemountCommand(transport) | ||
.execute()); | ||
} | ||
screencap(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => { | ||
return new ScreencapCommand(transport) | ||
.execute() | ||
.catch(err => { | ||
debug(`Emulating screencap command due to '${err}'`) | ||
return this.framebuffer(serial, 'png') | ||
}) | ||
}).nodeify(callback) | ||
} | ||
public async root(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new RootCommand(transport) | ||
.execute()); | ||
} | ||
openLocal(serial, path, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new LocalCommand(transport) | ||
.execute(path)).nodeify(callback) | ||
} | ||
public async trackJdwp(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new TrackJdwpCommand(transport) | ||
.execute()); | ||
} | ||
openLog(serial, name, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new LogCommand(transport) | ||
.execute(name)).nodeify(callback) | ||
} | ||
public async framebuffer(serial: string, format = 'raw') { | ||
return this.transport(serial) | ||
.then(transport => | ||
new FrameBufferCommand(transport) | ||
.execute(format)); | ||
} | ||
openTcp(serial, port, host, callback) { | ||
if (typeof host === 'function') { | ||
callback = host | ||
host = undefined | ||
} | ||
return this.transport(serial) | ||
.then(transport => | ||
new TcpCommand(transport) | ||
.execute(port, host)).nodeify(callback) | ||
} | ||
public async screencap(serial) { | ||
return this.transport(serial) | ||
.then(transport => { | ||
return new ScreencapCommand(transport) | ||
.execute() | ||
.catch(err => { | ||
debug(`Emulating screencap command due to '${err}'`); | ||
return this.framebuffer(serial, 'png') | ||
}) | ||
}); | ||
} | ||
public async openLocal(serial: string, path) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new LocalCommand(transport) | ||
.execute(path)); | ||
} | ||
openProcStat(serial, callback) { | ||
return this.syncService(serial) | ||
.then(sync => new ProcStat(sync)).nodeify(callback) | ||
} | ||
public async openLog(serial: string, name) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new LogCommand(transport) | ||
.execute(name)); | ||
} | ||
clear(serial, pkg, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ClearCommand(transport) | ||
.execute(pkg)).nodeify(callback) | ||
} | ||
public async openTcp(serial: string, port, host) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new TcpCommand(transport) | ||
.execute(port, host)); | ||
} | ||
install(serial, apk, callback) { | ||
const temp = Sync.temp(typeof apk === 'string' ? apk : '_stream.apk') | ||
return this.push(serial, apk, temp) | ||
.then(transfer => { | ||
let endListener, errorListener | ||
const resolver = Promise.defer() | ||
transfer.on('error', (errorListener = err => resolver.reject(err)) | ||
) | ||
public async openProcStat(serial) { | ||
return this.syncService(serial) | ||
.then(sync => new ProcStat(sync)); | ||
} | ||
transfer.on('end', (endListener = () => { | ||
return resolver.resolve(this.installRemote(serial, temp)) | ||
}) | ||
) | ||
public async clear(serial: string, pkg) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new ClearCommand(transport) | ||
.execute(pkg)); | ||
} | ||
return resolver.promise.finally(function () { | ||
transfer.removeListener('error', errorListener) | ||
return transfer.removeListener('end', endListener) | ||
//安装apk | ||
public async install(serial: string, apk) { | ||
let temp = Sync.temp(typeof apk === 'string' ? apk : '_stream.apk'); | ||
let work: any = await new Promise(async (resolve, reject) => { | ||
let transfer = await this.push(serial, apk, temp); | ||
transfer.on('error', (err => reject(err))); | ||
transfer.on('end', (() => resolve(this.installRemote(serial, temp)))); | ||
}); | ||
//移除所有监听器,避免内存泄露 | ||
work.removeAllListeners(); | ||
return work; | ||
} | ||
//从远端安装apk | ||
public async installRemote(serial: string, apk?) { | ||
return this.transport(serial) | ||
.then(transport => { | ||
return new InstallCommand(transport) | ||
.execute(apk) | ||
.then(() => { | ||
return this.shell(serial, ['rm', '-f', apk]) | ||
}) | ||
}).nodeify(callback) | ||
} | ||
.then(stream => | ||
new Parser(stream) | ||
.readAll()).then(out => true) | ||
}); | ||
} | ||
installRemote(serial, apk, callback) { | ||
return this.transport(serial) | ||
.then(transport => { | ||
return new InstallCommand(transport) | ||
.execute(apk) | ||
.then(() => { | ||
return this.shell(serial, ['rm', '-f', apk]) | ||
}) | ||
.then(stream => | ||
new Parser(stream) | ||
.readAll()).then(out => true) | ||
}).nodeify(callback) | ||
} | ||
public async uninstall(serial: string, pkg) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new UninstallCommand(transport) | ||
.execute(pkg)); | ||
} | ||
uninstall(serial, pkg, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new UninstallCommand(transport) | ||
.execute(pkg)).nodeify(callback) | ||
} | ||
public async isInstalled(serial: string, pkg) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new IsInstalledCommand(transport) | ||
.execute(pkg)); | ||
} | ||
isInstalled(serial, pkg, callback) { | ||
public async startActivity(serial: string, options) { | ||
try { | ||
return this.transport(serial) | ||
.then(transport => | ||
new IsInstalledCommand(transport) | ||
.execute(pkg)).nodeify(callback) | ||
} | ||
startActivity(serial, options, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new StartActivityCommand(transport) | ||
.execute(options)).catch(NoUserOptionError, () => { | ||
options.user = null | ||
return this.startActivity(serial, options) | ||
}).nodeify(callback) | ||
.execute(options)); | ||
} | ||
catch (e) { | ||
options.user = null; | ||
return this.startActivity(serial, options) | ||
} | ||
} | ||
startService(serial, options, callback) { | ||
public async startService(serial: string, options) { | ||
try { | ||
return this.transport(serial) | ||
@@ -411,83 +388,76 @@ .then(function (transport) { | ||
.execute(options) | ||
}).catch(NoUserOptionError, () => { | ||
options.user = null | ||
return this.startService(serial, options) | ||
}).nodeify(callback) | ||
}); | ||
} | ||
syncService(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new SyncCommand(transport) | ||
.execute()).nodeify(callback) | ||
catch (e) { | ||
options.user = null; | ||
return this.startService(serial, options) | ||
} | ||
} | ||
stat(serial, path, callback) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.stat(path) | ||
.finally(() => sync.end())).nodeify(callback) | ||
} | ||
public async syncService(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new SyncCommand(transport) | ||
.execute()); | ||
} | ||
readdir(serial, path, callback) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.readdir(path) | ||
.finally(() => sync.end())).nodeify(callback) | ||
} | ||
public async stat(serial: string, path) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.stat(path) | ||
.finally(() => sync.end())); | ||
} | ||
pull(serial, path, callback) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.pull(path) | ||
.on('end', () => sync.end())).nodeify(callback) | ||
} | ||
public async readdir(serial: string, path) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.readdir(path) | ||
.finally(() => sync.end())); | ||
} | ||
push(serial, contents, path, mode, callback) { | ||
if (typeof mode === 'function') { | ||
callback = mode | ||
mode = undefined | ||
} | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.push(contents, path, mode) | ||
.on('end', () => sync.end())).nodeify(callback) | ||
} | ||
public async pull(serial: string, path) { | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.pull(path) | ||
.on('end', () => sync.end())); | ||
} | ||
tcpip(serial, port = 5555, callback) { | ||
if (typeof port === 'function') { | ||
callback = port | ||
port = 5555 | ||
} | ||
return this.transport(serial) | ||
.then(transport => | ||
new TcpIpCommand(transport) | ||
.execute(port)).nodeify(callback) | ||
} | ||
public async push(serial: string, contents, path, mode?) { | ||
usb(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new UsbCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
return this.syncService(serial) | ||
.then(sync => | ||
sync.push(contents, path, mode) | ||
.on('end', () => sync.end())); | ||
} | ||
waitBootComplete(serial, callback) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new WaitBootCompleteCommand(transport) | ||
.execute()).nodeify(callback) | ||
} | ||
public async tcpip(serial: string, port = 5555) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new TcpIpCommand(transport) | ||
.execute(port)); | ||
} | ||
waitForDevice(serial, callback) { | ||
return this.connection() | ||
.then(conn => | ||
new WaitForDeviceCommand(conn) | ||
.execute(serial)).nodeify(callback) | ||
} | ||
public async usb(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new UsbCommand(transport) | ||
.execute()); | ||
} | ||
Client.initClass() | ||
return Client | ||
})() | ||
module.exports = Client | ||
public async waitBootComplete(serial) { | ||
return this.transport(serial) | ||
.then(transport => | ||
new WaitBootCompleteCommand(transport) | ||
.execute()); | ||
} | ||
public async waitForDevice(serial) { | ||
return this.connection() | ||
.then(conn => | ||
new WaitForDeviceCommand(conn) | ||
.execute(serial)); | ||
} | ||
} | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
4687
200614