服务器传输可以拿到设备信息,但是不能执行命令 #753
xu123shuai456
started this conversation in
General
Replies: 4 comments 3 replies
-
|
I don't know hacking so I can't see what your What's the result when calling |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
我使用的是JS语言 export class WebSocketAdbConnector {
constructor(wsUrl) {
this.wsUrl = wsUrl;
}
async connect() {
const ws = new WebSocket(this.wsUrl);
ws.onerror = (error) => {
console.log(error)
ws.close()
throw error
};
ws.binaryType = "arraybuffer";
// 等待连接建立
const connected = new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
reject(new Error("WebSocket connection timeout"));
ws.close();
}, 1000); // 5秒超时
ws.addEventListener("open", () => {
clearTimeout(timeout);
resolve();
});
ws.addEventListener("error", (e) => {
clearTimeout(timeout);
reject(new Error("WebSocket connection failed"));
ws.close();
});
});
// ReadableStream 管理
const readable = new ReadableStream({
start: (controller) => {
const onMessage = (event) => {
if (event.data instanceof ArrayBuffer) {
controller.enqueue(new Uint8Array(event.data));
}
};
const onError = (e) => {
controller.error(new Error("WebSocket error"));
ws.close();
};
ws.addEventListener("message", onMessage);
ws.addEventListener("error", onError);
// 返回清理函数
return () => {
ws.removeEventListener("message", onMessage);
ws.removeEventListener("error", onError);
};
},
cancel: () => {
ws.close();
}
});
// WritableStream 管理
const writable = new WritableStream({
write: async (chunk) => {
await connected;
if (ws.readyState !== WebSocket.OPEN) {
throw new Error("WebSocket not open");
}
ws.send(chunk.buffer);
},
abort: () => {
ws.close();
}
});
return {
readable,
writable,
closed: new Promise((resolve) => {
const onClose = () => resolve();
ws.addEventListener("close", onClose);
// 返回清理函数
return () => ws.removeEventListener("close", onClose);
}),
close: () => {
if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) {
ws.close();
}
}
};
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
非常感谢,我得问题得到了解决 |
Beta Was this translation helpful? Give feedback.
0 replies
-
async pushFile(itemPath, file) {
const sync = await this.device.sync();
try {
await sync.write({
filename: itemPath,
file: file.stream()
});
} catch (e) {
await sync.dispose();
throw e;
}
await sync.dispose();
}
async pullFile(itemPath){
const sync = await this.device.sync();
let data = [];
try {
let stream = await sync.read(itemPath);
await stream.pipeTo(
new WritableStream({
write: (v) => {
data.push(v);
},
})
);
} catch (e) {
sync.dispose();
throw e;
}
sync.dispose();
return new Blob(data);
}目前可以执行命令,但是在执行读写文件的时候,发现还是会被卡住 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
const connector = new WebSocketAdbConnector("http://localhost:8080/")
const client = await new AdbServerClient(connector)
const devices = await getDevicesWithTimeout(client, 1000); // 1秒超时
device = devices[0]
data.deviceName = device.device + " : " + device.serial
console.log(device)
let transport = await client.createTransport({ serial: device.serial });
const observer = await client.trackDevices();
let adb = new Adb(transport);
服务器执行websockify 8080 localhost:5037
目前可以拿到设备信息,但是在执行 await toRaw(adb).subprocess.shellProtocol.spawnWaitText(“ls”);时卡住了
Beta Was this translation helpful? Give feedback.
All reactions