diff --git a/src/client/whatsapp.ts b/src/client/whatsapp.ts index 6327229..6661c35 100644 --- a/src/client/whatsapp.ts +++ b/src/client/whatsapp.ts @@ -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 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((resolve, reject) => { const timer = setTimeout(() => { @@ -106,6 +113,7 @@ export class WhatsAppClient { this.socket!.send( JSON.stringify({ type: "request", + deviceId, id, method, params, diff --git a/test-client.ts b/test-client.ts index 8f8c19d..58681f2 100644 --- a/test-client.ts +++ b/test-client.ts @@ -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;`);