@aiot-toolkit/emulator 2.0.5-beta.11 → 2.0.5-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -46
- package/lib/static/proto/README.MD +2 -0
- package/lib/static/proto/emulator_controller.proto +1321 -0
- package/lib/static/proto/rtc_service.proto +117 -0
- package/lib/vvd/grpc/grpcError.d.ts +1 -0
- package/lib/vvd/grpc/grpcError.js +10 -0
- package/lib/vvd/grpc/index.d.ts +27 -0
- package/lib/vvd/grpc/index.js +117 -0
- package/lib/vvd/grpc/types/GrpcClient.d.ts +4 -0
- package/lib/vvd/grpc/types/GrpcClient.js +5 -0
- package/lib/vvd/grpc/types/KeyEvent.d.ts +19 -0
- package/lib/vvd/grpc/types/KeyEvent.js +20 -0
- package/lib/vvd/grpc/types/MouseEvent.d.ts +30 -0
- package/lib/vvd/grpc/types/MouseEvent.js +5 -0
- package/lib/vvd/index.d.ts +2 -0
- package/lib/vvd/index.js +5 -2
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -17,101 +17,134 @@ Vela 模拟器 SDK
|
|
|
17
17
|
## 安装
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
|
-
npm install @aiot/emulator
|
|
20
|
+
npm install @aiot-toolkit/emulator
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## 使用
|
|
24
24
|
|
|
25
|
-
###
|
|
25
|
+
### 初始化环境
|
|
26
26
|
|
|
27
27
|
```ts
|
|
28
28
|
import os from 'os'
|
|
29
29
|
import path from 'path'
|
|
30
|
-
import {
|
|
30
|
+
import { VvdManager } from '@aiot-toolkit/emulator'
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
const
|
|
32
|
+
async function main() {
|
|
33
|
+
const sdkHome = path.resolve(os.homedir(), '.export_dev')
|
|
34
|
+
const velaAvdCls = new VvdManager({ sdkHome })
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
avdArch: IAvdArchType.arm64,
|
|
40
|
-
avdHeight: '466',
|
|
41
|
-
avdWidth: '466',
|
|
42
|
-
imageType: VelaImageType.REL
|
|
36
|
+
const downloder = await velaAvdCls.downloadSDK({
|
|
37
|
+
force: true,
|
|
38
|
+
cliProgress: false,
|
|
39
|
+
parallelDownloads: 6
|
|
43
40
|
})
|
|
41
|
+
|
|
42
|
+
downloder.on('progress', (progress) => {
|
|
43
|
+
console.log(
|
|
44
|
+
`progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await downloder.downlodPromise
|
|
49
|
+
|
|
50
|
+
console.log('download success')
|
|
44
51
|
}
|
|
52
|
+
|
|
53
|
+
main()
|
|
45
54
|
```
|
|
46
55
|
|
|
47
|
-
###
|
|
56
|
+
### 创建 VVD
|
|
48
57
|
|
|
49
58
|
```ts
|
|
50
59
|
import os from 'os'
|
|
51
60
|
import path from 'path'
|
|
52
|
-
import { IAvdArchType,
|
|
61
|
+
import { IAvdArchType, VvdManager, VelaImageType, getDefaultImage } from '@aiot-toolkit/emulator'
|
|
53
62
|
|
|
54
|
-
const
|
|
55
|
-
|
|
63
|
+
const velaAvdCls = new VvdManager({
|
|
64
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
65
|
+
})
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
68
|
+
export async function createVVd() {
|
|
69
|
+
const defaultImage = getDefaultImage()
|
|
70
|
+
velaAvdCls.createVvd({
|
|
71
|
+
name: avdName,
|
|
72
|
+
imageType: defaultImage,
|
|
73
|
+
arch: IVvdArchType.arm,
|
|
74
|
+
imageDir: path.dirname(velaAvdCls.getLocalSystemPath(defaultImage)),
|
|
75
|
+
width: '466',
|
|
76
|
+
height: '466'
|
|
60
77
|
})
|
|
61
78
|
}
|
|
62
79
|
```
|
|
63
80
|
|
|
64
|
-
###
|
|
81
|
+
### 启动 VVD
|
|
65
82
|
|
|
66
83
|
```ts
|
|
67
84
|
import os from 'os'
|
|
68
85
|
import path from 'path'
|
|
69
|
-
import {
|
|
86
|
+
import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
|
|
70
87
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
88
|
+
const velaAvdCls = new VvdManager({
|
|
89
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
90
|
+
})
|
|
74
91
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
92
|
+
export async function startVvd(vvdName: string) {
|
|
93
|
+
/**
|
|
94
|
+
* coldBoot:boolean 是否冷启动
|
|
95
|
+
* emulatorInstance: EmulatorInstance 模拟器实例, 可以通过它与模拟器进行命令交互
|
|
96
|
+
* getAgent: () => Promise<GrpcEmulator> 获取模拟器的Agent,可以通过它与模拟器进行屏幕交互
|
|
97
|
+
*/
|
|
98
|
+
const { coldBoot, emulatorInstance, getAgent } = await velaAvdCls.startVvd({
|
|
99
|
+
vvdName
|
|
79
100
|
})
|
|
80
101
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
102
|
+
// 启动应用
|
|
103
|
+
emulatorInstance.startApp('com.xiaomi.mipicks')
|
|
104
|
+
|
|
105
|
+
const velaAgent = await getAgent()
|
|
106
|
+
// 获取模拟器截图
|
|
107
|
+
const imgBuffer = await velaAgent.getScreenshot()
|
|
108
|
+
// 点击模拟器指定位置,
|
|
109
|
+
await velaAgent.sendMouse({
|
|
110
|
+
x: 100,
|
|
111
|
+
y: 100,
|
|
112
|
+
// 按下
|
|
113
|
+
buttons: 1
|
|
114
|
+
})
|
|
115
|
+
await velaAgent.sendMouse({
|
|
116
|
+
x: 100,
|
|
117
|
+
y: 100,
|
|
118
|
+
// 松开
|
|
119
|
+
buttons: 0
|
|
85
120
|
})
|
|
86
|
-
|
|
87
|
-
await downloder.downlodPromise
|
|
88
|
-
|
|
89
|
-
console.log('download success')
|
|
90
121
|
}
|
|
91
|
-
|
|
92
|
-
main()
|
|
93
122
|
```
|
|
94
123
|
|
|
95
124
|
### 完整示例
|
|
96
125
|
|
|
97
126
|
```ts
|
|
98
127
|
// 安装 npm install @aiot/emulator
|
|
99
|
-
import
|
|
128
|
+
import os from 'os'
|
|
129
|
+
import path from 'path'
|
|
130
|
+
import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
|
|
100
131
|
|
|
101
|
-
const velaAvdCls = new
|
|
132
|
+
const velaAvdCls = new VvdManager({
|
|
133
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
134
|
+
})
|
|
102
135
|
|
|
103
136
|
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
104
137
|
velaAvdCls.createVvd({
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
138
|
+
name: 'O62',
|
|
139
|
+
arch: IAvdArchType.arm64,
|
|
140
|
+
height: '466',
|
|
141
|
+
width: '466',
|
|
109
142
|
imageType: VelaImageType.REL
|
|
110
143
|
})
|
|
111
144
|
|
|
112
145
|
/** 启动名为 'O62' 的模拟器 */
|
|
113
146
|
velaAvdCls.startVvd({
|
|
114
|
-
|
|
147
|
+
vvdName: 'O62'
|
|
115
148
|
})
|
|
116
149
|
|
|
117
150
|
export async function startVvd(vvdName: string) {}
|