mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-05 02:39:26 +02:00
feat(adb): throw special error when reverse tunnel not supported
This commit is contained in:
parent
fb642beb58
commit
61ca0aecc1
1 changed files with 24 additions and 3 deletions
|
@ -26,10 +26,33 @@ const AdbReverseStringResponse = new Struct()
|
||||||
.string("length", { length: 4 })
|
.string("length", { length: 4 })
|
||||||
.string("content", { lengthField: "length", lengthFieldRadix: 16 });
|
.string("content", { lengthField: "length", lengthFieldRadix: 16 });
|
||||||
|
|
||||||
|
export class AdbReverseError extends Error {
|
||||||
|
public constructor(message: string) {
|
||||||
|
super(message);
|
||||||
|
Object.setPrototypeOf(this, AdbReverseError.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AdbReverseNotSupportedError extends Error {
|
||||||
|
public constructor() {
|
||||||
|
super(
|
||||||
|
"ADB reverse tunnel is not supported on this device when connected wirelessly."
|
||||||
|
);
|
||||||
|
Object.setPrototypeOf(this, AdbReverseNotSupportedError.prototype);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const AdbReverseErrorResponse = new Struct()
|
const AdbReverseErrorResponse = new Struct()
|
||||||
.fields(AdbReverseStringResponse)
|
.fields(AdbReverseStringResponse)
|
||||||
.postDeserialize((value) => {
|
.postDeserialize((value) => {
|
||||||
throw new Error(value.content);
|
// https://issuetracker.google.com/issues/37066218
|
||||||
|
// ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over WiFi),
|
||||||
|
// and returns this confusing "more than one device/emulator" error.
|
||||||
|
if (value.content === "more than one device/emulator") {
|
||||||
|
throw new AdbReverseNotSupportedError();
|
||||||
|
} else {
|
||||||
|
throw new AdbReverseError(value.content);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export class AdbReverseCommand extends AutoDisposable {
|
export class AdbReverseCommand extends AutoDisposable {
|
||||||
|
@ -101,8 +124,6 @@ export class AdbReverseCommand extends AutoDisposable {
|
||||||
localAddress: string,
|
localAddress: string,
|
||||||
handler: AdbIncomingSocketHandler
|
handler: AdbIncomingSocketHandler
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// TODO(reverse): handle ADB bug
|
|
||||||
// https://issuetracker.google.com/issues/37066218
|
|
||||||
const stream = await this.sendRequest(
|
const stream = await this.sendRequest(
|
||||||
`reverse:forward:${deviceAddress};${localAddress}`
|
`reverse:forward:${deviceAddress};${localAddress}`
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue