Skip to content

Commit 0c384b2

Browse files
codeskyblueCopilot
andauthored
add support of scrcpy 3.3.3 (#62)
* add support of scrcpy 3.3.3 * Update uiautodev/remote/scrcpy.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 26ed255 commit 0c384b2

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

uiautodev/app.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,13 @@ async def handle_android_ws(websocket: WebSocket, serial: str):
155155
serial: device serial
156156
websocket: WebSocket
157157
"""
158+
scrcpy_version = websocket.query_params.get("version", "2.7")
158159
await websocket.accept()
159160

160161
try:
161162
logger.info(f"WebSocket serial: {serial}")
162163
device = adbutils.device(serial)
163-
server = ScrcpyServer(device)
164+
server = ScrcpyServer(device, version=scrcpy_version)
164165
await server.handle_unified_websocket(websocket, serial)
165166
except WebSocketDisconnect:
166167
logger.info(f"WebSocket disconnected by client.")
88.1 KB
Binary file not shown.

uiautodev/remote/scrcpy.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import socket
66
import struct
7+
from pathlib import Path
78
from typing import Optional
89

910
import retry
@@ -24,16 +25,19 @@ class ScrcpyServer:
2425
including video streaming and touch control.
2526
"""
2627

27-
def __init__(self, device: AdbDevice, scrcpy_jar_path: Optional[str] = None):
28+
def __init__(self, device: AdbDevice, version: Optional[str] = "2.7"):
2829
"""
2930
Initializes the ScrcpyServer instance.
3031
3132
Args:
32-
scrcpy_jar_path (str, optional): Path to the scrcpy server JAR file. Defaults to None.
33+
device (AdbDevice): The ADB device instance to use.
34+
version (str, optional): Scrcpy server version to use. Defaults to "2.7".
3335
"""
34-
self.scrcpy_jar_path = scrcpy_jar_path or os.path.join(os.path.dirname(__file__),
35-
'../binaries/scrcpy_server.jar')
36+
self.scrcpy_jar_path = Path(__file__).parent.joinpath(f'../binaries/scrcpy-server-v{version}.jar')
37+
if self.scrcpy_jar_path.exists() is False:
38+
raise FileNotFoundError(f"Scrcpy server JAR not found: {self.scrcpy_jar_path}")
3639
self.device = device
40+
self.version = version
3741
self.resolution_width = 0 # scrcpy 投屏转换宽度
3842
self.resolution_height = 0 # scrcpy 投屏转换高度
3943

@@ -59,6 +63,9 @@ def _parse_scrcpy_info(self, conn: socket.socket):
5963
if not dummy_byte or dummy_byte != b"\x00":
6064
raise ConnectionError("Did not receive Dummy Byte!")
6165
logger.debug('Received Dummy Byte!')
66+
# print('Received Dummy Byte!')
67+
if self.version == '3.3.3': # 临时处理一下, 3.3.3使用WebCodec来接码,前端解析分辨率
68+
return
6269
device_name = conn.recv(64).decode('utf-8').rstrip('\x00')
6370
logger.debug(f'Device name: {device_name}')
6471
codec = conn.recv(4)
@@ -100,10 +107,10 @@ def _start_scrcpy_server(self, control: bool = True) -> AdbConnection:
100107
start_command = (
101108
'CLASSPATH=/data/local/tmp/scrcpy_server.jar '
102109
'app_process / '
103-
'com.genymobile.scrcpy.Server 2.7 '
110+
f'com.genymobile.scrcpy.Server {self.version} '
104111
'log_level=info max_size=1024 max_fps=30 '
105112
'video_bit_rate=8000000 tunnel_forward=true '
106-
'send_frame_meta=false '
113+
'send_frame_meta=true '
107114
f'control={"true" if control else "false"} '
108115
'audio=false show_touches=false stay_awake=false '
109116
'power_off_on_close=false clipboard_autosync=false'

0 commit comments

Comments
 (0)