feat(scrcpy-server): separate package, add support for Vite

This commit is contained in:
Simon Chan 2023-06-27 15:29:35 +08:00
parent 419a7559fe
commit 9b0e06cdfb
No known key found for this signature in database
GPG key ID: 8F75717685A974FB
34 changed files with 4717 additions and 2588 deletions

View file

@ -59,6 +59,7 @@
"tsbuildinfo",
"typeof",
"undici",
"versioncode",
"webadb",
"webcodecs",
"webm",

View file

@ -39,15 +39,6 @@ module.exports = pipe(
basePath,
},
webpack(config) {
// Bundle Scrcpy Server
config.module.rules.push({
resourceQuery: /url/,
type: "asset/resource",
generator: {
filename: "static/chunks/[name].[hash][ext]",
},
});
config.module.rules.push({
test: /.*\.m?js$/,
// disable these modules because they generate a lot of warnings about

View file

@ -27,6 +27,7 @@
"@yume-chan/async": "^2.2.0",
"@yume-chan/b-tree": "workspace:^0.0.20",
"@yume-chan/event": "workspace:^0.0.20",
"@yume-chan/fetch-scrcpy-server": "workspace:^0.0.20",
"@yume-chan/pcm-player": "workspace:^0.0.20",
"@yume-chan/scrcpy": "workspace:^0.0.20",
"@yume-chan/scrcpy-decoder-tinyh264": "workspace:^0.0.20",

View file

@ -1,9 +1,5 @@
import { EventEmitter } from "@yume-chan/event";
const SERVER_URL = new URL(
"@yume-chan/scrcpy/bin/scrcpy-server?url",
import.meta.url
);
import { BIN } from "@yume-chan/fetch-scrcpy-server";
class FetchWithProgress {
public readonly promise: Promise<Uint8Array>;
@ -68,7 +64,7 @@ export function fetchServer(
onProgress?: (e: [downloaded: number, total: number]) => void
) {
if (!cachedValue) {
cachedValue = new FetchWithProgress(SERVER_URL);
cachedValue = new FetchWithProgress(BIN);
cachedValue.promise.catch(() => {
cachedValue = undefined;
});

View file

@ -26,7 +26,7 @@ import {
ScrcpyVideoDecoderConstructor,
TinyH264Decoder,
} from "@yume-chan/scrcpy-decoder-tinyh264";
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version";
import { VERSION } from "@yume-chan/fetch-scrcpy-server";
import { DecodeUtf8Stream, GatherStringStream } from "@yume-chan/stream-extra";
import {
autorun,
@ -305,7 +305,7 @@ export const SETTING_DEFINITIONS = computed(() => {
const displays = await AdbScrcpyClient.getDisplays(
GLOBAL_STATE.adb!,
DEFAULT_SERVER_PATH,
SCRCPY_SERVER_VERSION,
VERSION,
new AdbScrcpyOptionsLatest(
new ScrcpyOptionsLatest({
logLevel: ScrcpyLogLevel.Debug,
@ -403,7 +403,7 @@ export const SETTING_DEFINITIONS = computed(() => {
const encoders = await AdbScrcpyClient.getEncoders(
GLOBAL_STATE.adb!,
DEFAULT_SERVER_PATH,
SCRCPY_SERVER_VERSION,
VERSION,
new AdbScrcpyOptionsLatest(
new ScrcpyOptionsLatest({
logLevel: ScrcpyLogLevel.Debug,
@ -537,7 +537,7 @@ export const SETTING_DEFINITIONS = computed(() => {
const encoders = await AdbScrcpyClient.getEncoders(
GLOBAL_STATE.adb!,
DEFAULT_SERVER_PATH,
SCRCPY_SERVER_VERSION,
VERSION,
new AdbScrcpyOptionsLatest(
new ScrcpyOptionsLatest({
logLevel: ScrcpyLogLevel.Debug,

View file

@ -1,6 +1,7 @@
import { ADB_SYNC_MAX_PACKET_SIZE, encodeUtf8 } from "@yume-chan/adb";
import { AdbDaemonWebUsbDevice } from "@yume-chan/adb-daemon-webusb";
import { AdbScrcpyClient, AdbScrcpyOptionsLatest } from "@yume-chan/adb-scrcpy";
import { VERSION } from "@yume-chan/fetch-scrcpy-server";
import {
Float32PcmPlayer,
Float32PlanerPcmPlayer,
@ -24,7 +25,6 @@ import {
h265ParseConfiguration,
} from "@yume-chan/scrcpy";
import { ScrcpyVideoDecoder } from "@yume-chan/scrcpy-decoder-tinyh264";
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version";
import {
Consumable,
DistributionStream,
@ -268,9 +268,7 @@ export class ScrcpyPageState {
runInAction(() => {
this.log = [];
this.log.push(
`[client] Server version: ${SCRCPY_SERVER_VERSION}`
);
this.log.push(`[client] Server version: ${VERSION}`);
this.log.push(
`[client] Server arguments: ${options
.serialize()
@ -281,7 +279,7 @@ export class ScrcpyPageState {
const client = await AdbScrcpyClient.start(
GLOBAL_STATE.adb!,
DEFAULT_SERVER_PATH,
SCRCPY_SERVER_VERSION,
VERSION,
options
);

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
"pnpmShrinkwrapHash": "e4df30f56423bb267a886bf6a18f1e5de511cd8f",
"pnpmShrinkwrapHash": "44a16b54cd6e6ab0bca0baf63df4de9d614e3857",
"preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f"
}

View file

@ -396,7 +396,7 @@ export class PackageManager extends AdbCommandBase {
return output
.split("\n")
.filter((line) => !!line)
.map(PackageManager.parsePackageListItem);
.map((line) => PackageManager.parsePackageListItem(line));
}
// TODO: install: support split apk formats (`adb install-multiple`)

View file

@ -0,0 +1,5 @@
/index.js
/index.d.ts
/version.js
/version.d.ts
/server.bin

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2020-2023 Simon Chan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1,60 @@
# @yume-chan/fetch-scrcpy-server
A script to download Scrcpy server binary.
## Usage
```shell
fetch-scrcpy-server <version>
```
For example:
```shell
fetch-scrcpy-server 2.1
```
The server binary is written to `server.bin` and the version is written to `version.js` in this package's root.
## Autorun
Add to `postinstall` script in `package.json`:
```json
{
"scripts": {
"postinstall": "fetch-scrcpy-server 2.1"
}
}
```
## Use in code
### Webpack/Vite
It works out of the box for Webpack 5 and Vite.
`BIN` is a URL you can use in `fetch` to download.
```js
import { BIN, VERSION } from "@yume-chan/fetch-scrcpy-server";
console.log(VERSION); // 2.1
fetch(BIN)
.then((res) => res.arrayBuffer())
.then(console.log); // <ArrayBuffer ...>
```
### Node.js
This package is in ES Module format, so it needs to be imported in another ES Module, or using `createRequire`.
`BIN` is a URL to a local file, you can use `fs.readFile` to read it.
```js
import { BIN, VERSION } from "@yume-chan/fetch-scrcpy-server";
import fs from "fs/promises";
console.log(VERSION); // 2.1
fs.readFile(BIN).then(console.log); // <Buffer ...>
```

View file

@ -12,7 +12,7 @@ const fs = require("fs").promises;
}
console.log(`Downloading Scrcpy server binary version ${serverVersion}...`);
const binFolder = path.resolve(__dirname, "..", "bin");
const binFolder = path.resolve(__dirname, "..");
await fetchVersion({
repository: "Genymobile/scrcpy",
@ -24,15 +24,34 @@ const fs = require("fs").promises;
await fs.rename(
path.resolve(binFolder, `scrcpy-server-v${serverVersion}`),
path.resolve(binFolder, "scrcpy-server")
path.resolve(binFolder, "server.bin")
);
fs.writeFile(
path.resolve(binFolder, "index.js"),
`
export const VERSION ='${serverVersion}';
export const BIN = new URL('./server.bin', import.meta.url);
`
);
fs.writeFile(
path.resolve(binFolder, "index.d.ts"),
`
export const VERSION: '${serverVersion}';
export const BIN: URL;
`
);
fs.writeFile(
path.resolve(binFolder, "version.js"),
`export default '${serverVersion}';`
`
export const VERSION ='${serverVersion}';
`
);
fs.writeFile(
path.resolve(binFolder, "version.d.ts"),
`export default '${serverVersion}';`
`
export const VERSION: '${serverVersion}';
`
);
})();

View file

@ -0,0 +1,5 @@
import { BIN, VERSION } from "@yume-chan/fetch-scrcpy-server";
import fs from "fs/promises";
console.log(VERSION);
fs.readFile(BIN).then(console.log);

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"checkJs": true
},
}

View file

@ -0,0 +1,19 @@
{
"name": "example-node",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"author": "",
"license": "ISC",
"type": "module",
"dependencies": {
"@yume-chan/fetch-scrcpy-server": "link:../.."
},
"devDependencies": {
"@types/node": "^20.3.2"
}
}

View file

@ -0,0 +1,21 @@
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@yume-chan/fetch-scrcpy-server':
specifier: link:../..
version: link:../..
devDependencies:
'@types/node':
specifier: ^20.3.2
version: 20.3.2
packages:
/@types/node@20.3.2:
resolution: {integrity: sha512-vOBLVQeCQfIcF/2Y7eKFTqrMnizK5lRNQ7ykML/5RuwVXVWxYkgwS7xbt4B6fKCUPgbSL5FSsjHQpaGQP/dQmw==}
dev: true

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite Example</title>
</head>
<body>
<script type="module" src="./index.js"></script>
</body>
</html>

View file

@ -0,0 +1,6 @@
import { BIN, VERSION } from "@yume-chan/fetch-scrcpy-server";
console.log(VERSION);
fetch(BIN)
.then((res) => res.arrayBuffer())
.then(console.log);

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"checkJs": true
},
}

View file

@ -0,0 +1,19 @@
{
"name": "example-vite",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "vite",
"build": "vite build",
"start": "vite preview"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"vite": "^4.3.9",
"@yume-chan/fetch-scrcpy-server": "link:../.."
}
}

View file

@ -0,0 +1,315 @@
lockfileVersion: '6.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies:
'@yume-chan/fetch-scrcpy-server':
specifier: path:../../../..
version: link:../..
vite:
specifier: ^4.3.9
version: 4.3.9
packages:
/@esbuild/android-arm64@0.17.19:
resolution: {integrity: sha512-KBMWvEZooR7+kzY0BtbTQn0OAYY7CsiydT63pVEaPtVYF0hXbUaOyZog37DKxK7NF3XacBJOpYT4adIJh+avxA==}
engines: {node: '>=12'}
cpu: [arm64]
os: [android]
requiresBuild: true
dev: false
optional: true
/@esbuild/android-arm@0.17.19:
resolution: {integrity: sha512-rIKddzqhmav7MSmoFCmDIb6e2W57geRsM94gV2l38fzhXMwq7hZoClug9USI2pFRGL06f4IOPHHpFNOkWieR8A==}
engines: {node: '>=12'}
cpu: [arm]
os: [android]
requiresBuild: true
dev: false
optional: true
/@esbuild/android-x64@0.17.19:
resolution: {integrity: sha512-uUTTc4xGNDT7YSArp/zbtmbhO0uEEK9/ETW29Wk1thYUJBz3IVnvgEiEwEa9IeLyvnpKrWK64Utw2bgUmDveww==}
engines: {node: '>=12'}
cpu: [x64]
os: [android]
requiresBuild: true
dev: false
optional: true
/@esbuild/darwin-arm64@0.17.19:
resolution: {integrity: sha512-80wEoCfF/hFKM6WE1FyBHc9SfUblloAWx6FJkFWTWiCoht9Mc0ARGEM47e67W9rI09YoUxJL68WHfDRYEAvOhg==}
engines: {node: '>=12'}
cpu: [arm64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/@esbuild/darwin-x64@0.17.19:
resolution: {integrity: sha512-IJM4JJsLhRYr9xdtLytPLSH9k/oxR3boaUIYiHkAawtwNOXKE8KoU8tMvryogdcT8AU+Bflmh81Xn6Q0vTZbQw==}
engines: {node: '>=12'}
cpu: [x64]
os: [darwin]
requiresBuild: true
dev: false
optional: true
/@esbuild/freebsd-arm64@0.17.19:
resolution: {integrity: sha512-pBwbc7DufluUeGdjSU5Si+P3SoMF5DQ/F/UmTSb8HXO80ZEAJmrykPyzo1IfNbAoaqw48YRpv8shwd1NoI0jcQ==}
engines: {node: '>=12'}
cpu: [arm64]
os: [freebsd]
requiresBuild: true
dev: false
optional: true
/@esbuild/freebsd-x64@0.17.19:
resolution: {integrity: sha512-4lu+n8Wk0XlajEhbEffdy2xy53dpR06SlzvhGByyg36qJw6Kpfk7cp45DR/62aPH9mtJRmIyrXAS5UWBrJT6TQ==}
engines: {node: '>=12'}
cpu: [x64]
os: [freebsd]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-arm64@0.17.19:
resolution: {integrity: sha512-ct1Tg3WGwd3P+oZYqic+YZF4snNl2bsnMKRkb3ozHmnM0dGWuxcPTTntAF6bOP0Sp4x0PjSF+4uHQ1xvxfRKqg==}
engines: {node: '>=12'}
cpu: [arm64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-arm@0.17.19:
resolution: {integrity: sha512-cdmT3KxjlOQ/gZ2cjfrQOtmhG4HJs6hhvm3mWSRDPtZ/lP5oe8FWceS10JaSJC13GBd4eH/haHnqf7hhGNLerA==}
engines: {node: '>=12'}
cpu: [arm]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-ia32@0.17.19:
resolution: {integrity: sha512-w4IRhSy1VbsNxHRQpeGCHEmibqdTUx61Vc38APcsRbuVgK0OPEnQ0YD39Brymn96mOx48Y2laBQGqgZ0j9w6SQ==}
engines: {node: '>=12'}
cpu: [ia32]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-loong64@0.17.19:
resolution: {integrity: sha512-2iAngUbBPMq439a+z//gE+9WBldoMp1s5GWsUSgqHLzLJ9WoZLZhpwWuym0u0u/4XmZ3gpHmzV84PonE+9IIdQ==}
engines: {node: '>=12'}
cpu: [loong64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-mips64el@0.17.19:
resolution: {integrity: sha512-LKJltc4LVdMKHsrFe4MGNPp0hqDFA1Wpt3jE1gEyM3nKUvOiO//9PheZZHfYRfYl6AwdTH4aTcXSqBerX0ml4A==}
engines: {node: '>=12'}
cpu: [mips64el]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-ppc64@0.17.19:
resolution: {integrity: sha512-/c/DGybs95WXNS8y3Ti/ytqETiW7EU44MEKuCAcpPto3YjQbyK3IQVKfF6nbghD7EcLUGl0NbiL5Rt5DMhn5tg==}
engines: {node: '>=12'}
cpu: [ppc64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-riscv64@0.17.19:
resolution: {integrity: sha512-FC3nUAWhvFoutlhAkgHf8f5HwFWUL6bYdvLc/TTuxKlvLi3+pPzdZiFKSWz/PF30TB1K19SuCxDTI5KcqASJqA==}
engines: {node: '>=12'}
cpu: [riscv64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-s390x@0.17.19:
resolution: {integrity: sha512-IbFsFbxMWLuKEbH+7sTkKzL6NJmG2vRyy6K7JJo55w+8xDk7RElYn6xvXtDW8HCfoKBFK69f3pgBJSUSQPr+4Q==}
engines: {node: '>=12'}
cpu: [s390x]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/linux-x64@0.17.19:
resolution: {integrity: sha512-68ngA9lg2H6zkZcyp22tsVt38mlhWde8l3eJLWkyLrp4HwMUr3c1s/M2t7+kHIhvMjglIBrFpncX1SzMckomGw==}
engines: {node: '>=12'}
cpu: [x64]
os: [linux]
requiresBuild: true
dev: false
optional: true
/@esbuild/netbsd-x64@0.17.19:
resolution: {integrity: sha512-CwFq42rXCR8TYIjIfpXCbRX0rp1jo6cPIUPSaWwzbVI4aOfX96OXY8M6KNmtPcg7QjYeDmN+DD0Wp3LaBOLf4Q==}
engines: {node: '>=12'}
cpu: [x64]
os: [netbsd]
requiresBuild: true
dev: false
optional: true
/@esbuild/openbsd-x64@0.17.19:
resolution: {integrity: sha512-cnq5brJYrSZ2CF6c35eCmviIN3k3RczmHz8eYaVlNasVqsNY+JKohZU5MKmaOI+KkllCdzOKKdPs762VCPC20g==}
engines: {node: '>=12'}
cpu: [x64]
os: [openbsd]
requiresBuild: true
dev: false
optional: true
/@esbuild/sunos-x64@0.17.19:
resolution: {integrity: sha512-vCRT7yP3zX+bKWFeP/zdS6SqdWB8OIpaRq/mbXQxTGHnIxspRtigpkUcDMlSCOejlHowLqII7K2JKevwyRP2rg==}
engines: {node: '>=12'}
cpu: [x64]
os: [sunos]
requiresBuild: true
dev: false
optional: true
/@esbuild/win32-arm64@0.17.19:
resolution: {integrity: sha512-yYx+8jwowUstVdorcMdNlzklLYhPxjniHWFKgRqH7IFlUEa0Umu3KuYplf1HUZZ422e3NU9F4LGb+4O0Kdcaag==}
engines: {node: '>=12'}
cpu: [arm64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/@esbuild/win32-ia32@0.17.19:
resolution: {integrity: sha512-eggDKanJszUtCdlVs0RB+h35wNlb5v4TWEkq4vZcmVt5u/HiDZrTXe2bWFQUez3RgNHwx/x4sk5++4NSSicKkw==}
engines: {node: '>=12'}
cpu: [ia32]
os: [win32]
requiresBuild: true
dev: false
optional: true
/@esbuild/win32-x64@0.17.19:
resolution: {integrity: sha512-lAhycmKnVOuRYNtRtatQR1LPQf2oYCkRGkSFnseDAKPl8lu5SOsK/e1sXe5a0Pc5kHIHe6P2I/ilntNv2xf3cA==}
engines: {node: '>=12'}
cpu: [x64]
os: [win32]
requiresBuild: true
dev: false
optional: true
/esbuild@0.17.19:
resolution: {integrity: sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==}
engines: {node: '>=12'}
hasBin: true
requiresBuild: true
optionalDependencies:
'@esbuild/android-arm': 0.17.19
'@esbuild/android-arm64': 0.17.19
'@esbuild/android-x64': 0.17.19
'@esbuild/darwin-arm64': 0.17.19
'@esbuild/darwin-x64': 0.17.19
'@esbuild/freebsd-arm64': 0.17.19
'@esbuild/freebsd-x64': 0.17.19
'@esbuild/linux-arm': 0.17.19
'@esbuild/linux-arm64': 0.17.19
'@esbuild/linux-ia32': 0.17.19
'@esbuild/linux-loong64': 0.17.19
'@esbuild/linux-mips64el': 0.17.19
'@esbuild/linux-ppc64': 0.17.19
'@esbuild/linux-riscv64': 0.17.19
'@esbuild/linux-s390x': 0.17.19
'@esbuild/linux-x64': 0.17.19
'@esbuild/netbsd-x64': 0.17.19
'@esbuild/openbsd-x64': 0.17.19
'@esbuild/sunos-x64': 0.17.19
'@esbuild/win32-arm64': 0.17.19
'@esbuild/win32-ia32': 0.17.19
'@esbuild/win32-x64': 0.17.19
dev: false
/fsevents@2.3.2:
resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
requiresBuild: true
dev: false
optional: true
/nanoid@3.3.6:
resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
dev: false
/picocolors@1.0.0:
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
dev: false
/postcss@8.4.24:
resolution: {integrity: sha512-M0RzbcI0sO/XJNucsGjvWU9ERWxb/ytp1w6dKtxTKgixdtQDq4rmx/g8W1hnaheq9jgwL/oyEdH5Bc4WwJKMqg==}
engines: {node: ^10 || ^12 || >=14}
dependencies:
nanoid: 3.3.6
picocolors: 1.0.0
source-map-js: 1.0.2
dev: false
/rollup@3.25.3:
resolution: {integrity: sha512-ZT279hx8gszBj9uy5FfhoG4bZx8c+0A1sbqtr7Q3KNWIizpTdDEPZbV2xcbvHsnFp4MavCQYZyzApJ+virB8Yw==}
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
hasBin: true
optionalDependencies:
fsevents: 2.3.2
dev: false
/source-map-js@1.0.2:
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}
dev: false
/vite@4.3.9:
resolution: {integrity: sha512-qsTNZjO9NoJNW7KnOrgYwczm0WctJ8m/yqYAMAK9Lxt4SoySUfS5S8ia9K7JHpa3KEeMfyF8LoJ3c5NeBJy6pg==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
peerDependencies:
'@types/node': '>= 14'
less: '*'
sass: '*'
stylus: '*'
sugarss: '*'
terser: ^5.4.0
peerDependenciesMeta:
'@types/node':
optional: true
less:
optional: true
sass:
optional: true
stylus:
optional: true
sugarss:
optional: true
terser:
optional: true
dependencies:
esbuild: 0.17.19
postcss: 8.4.24
rollup: 3.25.3
optionalDependencies:
fsevents: 2.3.2
dev: false

View file

@ -0,0 +1,11 @@
import { defineConfig } from "vite";
export default defineConfig({
// This example installs the package as symlink
// so this is required to allow vite to access the package
server: {
fs: {
allow: ["../.."],
},
},
});

View file

@ -0,0 +1,3 @@
!/dist
/dist/*
!/dist/index.html

View file

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Webpack Example</title>
</head>
<body>
<script src="./bundle.js"></script>
</body>
</html>

View file

@ -0,0 +1,5 @@
{
"compilerOptions": {
"checkJs": true
},
}

View file

@ -0,0 +1,22 @@
{
"name": "example-webpack",
"private": true,
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "webpack --mode=production",
"start": "serve dist"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.3.2",
"serve": "^14.2.0",
"webpack": "^5.88.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"@yume-chan/fetch-scrcpy-server": "link:../.."
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,6 @@
import { BIN, VERSION } from "@yume-chan/fetch-scrcpy-server";
console.log(VERSION);
fetch(BIN)
.then((res) => res.arrayBuffer())
.then(console.log);

View file

@ -0,0 +1,11 @@
const path = require("path");
const config = {
entry: "./src/index.js",
output: {
path: path.resolve(__dirname, "dist"),
filename: "bundle.js",
},
};
module.exports = config;

View file

@ -0,0 +1,35 @@
{
"name": "@yume-chan/fetch-scrcpy-server",
"version": "0.0.20",
"description": "A script to download Scrcpy server binary.",
"keywords": [
"scrcpy"
],
"license": "MIT",
"author": {
"name": "Simon Chan",
"email": "cnsimonchan@live.com",
"url": "https://chensi.moe/blog"
},
"homepage": "https://github.com/yume-chan/ya-webadb/tree/main/packages/fetch-scrcpy-server#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/yume-chan/ya-webadb.git",
"directory": "packages/fetch-scrcpy-server"
},
"bugs": {
"url": "https://github.com/yume-chan/ya-webadb/issues"
},
"bin": {
"fetch-scrcpy-server": "bin/fetch-server.cjs"
},
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"dependencies": {
"gh-release-fetch": "^3.0.2"
},
"devDependencies": {
"@types/node": "^20.2.1"
}
}

View file

@ -0,0 +1,203 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright (C) 2018 Genymobile
Copyright (C) 2018-2021 Romain Vimont
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View file

@ -9,12 +9,6 @@ It's compatible with the official Scrcpy server binaries.
- [How does Scrcpy work](#how-does-scrcpy-work)
- [What does this package do](#what-does-this-package-do)
- [Prepare server binary](#prepare-server-binary)
- [`fetch-scrcpy-server`](#fetch-scrcpy-server)
- [Use the server binary](#use-the-server-binary)
- [Node.js CommonJS](#nodejs-commonjs)
- [Node.js ES module](#nodejs-es-module)
- [Webpack 4](#webpack-4)
- [Webpack 5](#webpack-5)
- [Server versions](#server-versions)
- [Reading and writing packets](#reading-and-writing-packets)
- [Reading video/audio packets](#reading-videoaudio-packets)
@ -44,116 +38,10 @@ This package can't push nor start the server, nor render the video and audio. It
This package is compatible with many versions of the official server binary, but it doesn't include the server binary itself.
You can download the server binary from official releases (https://github.com/Genymobile/scrcpy/releases), or use the included `fetch-scrcpy-server` script to automate the process.
You can download the server binary from official releases (https://github.com/Genymobile/scrcpy/releases), or use the `@yume-chan/fetch-scrcpy-server` package to automate the process.
The server binary is subject to [Apache License 2.0](https://github.com/Genymobile/scrcpy/blob/master/LICENSE).
### `fetch-scrcpy-server`
This script downloads the server binary from official releases for you.
Before using this script, install `gh-release-fetch@3` package separately:
```sh
npm install --save-dev gh-release-fetch@3
```
Usage:
```
npx fetch-scrcpy-server <version>
```
For example:
```
npx fetch-scrcpy-server 2.1
```
Add it to `scripts.postinstall` in your `package.json`, so running `npm install` automatically invokes the script:
```json
{
"scripts": {
"postinstall": "fetch-scrcpy-server 2.1"
}
}
```
The server binary will be saved to `bin/scrcpy-server` in this package's installation directory (usually in `node_modules`).
It will also save the version number to `bin/version.js`.
```js
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version.js";
console.log(SCRCPY_SERVER_VERSION); // "2.1"
```
### Use the server binary
The server binary file needs to be embedded into your application, the exact method depends on the bundler and runtime.
To name a few:
#### Node.js CommonJS
```ts
const fs = require("fs");
const path: string = require.resolve("@yume-chan/scrcpy/bin/scrcpy-server"); // Or your own server binary path
const buffer: Buffer = fs.readFileSync(path);
```
#### Node.js ES module
Without the `import.meta.resolve` feature:
```ts
import fs from "node:fs/promises";
import { createRequire } from "node:module";
const path: string = createRequire(import.meta.url).resolve(
"@yume-chan/scrcpy/bin/scrcpy-server"
); // Or your own server binary path
const buffer: Buffer = await fs.readFile(path);
```
With `import.meta.resolve` feature (requires `--experimental-import-meta-resolve` command line flag for Node.js 12.6.0+):
```ts
import fs from "node:fs/promises";
const path: string = await import.meta.resolve(
"@yume-chan/scrcpy/bin/scrcpy-server"
);
const buffer: Buffer = await fs.readFile(path);
```
#### Webpack 4
Requires installing and configuring file-loader (https://v4.webpack.js.org/loaders/file-loader/)
```ts
import SCRCPY_SERVER_URL from "@yume-chan/scrcpy/bin/scrcpy-server"; // Or your own server binary path
const buffer: ArrayBuffer = await fetch(SCRCPY_SERVER_URL).then((response) =>
response.arrayBuffer()
);
```
#### Webpack 5
Requires configuring Asset Modules (https://webpack.js.org/guides/asset-modules/)
```ts
const SCRCPY_SERVER_URL = new URL(
"@yume-chan/scrcpy/bin/scrcpy-server",
import.meta.url
); // Or your own server binary path
const buffer: ArrayBuffer = await fetch(SCRCPY_SERVER_URL).then((response) =>
response.arrayBuffer()
);
```
## Server versions
Scrcpy protocol changes over time, and are usually not backwards compatible. This package supports multiple server versions (ranges), and uses different option types to choose different behaviors. Using incorrect option version usually results in errors.

View file

@ -445,6 +445,12 @@
"shouldPublish": true,
"versionPolicyName": "adb"
},
{
"packageName": "@yume-chan/fetch-scrcpy-server",
"projectFolder": "libraries/fetch-scrcpy-server",
"shouldPublish": true,
"versionPolicyName": "adb"
},
{
"packageName": "@yume-chan/scrcpy-decoder-tinyh264",
"projectFolder": "libraries/scrcpy-decoder-tinyh264",