Giter VIP home page Giter VIP logo

Comments (3)

drauggres avatar drauggres commented on July 26, 2024

Hi.
There is no such feature now: all my test devices are connected via USB.
But this can be implemented with little effort (assuming adb on device already listens for a tcp/ip connection).

Worth to notice:

  1. to connect adb to device over Wi-Fi (on Android 10 and lower) you must connect it with usb first
  2. ws-scrcpy server detects all connected devices and runs scrcpy-server.jar on them
  3. scrcpy-server.jar will keep running after device disconnection (not like the original scrcpy), i.e. you still can connect to the stream (if you know ip-address of the device)

from ws-scrcpy.

JonahLyu avatar JonahLyu commented on July 26, 2024

I finally made it. this is what I try:
In typings/@devicefarmer/adbkit/index.d.ts, add the following interfaces in AdbKitClient:

export interface AdbKitClient {
    //other interfaces
    forward(serial: string, local: string, remote: string, callback?: Callback<true>): Promise<true>;
    connect(host: string, port?: string, callback?: Callback<string>): Promise<string>;   //add this line
    disconnect(host: string, port?: string, callback?: Callback<string>): Promise<string>; //add this line as well
}

Then in src/server/Util.ts, amend the Util.foward() method. Add the adb connect so it tries to establish a new connection before it searches existing adb forward:

public static async forward(serial: string, remote: string): Promise<number> {
        const client = ADB.createClient();

        //add following lines
        serial = await client.connect(serial);
        console.log(`connect to ${serial}`);
        //add above lines
     
        const forwards = await client.listForwards(serial);
        ...
        return port;
    }

So now I can specify a remote device in the html query:

http://127.0.0.1:8000/#!action=stream&udid=<device host>%3A<device adb port>&decoder=broadway&ip=127.0.0.1&port=8000&query=%3Faction%3Dproxy%26remote%3Dtcp%253A8886%26udid%3D<device host>%253A<device adb port>

But the known issue now is:
how to disconnect the adb automatically when the websocket closes?

Any hint?

from ws-scrcpy.

drauggres avatar drauggres commented on July 26, 2024

It would be convenient to add the following actions before this line (not in the forward method):

const service = ServiceWebsocketProxy.createService(ws, udid, remote, path);

  1. Check if the device already connected
  2. If it is not:
    2.1 call client.connect(..)
    2.2 add ws.onclose = () => { client.disconnect(..); }

P.S. In develop branch I have complete typings for adbkit.

from ws-scrcpy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.