Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devices and ws-scrcpy on differents machines #255

Open
ngodinhkhanh110 opened this issue Feb 20, 2023 · 3 comments
Open

Devices and ws-scrcpy on differents machines #255

ngodinhkhanh110 opened this issue Feb 20, 2023 · 3 comments

Comments

@ngodinhkhanh110
Copy link

Hello, thank you for the awesome project.
All is working perfectly in local computer.
I want to deploy it on the internet and i have a problem with it.

Now i have some Android devices connect to Windows machine which IP is 10.0.56.12, ws-scrcpy is running on another machine which IP is 10.0.54.34
I have used the nginx stream the adb server port 5037 to 15037 on the remote computer (10.0.56.12):

stream {
server {
listen 5037;
proxy_pass localhost:15037;
}
}

I changed the AdbExtended opts host to 10.0.56.12 and its port to 15037:

export class AdbExtended extends Adb {
static createClient(options: Options = {}): ExtendedClient {
const opts: ClientOptions = {
bin: options.bin,
host: options.host || process.env.ADB_HOST || '10.0.56.12',
port: options.port || 15037,
};
if (!opts.port) {
const port = parseInt(process.env.ADB_PORT || '', 10);
if (!isNaN(port)) {
opts.port = port;
} else {
opts.port = 5037;
}
}
return new ExtendedClient(opts);
}
}

when i opened the browser, i still get the device list but i can not access to the stream (error: [StreamReceiver] WS closed: connect ECONNREFUSED 127.0.0.1:8002)

@drauggres
Copy link
Collaborator

Hi.
First of all, I have no idea if it is possible to proxy adb with nginx. To access devices connected to multiple machines through a single host you can apply configuration.

stream {
server {
listen 5037;
proxy_pass localhost:15037;
}
}

Shouldn't it be the other way around: listen on 15037 and proxy to 5037?
Does it work without ws-scrcpy? If you run adb -H 10.0.56.12 -P 15037 devices on 10.0.54.34, does it print your devices connected to windows machine?

@ngodinhkhanh110
Copy link
Author

Hi, thank you for your answer,

I tried to configure the config.example.yaml file and set path to WS_SCRCPY_CONFIG variable but it doesn't work.
When i removed the nginx configuration or turn it off, i received nothing when i run adb -H 10.0.56.12 -P 15037 (failed to check server version: cannot connect to daemon at tcp:10.0.56.12:15037: cannot connect to 10.0.56.12:15037: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond).

And now my solution is to continue proxy the port 8001 or maybe 8002 in remote computer(10.0.56.12) in nginx because the tcp:8886 in device will be forwarded to tcp:8001 or tcp:8002
After that, i had to change the the ws domain to 10.0.56.12 instead of 127.0.0.1

public static createProxyOverAdb(ws: WS, udid: string, remote: string, path?: string | null): WebsocketProxy {
    const service = new WebsocketProxy(ws);
    AdbUtils.forward(udid, remote)
        .then((port) => {
            const wsUrl = `ws://10.0.56.12:${port}${path ? path : ''}`;
            return service.init(wsUrl);
        })
        .catch((e) => {
            const msg = `[${this.TAG}] Failed to start service: ${e.message}`;
            console.error(msg);
            ws.close(4005, msg);
        });
    return service;
}

And it works, but it is a little bit inconvenient because i don't know the port 8001 or 8002 is fixed or not. Do you have any suggestion?

@areswxin
Copy link

Hi, thank you for your answer,

I tried to configure the config.example.yaml file and set path to WS_SCRCPY_CONFIG variable but it doesn't work. When i removed the nginx configuration or turn it off, i received nothing when i run adb -H 10.0.56.12 -P 15037 (failed to check server version: cannot connect to daemon at tcp:10.0.56.12:15037: cannot connect to 10.0.56.12:15037: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond).

And now my solution is to continue proxy the port 8001 or maybe 8002 in remote computer(10.0.56.12) in nginx because the tcp:8886 in device will be forwarded to tcp:8001 or tcp:8002 After that, i had to change the the ws domain to 10.0.56.12 instead of 127.0.0.1

public static createProxyOverAdb(ws: WS, udid: string, remote: string, path?: string | null): WebsocketProxy {
    const service = new WebsocketProxy(ws);
    AdbUtils.forward(udid, remote)
        .then((port) => {
            const wsUrl = `ws://10.0.56.12:${port}${path ? path : ''}`;
            return service.init(wsUrl);
        })
        .catch((e) => {
            const msg = `[${this.TAG}] Failed to start service: ${e.message}`;
            console.error(msg);
            ws.close(4005, msg);
        });
    return service;
}

And it works, but it is a little bit inconvenient because i don't know the port 8001 or 8002 is fixed or not. Do you have any suggestion?

hi
I have the same problem
I tested it , 8002 is fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants