@cpzxrobot/sdk 1.2.92 → 1.2.93
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/device_gateway.ts +1 -1
- package/dist/device_gateway.js +1 -1
- package/dist/index.js +14 -411
- package/dist/mobile_platform.js +154 -0
- package/dist/platform_interface.js +12 -0
- package/dist/user_gateway.js +14 -32
- package/dist/web_platform.js +291 -0
- package/dist/windows_platform.js +128 -0
- package/index.ts +20 -454
- package/mobile_platform.ts +179 -0
- package/package.json +1 -1
- package/platform_interface.ts +35 -0
- package/types.d.ts +12 -10
- package/user_gateway.ts +14 -32
- package/web_platform.ts +322 -0
- package/windows_platform.ts +129 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { PlatformInterface } from "./platform_interface";
|
|
2
|
+
import { Factory, MyAxiosInstance, Unit } from "./types";
|
|
3
|
+
|
|
4
|
+
export class WindwosMiniAppPlatform implements PlatformInterface {
|
|
5
|
+
private messagePort?: MessagePort;
|
|
6
|
+
private sseCallbacks: { [key: string]: (data: any) => void } = {};
|
|
7
|
+
token: string = "";
|
|
8
|
+
appCode: string = "";
|
|
9
|
+
baseURL: string = "";
|
|
10
|
+
|
|
11
|
+
constructor() {
|
|
12
|
+
window.addEventListener('message', (event) => {
|
|
13
|
+
if (event.data == 'capturePort') {
|
|
14
|
+
if (event.ports[0] != null) {
|
|
15
|
+
this.messagePort = event.ports[0];
|
|
16
|
+
this.messagePort.onmessage = (event) => {
|
|
17
|
+
if (event.data.id != undefined) {
|
|
18
|
+
const callback = this.sseCallbacks[event.data.id];
|
|
19
|
+
callback?.(event.data.data);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}, false);
|
|
25
|
+
}
|
|
26
|
+
setSelectedFarm(farm: Factory): void {
|
|
27
|
+
throw new Error("Method not implemented.");
|
|
28
|
+
}
|
|
29
|
+
setSelectedUnit(unit: Unit): void {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
window.miniapp.selectUnit?.(unit).then((res) => {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
window._notifyUnitChanged?.(unit);
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
ready(): Promise<boolean> {
|
|
38
|
+
return Promise.resolve(true);
|
|
39
|
+
}
|
|
40
|
+
getAxiosFromMiniApp(): MyAxiosInstance {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
return window.getAxiosFromMiniApp();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getSelectedFarmFromMiniApp(): Promise<any> {
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
return window.getSelectedFarmFromMiniApp?.();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
getSelectedUnitFromMiniApp(): Promise<any> {
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
return window.getSelectedUnitFromMiniApp?.();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
jumpToMiniApp(url: string): Promise<void> {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
return window.miniapp?.open(url);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
scanQrcode(): Promise<string> {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
return window.miniapp?.scanQrcode();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setTitle(title: string): void {
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
window.miniapp?.setTitle(title);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
saveBase64(base64: string, filename: string): Promise<void> {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
return window.miniapp?.saveBase64(base64, filename);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
saveBlob(blob: Blob, filename: string): Promise<void> {
|
|
76
|
+
const reader = new FileReader();
|
|
77
|
+
return new Promise<void>((resolve, reject) => {
|
|
78
|
+
reader.readAsDataURL(blob);
|
|
79
|
+
reader.onloadend = async () => {
|
|
80
|
+
const base64 = reader.result as string;
|
|
81
|
+
await this.saveBase64(base64, filename);
|
|
82
|
+
resolve();
|
|
83
|
+
};
|
|
84
|
+
reader.onerror = (err) => {
|
|
85
|
+
reject(err);
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
vibrate(time?: number): void {
|
|
91
|
+
// @ts-ignore
|
|
92
|
+
window.miniapp?.vibrate(time);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
showInDeviceManager(deviceId: any, type: string): Promise<void> {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
return window.miniapp?.showInDeviceManager(deviceId, type);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
reloadGroup(key: string): void {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
window.miniapp?.reloadGroup(key);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getGeo(): Promise<{ lat: number; lng: number }> {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
return window.miniapp?.getGeo();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
setResult(name: string, value: any): void {
|
|
111
|
+
// @ts-ignore
|
|
112
|
+
window.miniapp?.setResult(name, value);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setResultAs(name: string, value: any, type: string): void {
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
window.miniapp?.setResultAs(name, value, type);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setError(message: string): void {
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
window.miniapp?.setError(message);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
setProgress(precentage: number): void {
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
window.miniapp?.setProgress(precentage);
|
|
128
|
+
}
|
|
129
|
+
}
|