diff --git a/README.md b/README.md index 7b58c908..891e57fd 100644 --- a/README.md +++ b/README.md @@ -131,13 +131,17 @@ You can customize project before build by overriding the * `INCLUDE_GOOG` - include code for Android device tracking and control * `INCLUDE_ADB_SHELL` - [remote shell](#remote-shell) for android devices ([xtermjs/xterm.js][xterm.js], [Tyriar/node-pty][node-pty]) -* `INCLUDE_DEV_TOOLS` - [dev tools](#debug-webpageswebview) for web pages and web views on android -devices +* `INCLUDE_DEV_TOOLS` - [dev tools](#debug-webpageswebview) for web pages and +web views on android devices * `INCLUDE_FILE_LISTING` - minimalistic [file management](#file-listing) * `USE_BROADWAY` - include [Broadway Player](#broadway-player) * `USE_H264_CONVERTER` - include [Mse Player](#mse-player) * `USE_TINY_H264` - include [TinyH264 Player](#tinyh264-player) * `USE_WEBCODECS` - include [WebCodecs Player](#webcodecs-player) +* `SCRCPY_LISTENS_ON_ALL_INTERFACES` - WebSocket server in `scrcpy-server.jar` +will listen for connections on all available interfaces. When `true`, it allows +connecting to device directly from a browser. Otherwise, the connection must be +established over adb. ## Run configuration diff --git a/src/app/googDevice/client/DeviceTracker.ts b/src/app/googDevice/client/DeviceTracker.ts index 232ecd21..7f15bbf8 100644 --- a/src/app/googDevice/client/DeviceTracker.ts +++ b/src/app/googDevice/client/DeviceTracker.ts @@ -80,15 +80,16 @@ export class DeviceTracker extends BaseDeviceTracker { const selectElement = e.currentTarget as HTMLSelectElement; - this.updateLink(selectElement, true); - }; - - private updateLink(selectElement: HTMLSelectElement, store: boolean): void { const option = selectElement.selectedOptions[0]; const url = decodeURI(option.getAttribute(Attribute.URL) || ''); - const name = option.getAttribute(Attribute.NAME); + const name = option.getAttribute(Attribute.NAME) || ''; const fullName = decodeURIComponent(selectElement.getAttribute(Attribute.FULL_NAME) || ''); - const udid = selectElement.getAttribute(Attribute.UDID); + const udid = selectElement.getAttribute(Attribute.UDID) || ''; + this.updateLink({ url, name, fullName, udid, store: true }); + }; + + private updateLink(params: { url: string; name: string; fullName: string; udid: string; store: boolean }): void { + const { url, name, fullName, udid, store } = params; const playerTds = document.getElementsByName( encodeURIComponent(`${DeviceTracker.AttributePrefixPlayerFor}${fullName}`), ); @@ -147,8 +148,7 @@ export class DeviceTracker extends BaseDeviceTracker
@@ -252,6 +255,10 @@ export class DeviceTracker extends BaseDeviceTracker { - const optionElement = DeviceTracker.createInterfaceOption( - { - ...this.params, - secure: false, - hostname: value.ipv4, - port: SERVER_PORT, - }, - value.name, - ); + /// #if SCRCPY_LISTENS_ON_ALL_INTERFACES + device.interfaces.forEach((value) => { + const params = { + ...this.params, + secure: false, + hostname: value.ipv4, + port: SERVER_PORT, + }; + const url = DeviceTracker.createUrl(params).toString(); + const optionElement = DeviceTracker.createInterfaceOption(value.name, url); optionElement.innerText = `${value.name}: ${value.ipv4}`; selectElement.appendChild(optionElement); if (lastSelected) { - if (lastSelected === value.name) { + if (lastSelected === value.name || !selectedInterfaceName) { optionElement.selected = true; + selectedInterfaceUrl = url; + selectedInterfaceName = value.name; } } else if (device['wifi.interface'] === value.name) { optionElement.selected = true; } }); + /// #else + selectedInterfaceUrl = proxyInterfaceUrl; + selectedInterfaceName = proxyInterfaceName; + td.classList.add('hidden'); + /// #endif if (isActive) { - const adbProxyOption = DeviceTracker.createInterfaceOption(this.params, 'proxy', device.udid); - if (lastSelected === 'proxy') { + const adbProxyOption = DeviceTracker.createInterfaceOption(proxyInterfaceName, proxyInterfaceUrl); + if (lastSelected === proxyInterfaceName || !selectedInterfaceName) { adbProxyOption.selected = true; + selectedInterfaceUrl = proxyInterfaceUrl; + selectedInterfaceName = proxyInterfaceName; } selectElement.appendChild(adbProxyOption); const actionButton = document.createElement('button'); @@ -296,7 +312,6 @@ export class DeviceTracker extends BaseDeviceTracker