Simplest Vue demo/TS demo that only implements the scrcpy function #592
-
Is there a simplest Vue demo/ts demo that only implements the scrcpy function? I've checked the andbrowser, but it's using an early version of your libraries and most of your API have changed. I have also cloned your whole project and successfully run it, but I'm just starting to learn the front-end, and it's a bit difficult for me to understand your source code. I tried to find the way you run the scrcpy server in your code or the latest API but I failed. I only find |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hello 作者大大. I have written these codes to implements scrcpy in my vue project. <template>
<div>
<el-button @click="handleClick">connect</el-button>
<div ref="div"></div>
</div>
</template>
<script lang="ts" setup>
import { AdbDaemonWebUsbDevice } from '@yume-chan/adb-daemon-webusb'
import { Adb, AdbDaemonTransport } from '@yume-chan/adb'
import AdbWebCredentialStore from '@yume-chan/adb-credential-web'
import { AdbDaemonWebUsbDeviceManager } from '@yume-chan/adb-daemon-webusb'
import {
DEFAULT_SERVER_PATH,
ScrcpyOptions2_0,
ScrcpyVideoCodecId,
} from '@yume-chan/scrcpy'
import { AdbScrcpyClient, AdbScrcpyOptions2_0 } from '@yume-chan/adb-scrcpy'
import SCRCPY_SERVER_VERSION from '@yume-chan/scrcpy/bin/version.js'
import { WebCodecsDecoder } from '@yume-chan/scrcpy-decoder-webcodecs'
import { onMounted, ref } from 'vue'
const CredentialStore = new AdbWebCredentialStore()
let backend: AdbDaemonWebUsbDevice | undefined
const div = ref()
const decoder = new WebCodecsDecoder(ScrcpyVideoCodecId.H264)
onMounted(() => {
div.value.appendChild(decoder.renderer)
})
const handleClick = async () => {
if (!AdbDaemonWebUsbDeviceManager.BROWSER) {
alert('WebUSB is not supported in this browser')
return
}
if (!backend) {
backend = await AdbDaemonWebUsbDeviceManager.BROWSER.requestDevice()
if (!backend) {
alert('No device selected')
return
}
}
const connection = await backend.connect()
// tell user to accept connection on device
const device = new Adb(
await AdbDaemonTransport.authenticate({
serial: backend.serial,
connection,
credentialStore: CredentialStore,
})
)
const result = await device.subprocess.spawnAndWait("echo 'Hello, World!'")
console.log(result.stdout)
const client = await AdbScrcpyClient.start(
device,
DEFAULT_SERVER_PATH,
// If server binary was downloaded manually, must provide the correct version
SCRCPY_SERVER_VERSION,
new AdbScrcpyOptions2_0(
new ScrcpyOptions2_0({
audio: false,
control: false,
})
)
)
const { metadata: videoMetadata, stream: videoPacketStream } =
await client.videoStream
videoPacketStream // from `@yume-chan/scrcpy`
.pipeTo(decoder.writable)
}
</script> But an error happens when I click the button:
Why it happens? I guess this is related to the fact that I didn't download the |
Beta Was this translation helpful? Give feedback.
It's called
scrcpy-server-v{VERSION}
, without extension.It uses
fetch-scrcpy-server
:ya-webadb/apps/demo/package.json
Line 6 in d91fef0
The
fetch-scrcpy-server
script is in the@yume-chan/scrcpy
package, but you do have to addgh-release-fetch@3
package. See the related section in README: https://www.npmjs.com/package/@yume-chan/scrcpy#fetch-scrcpy-serverNote t…