forked from danielcardeenas/sulla
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.layer.ts
53 lines (47 loc) Β· 1.21 KB
/
host.layer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Page } from 'puppeteer';
import { HostDevice } from '../model';
import { SocketState } from '../model/enum';
declare module WAPI {
const getHost: () => HostDevice;
const getWAVersion: () => string;
const isConnected: () => boolean;
const getBatteryLevel: () => number;
}
export class HostLayer {
constructor(public page: Page) {
this.page = page;
}
/**
* @returns Current host device details
*/
public async getHostDevice() {
return await this.page.evaluate(() => WAPI.getHost());
}
/**
* Retrieves WA version
*/
public async getWAVersion() {
return await this.page.evaluate(() => WAPI.getWAVersion());
}
/**
* Retrieves the connecction state
*/
public async getConnectionState(): Promise<SocketState> {
return await this.page.evaluate(() => {
//@ts-ignore
return Store.State.default.state;
});
}
/**
* Retrieves if the phone is online. Please note that this may not be real time.
*/
public async isConnected() {
return await this.page.evaluate(() => WAPI.isConnected());
}
/**
* Retrieves Battery Level
*/
public async getBatteryLevel() {
return await this.page.evaluate(() => WAPI.getBatteryLevel());
}
}