feat: add select deviceId
This commit is contained in:
@@ -16,6 +16,7 @@ export class WhatsAppClient {
|
|||||||
|
|
||||||
private url: string = "";
|
private url: string = "";
|
||||||
private socket: WebSocket | null = null;
|
private socket: WebSocket | null = null;
|
||||||
|
private deviceId: string | undefined = undefined;
|
||||||
|
|
||||||
private pending = new Map<
|
private pending = new Map<
|
||||||
string,
|
string,
|
||||||
@@ -28,8 +29,13 @@ export class WhatsAppClient {
|
|||||||
|
|
||||||
private listeners: Map<string, (...args: any[]) => void> = new Map();
|
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.url = url;
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
setDeviceId(id?: string | null) {
|
||||||
|
this.deviceId = id || undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
@@ -89,6 +95,7 @@ export class WhatsAppClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
|
const deviceId = this.deviceId;
|
||||||
|
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
@@ -106,6 +113,7 @@ export class WhatsAppClient {
|
|||||||
this.socket!.send(
|
this.socket!.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "request",
|
type: "request",
|
||||||
|
deviceId,
|
||||||
id,
|
id,
|
||||||
method,
|
method,
|
||||||
params,
|
params,
|
||||||
|
|||||||
+7
-4
@@ -5,10 +5,12 @@ import { getId } from "./ui/src/lib/utils";
|
|||||||
const wa = new WhatsAppClient(process.env.WS_URL);
|
const wa = new WhatsAppClient(process.env.WS_URL);
|
||||||
await wa.connect();
|
await wa.connect();
|
||||||
|
|
||||||
// console.log("status", await wa.status());
|
const devices = await wa.listDevices();
|
||||||
|
console.log("devices", devices);
|
||||||
|
|
||||||
// const devices = await wa.listDevices();
|
wa.setDeviceId("1789898358415");
|
||||||
// console.log("devices", devices);
|
// await wa.exec("window.location.reload(); return 1;");
|
||||||
|
console.log("status", await wa.status());
|
||||||
|
|
||||||
// const data = JSON.stringify({
|
// const data = JSON.stringify({
|
||||||
// DEVICE_ID: "1789636162707",
|
// 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 localStorage.getItem('wa-bridge-consts');`);
|
||||||
|
|
||||||
// const test = await wa.exec(`return document.hasFocus();`);
|
// 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);
|
console.log("test", test);
|
||||||
|
|
||||||
// const test = await wa.exec(`return GM_info.script.version;`);
|
// const test = await wa.exec(`return GM_info.script.version;`);
|
||||||
|
|||||||
Reference in New Issue
Block a user