feat: add select deviceId
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user