ya-webadb

repository·main·Indexed 25 days ago

https://github.com/yume-chan/ya-webadb

A TypeScript-based re-implementation of the ADB (Android Debugging Bridge) client called Tango, enabling ADB functionality in web browsers, Node.js, and Electron. The repository includes @yume-chan/adb-cli for mimicking standard adb tool functionality, as well as several utility libraries for Android Open Accessory (AOA) protocol via WebUSB, PCM audio playback, C-style structure serialization, and specialized Web Streams API extensions.

Tokens
43.3K
Snippets
56
Records
415
Agent score
85%

What's inside ya-webadb

  1. Overview of Tango

    main
    Tango is a TypeScript re-implementation of the Android Debugging Bridge (ADB) client. It is designed to work across multiple environments, including Chromium-based browsers (such as Chrome for Android), Node.js, and Electron.
  2. Play raw audio sample streams with @yume-chan/pcm-player

    main

    The @yume-chan/pcm-player library allows you to play raw audio sample streams using the Web Audio API. It supports arbitrary channel counts and sample rates, and includes a basic OLA (overlap-add) resampler.

    Available Player Classes

    Choose a player class based on your audio sample format:

    • Int16PcmPlayer: For little-endian 16-bit integer PCM data.
    • Float32PcmPlayer: For 32-bit float PCM data.
    • Float32PlanerPcmPlayer: For 32-bit float PCM data provided in a planar format (two-dimensional array, left channel first).

    Note on Interleaved vs Planar:

    • Non-Planar (e.g., Int16PcmPlayer, Float32PcmPlayer): Audio samples are interleaved (e.g., [L, R, L, R...]).
    • Planar (e.g., Float32PlanerPcmPlayer): Audio samples are in a two-dimensional array (e.g., [[L, L...], [R, R...]]).

    Important: User Activation Requirement

    Because the player constructors create an AudioContext, they must be invoked within a user event handler (such as an onclick event) to comply with browser autoplay policies.

    var player = Int16PcmPlayer(44100);
    player.start();
    player.feed(new Int16Array([0, 0, 0, 0, 0, 0, 0, 0]));
    player.stop(); // `AudioContext` will be closed, so can't be restarted
  3. Use @yume-chan/no-data-view to read/write numbers from Uint8Arrays

    main

    The @yume-chan/no-data-view package provides a set of methods to read and write numbers directly from Uint8Arrays. This approach avoids the memory allocation, performance impact, and GC pressure associated with creating new DataView instances for every short Uint8Array.

    Because these are basic number operations, the performance is nearly identical to native DataView methods, and in some cases (like getBigUint64 and setBigUint64 in Chrome), this implementation is actually faster.

  4. Reboot a device to specific modes with @yume-chan/adb-cli

    main

    Use the reboot command to restart the device. You can specify various modes:

    • bootloader
    • recovery
    • sideload (reboots into recovery and automatically starts sideload mode)
    • sideload-auto-reboot (same as sideload but reboots after sideloading)

    If no mode is specified, it defaults to booting the system image.

  5. Configure Web Streams API polyfills in Node.js

    main

    The @yume-chan/stream-extra library uses ReadableStream, WritableStream, and TransformStream from globalThis. If these are not natively available, it defaults to using web-streams-polyfill.

    In Node.js environments where loading the stream/web module causes compatibility issues with bundlers (like Webpack) or Top Level Await, you can manually assign the streams to globalThis before loading this library:

    import { WritableStream, ReadableStream, TransformStream } from 'stream/web';
    
    (globalThis as any).WritableStream = WritableStream;
    (globalThis as any).ReadableStream = ReadableStream;
    (globalThis as any).TransformStream = TransformStream;
    
    // Now load @yume-chan/stream-extra