-
Notifications
You must be signed in to change notification settings - Fork 208
/
Copy pathclient.ts
38 lines (32 loc) · 924 Bytes
/
client.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
import * as maa from './maa'
import { Resource } from './resource'
export class AgentClient {
handle: maa.AgentClientHandle
constructor() {
const h = maa.agent_client_create()
if (!h) {
throw 'AgentClient create failed'
}
this.handle = h
}
destroy() {
maa.agent_client_destroy(this.handle)
}
bind_resource(resource: Resource) {
if (!maa.agent_client_bind_resource(this.handle, resource.handle)) {
throw 'AgentClient bind resource failed'
}
}
start_child(identifier: string | null) {
const rid = maa.agent_client_start_child(this.handle, identifier)
if (rid === null) {
throw 'AgentClient start child failed'
}
return rid
}
connect() {
if (!maa.agent_client_connect(this.handle)) {
throw 'AgentClient connect failed'
}
}
}