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,