Skip to main content

Options

Scrcpy protocol changes over time, and are usually not backward compatible. Tango is compatible with many versions of Scrcpy server, by providing a set of options classes for each server version (or range).

The options class serves two purposes:

  • It defines which server options are available (for you, the user)
  • It normalize the behavior between different server versions (for internal use)

It's important to use the correct options class for the server version you're using. Using an incorrect version almost always results in errors.

If the latest version of Scrcpy server is not declared as supported, you may try using the options class for the previous version. If it doesn't work, you may need to wait for an update.

With @yume-chan/scrcpy

Each time a new option is added to the server, or a breaking change is introduced, a new options class is added. The class name has a pattern of ScrcpyOptionsX_YY, where X is the major version and YY is the minor version. For example, ScrcpyOptions2_1 is the options class for server version 2.1.

Some Scrcpy versions contain only bug fixes or client-side changes, so they don't have a corresponding options class. In this case, the option class for the previous version can be used.

Check the versions page to see which options class to use for each server version.

Create options

All options classes take a single object parameter for server options:

import { ScrcpyOptions2_2 } from "@yume-chan/scrcpy";

const options = new ScrcpyOptions2_2({
videoSource: "camera",
// ...
});

Check the TypeScript definition files for available server options in each version.

All server options are optional, the default value can be found in ScrcpyOptionsX_YY.DEFAULTS or options.defaults fields.

Since the options class is stateful, don't reuse the same instance for multiple connections. Except, for other APIs that operate on the connection, the same options instance can be used.

Watch device clipboard changes

Scrcpy server will monitor the clipboard on the device and send the content to client when it changes. Only text content in clipboard is supported.

options.clipboard is a ReadableStream<string>. Like other streams, you must keep reading from it to prevent blocking the whole connection.

note

See Web Streams Basics page for a quick introduction to ReadableStream, WriteableStream, and other types from Web Streams API.

options.clipboard
.pipeTo(
new WritableStream({
write(value) {
console.log(value);
},
})
)
.catch(console.error);

You should use .catch and not await the returned Promise, since the Promise will never resolve.

Upcoming changes

Due to a design oversight, the .cancel() method on options.clipboard will cause an error, and the stream never ends when connection is closed. These issues will be fixed in the next version.

If an error happened in the device message socket, options.clipboard will enter an error state and no longer emit more values. The catch handler on the pipeTo call will be called with the error.

With @yume-chan/adb-scrcpy

@yume-chan/adb-scrcpy needs to do some additional behavior normalizations, so it has its own options classes. The naming convention is the same as @yume-chan/scrcpy, but with an Adb prefix. For example, AdbScrcpyOptions2_1 is the options class for server version 2.1.

It's more rare for protocol changes to affect AdbScrcpyOptionsX_YY, thus there are fewer AdbScrcpyOptionsX_YY classes than ScrcpyOptionsX_YY classes, and the versions between them don't always match.

Check the versions page to see which options class to use for each server version.

AdbScrcpyOptionsX_YY wraps a ScrcpyOptionsX_YY instance, so read the previous section and create a ScrcpyOptionsX_YY instance first.

import { AdbScrcpyOptions2_1 } from "@yume-chan/adb-scrcpy";
import { ScrcpyOptions2_2 } from "@yume-chan/scrcpy";

const options = new AdbScrcpyOptions2_1(
new ScrcpyOptions2_2({
videoSource: "camera",
// ...
})
);

options.clipboard
.pipeTo(
new WritableStream({
write(value) {
console.log(value);
},
})
)
.catch(console.error);

options.clipboard is also available in AdbScrcpyOptionsX_YY, the usage is the same.