Skip to content

Commit

Permalink
add info about AdbReverseNotSupportedError
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Dec 3, 2024
1 parent 81acc76 commit 64284b4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
39 changes: 37 additions & 2 deletions docs/scrcpy/connect-server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,40 @@ Tango encapsulates the reverse tunnel feature into a callback-based API:

The `AdbScrcpyClient.start` method uses reverse tunnels by default. It sets up the reverse tunnel and waits for the correct amount of connections automatically.

However, if [`reverse.add`](../api/adb/reverse/add.mdx) throws an `AdbReverseNotSupportedError`, `AdbScrcpyClient` will automatically modify the options to use forward tunnel instead.

If you are using a custom transport that doesn't support reverse tunnel, you can set `tunnelForward: true` option explicitly:

```ts transpile
import { ScrcpyOptions3_0 } from "@yume-chan/scrcpy";

const options = new ScrcpyOptions3_0({
tunnelForward: true,
});
```

Or you can throw an `AdbReverseNotSupportedError` in your custom transport:

```ts transpile
import { AdbReverseNotSupportedError } from "@yume-chan/adb";

export class YourTransport implements AdbTransport {
/// other methods

addReverseTunnel() {
throw new AdbReverseNotSupportedError();
}

removeReverseTunnel() {
throw new AdbReverseNotSupportedError();
}

clearReverseTunnels() {
throw new AdbReverseNotSupportedError();
}
}
```

## Forward tunnel

This mode can be used as a fallback when reverse tunnel is not supported. In forward tunnel mode, the server listens on the Unix domain socket address, and the client creates multiple connections to it.
Expand Down Expand Up @@ -91,12 +125,12 @@ You also need retry the connection until the correct amount of sockets are creat
### With `@yume-chan/adb-scrcpy`

When `tunnelForward: true` option is specified, `AdbScrcpyClient` automatically uses forward tunnel mode to connect to Scrcpy server.
{/*
{/\*
Besides that, if reverse tunnel is not supported (when `reverse.add` method throws an `AdbReverseNotSupportedError`), `AdbScrcpyClient` will automatically modify the options to use forward tunnel instead.

If you don't want to or can't implement reverse tunnel commands in your custom transport, you can set `tunnelForward: true` option explicitly, or also throw an `AdbReverseNotSupportedError` in these methods:

```ts
````ts
import { AdbReverseNotSupportedError, AdbTransport } from "@yume-chan/adb";

class YourTransport implements AdbTransport {
Expand All @@ -115,3 +149,4 @@ class YourTransport implements AdbTransport {
}
}
``` */}
````
4 changes: 2 additions & 2 deletions docs/tango/custom-transport/transport.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AdbTransport {

addReverseTunnel(
handler: AdbIncomingSocketHandler,
address?: string,
address?: string
): string | Promise<string>;

removeReverseTunnel(address: string): void | Promise<void>;
Expand Down Expand Up @@ -96,7 +96,7 @@ class MockTransport implements AdbTransport {

addReverseTunnel(
handler: AdbIncomingSocketHandler,
address?: string | undefined,
address?: string | undefined
): ValueOrPromise<string> {
throw new Error("Method not implemented.");
}
Expand Down

0 comments on commit 64284b4

Please sign in to comment.