diff --git a/libraries/adb-daemon-webusb/src/observer.ts b/libraries/adb-daemon-webusb/src/observer.ts index 580503a81..81cbe330f 100644 --- a/libraries/adb-daemon-webusb/src/observer.ts +++ b/libraries/adb-daemon-webusb/src/observer.ts @@ -20,9 +20,6 @@ export class AdbDaemonWebUsbDeviceObserver #exclusionFilters?: USBDeviceFilter[] | undefined; #usbManager: USB; - #onError = new EventEmitter(); - onError = this.#onError.event; - #onDeviceAdd = new EventEmitter(); onDeviceAdd = this.#onDeviceAdd.event; @@ -86,7 +83,6 @@ export class AdbDaemonWebUsbDeviceObserver this.#handleDisconnect, ); - this.#onError.dispose(); this.#onDeviceAdd.dispose(); this.#onDeviceRemove.dispose(); this.#onListChange.dispose(); diff --git a/libraries/adb/src/device-observer.ts b/libraries/adb/src/device-observer.ts index 201d336f5..f00ed26cc 100644 --- a/libraries/adb/src/device-observer.ts +++ b/libraries/adb/src/device-observer.ts @@ -2,7 +2,6 @@ import type { MaybePromiseLike } from "@yume-chan/async"; import type { Event } from "@yume-chan/event"; export interface DeviceObserver { - onError: Event; onDeviceAdd: Event; onDeviceRemove: Event; onListChange: Event; diff --git a/libraries/adb/src/server/client.ts b/libraries/adb/src/server/client.ts index 6d6997a4d..a2819bdbf 100644 --- a/libraries/adb/src/server/client.ts +++ b/libraries/adb/src/server/client.ts @@ -2,6 +2,7 @@ import type { MaybePromiseLike } from "@yume-chan/async"; import { PromiseResolver } from "@yume-chan/async"; +import type { Event } from "@yume-chan/event"; import { EventEmitter } from "@yume-chan/event"; import { getUint64LittleEndian } from "@yume-chan/no-data-view"; import type { @@ -24,7 +25,7 @@ import { import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js"; import { AdbBanner } from "../banner.js"; -import type { DeviceObserver } from "../device-observer.js"; +import type { DeviceObserver as DeviceObserverBase } from "../device-observer.js"; import type { AdbFeature } from "../features.js"; import { hexToNumber, sequenceEqual, write4HexDigits } from "../utils/index.js"; @@ -287,7 +288,7 @@ export class AdbServerClient { /** * Monitors device list changes. */ - async trackDevices(): Promise> { + async trackDevices(): Promise { const connection = await this.createConnection("host:track-devices-l"); let current: AdbServerClient.Device[] = []; @@ -752,4 +753,8 @@ export namespace AdbServerClient { } } } + + export interface DeviceObserver extends DeviceObserverBase { + onError: Event; + } } diff --git a/libraries/scrcpy-decoder-tinyh264/src/decoder.ts b/libraries/scrcpy-decoder-tinyh264/src/decoder.ts index 0e3037ba6..a7a758f62 100644 --- a/libraries/scrcpy-decoder-tinyh264/src/decoder.ts +++ b/libraries/scrcpy-decoder-tinyh264/src/decoder.ts @@ -17,19 +17,10 @@ import type { import type { TinyH264Wrapper } from "./wrapper.js"; import { createTinyH264Wrapper } from "./wrapper.js"; -const NOOP = () => { +const noop = () => { // no-op }; -export interface TinyH264DecoderInit { - /** - * Optional render target canvas element or offscreen canvas. - * If not provided, a new `` (when DOM is available) - * or a `OffscreenCanvas` will be created. - */ - canvas?: HTMLCanvasElement | OffscreenCanvas | undefined; -} - export function createCanvas() { if (typeof document !== "undefined") { return document.createElement("canvas"); @@ -77,7 +68,7 @@ export class TinyH264Decoder implements ScrcpyVideoDecoder { #yuvCanvas: YuvCanvas | undefined; #initializer: PromiseResolver | undefined; - constructor({ canvas }: TinyH264DecoderInit = {}) { + constructor({ canvas }: TinyH264Decoder.Options = {}) { if (canvas) { this.#renderer = canvas; } else { @@ -180,7 +171,18 @@ export class TinyH264Decoder implements ScrcpyVideoDecoder { this.#initializer?.promise .then((wrapper) => wrapper.dispose()) // NOOP: It's disposed so nobody cares about the error - .catch(NOOP); + .catch(noop); this.#initializer = undefined; } } + +export namespace TinyH264Decoder { + export interface Options { + /** + * Optional render target canvas element or offscreen canvas. + * If not provided, a new `` (when DOM is available) + * or a `OffscreenCanvas` will be created. + */ + canvas?: HTMLCanvasElement | OffscreenCanvas | undefined; + } +} diff --git a/libraries/scrcpy-decoder-webcodecs/src/video/decoder.ts b/libraries/scrcpy-decoder-webcodecs/src/video/decoder.ts index 53efc006d..a9c66c50f 100644 --- a/libraries/scrcpy-decoder-webcodecs/src/video/decoder.ts +++ b/libraries/scrcpy-decoder-webcodecs/src/video/decoder.ts @@ -96,15 +96,6 @@ const VideoFrameCapturerPool = /* #__PURE__ */ new Pool(() => new VideoFrameCapturer(), 4); -export interface WebCodecsVideoDecoderInit { - /** - * The video codec to decode - */ - codec: ScrcpyVideoCodecId; - - renderer: WebCodecsVideoDecoderRenderer; -} - export class WebCodecsVideoDecoder implements ScrcpyVideoDecoder { static get isSupported() { return typeof globalThis.VideoDecoder !== "undefined"; @@ -164,7 +155,7 @@ export class WebCodecsVideoDecoder implements ScrcpyVideoDecoder { /** * Create a new WebCodecs video decoder. */ - constructor({ codec, renderer }: WebCodecsVideoDecoderInit) { + constructor({ codec, renderer }: WebCodecsVideoDecoder.Options) { this.#codec = codec; this.#renderer = renderer; @@ -303,3 +294,14 @@ export class WebCodecsVideoDecoder implements ScrcpyVideoDecoder { this.#captureFrame?.close(); } } + +export namespace WebCodecsVideoDecoder { + export interface Options { + /** + * The video codec to decode + */ + codec: ScrcpyVideoCodecId; + + renderer: WebCodecsVideoDecoderRenderer; + } +} diff --git a/libraries/scrcpy-decoder-webcodecs/src/video/render/bitmap.ts b/libraries/scrcpy-decoder-webcodecs/src/video/render/bitmap.ts index 1e7b8fa00..3c466a49d 100644 --- a/libraries/scrcpy-decoder-webcodecs/src/video/render/bitmap.ts +++ b/libraries/scrcpy-decoder-webcodecs/src/video/render/bitmap.ts @@ -1,6 +1,6 @@ -import { CanvasWebCodecsVideoDecoderRenderer } from "./canvas.js"; +import { CanvasWebCodecsDecoderRenderer } from "./canvas.js"; -export class BitmapWebCodecsDecoderRenderer extends CanvasWebCodecsVideoDecoderRenderer { +export class BitmapWebCodecsDecoderRenderer extends CanvasWebCodecsDecoderRenderer { #context: ImageBitmapRenderingContext; constructor(canvas?: HTMLCanvasElement | OffscreenCanvas) { diff --git a/libraries/scrcpy-decoder-webcodecs/src/video/render/canvas.ts b/libraries/scrcpy-decoder-webcodecs/src/video/render/canvas.ts index 8fda1698b..5843f4520 100644 --- a/libraries/scrcpy-decoder-webcodecs/src/video/render/canvas.ts +++ b/libraries/scrcpy-decoder-webcodecs/src/video/render/canvas.ts @@ -2,7 +2,7 @@ import { createCanvas } from "@yume-chan/scrcpy-decoder-tinyh264"; import type { WebCodecsVideoDecoderRenderer } from "./type.js"; -export abstract class CanvasWebCodecsVideoDecoderRenderer +export abstract class CanvasWebCodecsDecoderRenderer implements WebCodecsVideoDecoderRenderer { #canvas: HTMLCanvasElement | OffscreenCanvas; diff --git a/libraries/scrcpy-decoder-webcodecs/src/video/render/webgl.ts b/libraries/scrcpy-decoder-webcodecs/src/video/render/webgl.ts index 597409b09..8be1d5a65 100644 --- a/libraries/scrcpy-decoder-webcodecs/src/video/render/webgl.ts +++ b/libraries/scrcpy-decoder-webcodecs/src/video/render/webgl.ts @@ -1,6 +1,6 @@ import { createCanvas } from "@yume-chan/scrcpy-decoder-tinyh264"; -import { CanvasWebCodecsVideoDecoderRenderer } from "./canvas.js"; +import { CanvasWebCodecsDecoderRenderer } from "./canvas.js"; const Resolved = Promise.resolve(); @@ -24,7 +24,7 @@ function createContext( ); } -export class WebGLWebCodecsDecoderRenderer extends CanvasWebCodecsVideoDecoderRenderer { +export class WebGLWebCodecsDecoderRenderer extends CanvasWebCodecsDecoderRenderer { static vertexShaderSource = ` attribute vec2 xy;