@yume-chan/scrcpy
Version:
TypeScript implementation of Scrcpy client.
87 lines • 2.64 kB
JavaScript
import { Consumable } from "@yume-chan/stream-extra";
import { ScrcpyControlMessageSerializer } from "./serializer.js";
export class ScrcpyControlMessageWriter {
#writer;
#serializer;
constructor(writer, options) {
this.#writer = writer;
this.#serializer = new ScrcpyControlMessageSerializer(options);
}
write(message) {
return Consumable.WritableStream.write(this.#writer, message);
}
injectKeyCode(message) {
return this.write(this.#serializer.injectKeyCode(message));
}
injectText(text) {
return this.write(this.#serializer.injectText(text));
}
/**
* `pressure` is a float value between 0 and 1.
*/
injectTouch(message) {
return this.write(this.#serializer.injectTouch(message));
}
/**
* `scrollX` and `scrollY` are float values between 0 and 1.
*/
async injectScroll(message) {
const data = this.#serializer.injectScroll(message);
if (data) {
await this.write(data);
}
}
async backOrScreenOn(action) {
const data = this.#serializer.backOrScreenOn(action);
if (data) {
await this.write(data);
}
}
setScreenPowerMode(mode) {
return this.write(this.#serializer.setDisplayPower(mode));
}
expandNotificationPanel() {
return this.write(this.#serializer.expandNotificationPanel());
}
expandSettingPanel() {
return this.write(this.#serializer.expandSettingPanel());
}
collapseNotificationPanel() {
return this.write(this.#serializer.collapseNotificationPanel());
}
rotateDevice() {
return this.write(this.#serializer.rotateDevice());
}
async setClipboard(message) {
const result = this.#serializer.setClipboard(message);
if (result instanceof Uint8Array) {
await this.write(result);
}
else {
await this.write(result[0]);
await result[1];
}
}
uHidCreate(message) {
return this.write(this.#serializer.uHidCreate(message));
}
uHidInput(message) {
return this.write(this.#serializer.uHidInput(message));
}
uHidDestroy(id) {
return this.write(this.#serializer.uHidDestroy(id));
}
startApp(name, options) {
return this.write(this.#serializer.startApp(name, options));
}
resetVideo() {
return this.write(this.#serializer.resetVideo());
}
releaseLock() {
this.#writer.releaseLock();
}
async close() {
await this.#writer.close();
}
}
//# sourceMappingURL=writer.js.map