feat: add select deviceId

This commit is contained in:
2026-09-22 07:45:40 +08:00
parent 495ee9c040
commit 999ecc1a61
2 changed files with 16 additions and 5 deletions
+9 -1
View File
@@ -16,6 +16,7 @@ export class WhatsAppClient {
private url: string = "";
private socket: WebSocket | null = null;
private deviceId: string | undefined = undefined;
private pending = new Map<
string,
@@ -28,8 +29,13 @@ export class WhatsAppClient {
private listeners: Map<string, (...args: any[]) => void> = new Map();
constructor(url = "ws://127.0.0.1:8787") {
constructor(url = "ws://127.0.0.1:8787", deviceId?: string) {
this.url = url;
this.deviceId = deviceId;
}
setDeviceId(id?: string | null) {
this.deviceId = id || undefined;
}
async connect() {
@@ -89,6 +95,7 @@ export class WhatsAppClient {
}
const id = crypto.randomUUID();
const deviceId = this.deviceId;
return new Promise<T>((resolve, reject) => {
const timer = setTimeout(() => {
@@ -106,6 +113,7 @@ export class WhatsAppClient {
this.socket!.send(
JSON.stringify({
type: "request",
deviceId,
id,
method,
params,
+7 -4
View File
@@ -5,10 +5,12 @@ import { getId } from "./ui/src/lib/utils";
const wa = new WhatsAppClient(process.env.WS_URL);
await wa.connect();
// console.log("status", await wa.status());
const devices = await wa.listDevices();
console.log("devices", devices);
// const devices = await wa.listDevices();
// console.log("devices", devices);
wa.setDeviceId("1789898358415");
// await wa.exec("window.location.reload(); return 1;");
console.log("status", await wa.status());
// const data = JSON.stringify({
// DEVICE_ID: "1789636162707",
@@ -19,7 +21,8 @@ await wa.connect();
// const test = await wa.exec(`return localStorage.getItem('wa-bridge-consts');`);
// const test = await wa.exec(`return document.hasFocus();`);
const test = await wa.exec(`window.location.reload(); return 1;`);
// const test = await wa.exec(`window.location.reload(); return 1;`);
const test = await wa.listChats();
console.log("test", test);
// const test = await wa.exec(`return GM_info.script.version;`);