@cpzxrobot/sdk 1.2.92 → 1.2.94

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 CHANGED
@@ -205,7 +205,7 @@ export class DeviceGateway extends Object {
205
205
  //获取设备详情
206
206
  //ID:点位ID,设备UUID,当type是device时,为设备ID(UUID);当type是datapoint时,为点位ID(number)
207
207
  show(id: any, type: "device"|"datapoint" = "datapoint"){
208
- this.context.showInDeviceManager(id,type);
208
+ this.context.platform.showInDeviceManager(id,type);
209
209
  }
210
210
 
211
211
  async watch(
@@ -157,7 +157,7 @@ class DeviceGateway extends Object {
157
157
  //获取设备详情
158
158
  //ID:点位ID,设备UUID,当type是device时,为设备ID(UUID);当type是datapoint时,为点位ID(number)
159
159
  show(id, type = "datapoint") {
160
- this.context.showInDeviceManager(id, type);
160
+ this.context.platform.showInDeviceManager(id, type);
161
161
  }
162
162
  async watch(id, fn) {
163
163
  var axios = await this.context.ready;
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Cpzxrobot = void 0;
27
27
  exports.default = default_1;
28
28
  const device_gateway_1 = require("./device_gateway");
29
+ const windows_platform_1 = require("./windows_platform");
29
30
  const user_gateway_1 = require("./user_gateway");
30
31
  const factory_gateway_1 = require("./factory_gateway");
31
32
  const transport_gateway_1 = require("./transport_gateway");
@@ -48,8 +49,10 @@ const quotation_gateway_1 = require("./quotation_gateway");
48
49
  const ai_gateway_1 = require("./ai_gateway");
49
50
  const construction_gateway_1 = require("./construction_gateway");
50
51
  const system_gateway_1 = require("./system_gateway");
52
+ const mobile_platform_1 = require("./mobile_platform");
53
+ const web_platform_1 = require("./web_platform");
51
54
  class Cpzxrobot {
52
- constructor(appCode) {
55
+ constructor(appCode, baseUrl, initSelectedFactory, initSelectedUnit) {
53
56
  this.pigfarm = new pigfarm_gateway_1.PigfarmGateway(this);
54
57
  this.chickenfarm = new chickenfarm_gateway_1.ChickenFarmGateway(this);
55
58
  this.hash = "shzx";
@@ -75,7 +78,7 @@ class Cpzxrobot {
75
78
  this.resolveReady = resolve;
76
79
  this.rejectReady = reject;
77
80
  });
78
- this.getDomain();
81
+ this.getDomain(baseUrl, initSelectedFactory, initSelectedUnit);
79
82
  this.appCode = appCode;
80
83
  this.user = new user_gateway_1.UserGateway(this);
81
84
  this.factory = new factory_gateway_1.FactoryGateway(this);
@@ -100,362 +103,25 @@ class Cpzxrobot {
100
103
  }
101
104
  initAxios(baseURL) {
102
105
  if (this.mode !== "miniapp_in_app") {
103
- const fetchWithAuth = async (input, init) => {
104
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
105
- headers.set('Authorization', this.token);
106
- headers.set('Miniapp-Code', this.appCode);
107
- const response = await fetch(baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
108
- if (!response.ok) {
109
- throw new Error(`HTTP error! status: ${response.status}`);
110
- }
111
- return response;
112
- };
113
- const streamWithAuth = async (input, init, fn) => {
114
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
115
- headers.set('Authorization', this.token);
116
- headers.set('Miniapp-Code', this.appCode);
117
- const response = await fetch(baseURL + input.toString(), Object.assign(Object.assign({}, init), { headers }));
118
- var reader = response.body.getReader();
119
- const decoder = new TextDecoder("utf-8");
120
- let done = false;
121
- var buf = "";
122
- while (!done) {
123
- const { value, done } = await reader.read();
124
- if (done) {
125
- break;
126
- }
127
- const chunkValue = decoder.decode(value);
128
- //split value to lines
129
- // 将值拆分为行
130
- buf = buf + chunkValue;
131
- var i = buf.indexOf("\n");
132
- while (i > -1) {
133
- //find first \n
134
- var line = buf.substring(0, i);
135
- try {
136
- if (line === "[DONE]") {
137
- break;
138
- }
139
- else {
140
- // remove prefix 'data: '
141
- // 移除前缀 'data: '
142
- var data = JSON.parse(line.split(": ")[1]);
143
- //{"choices":[{"delta":{"content":" </"},"index":0}],"created":1741749068,"id":"chatcmpl-67ccb889154043f5874cbf3a64ec163e","model":"DeepSeek-R1","object":"chat.completion.chunk"}
144
- fn === null || fn === void 0 ? void 0 : fn.call(data);
145
- }
146
- }
147
- catch (e) {
148
- console.error("解析失败", e);
149
- }
150
- buf = buf.substring(i + 1);
151
- i = buf.indexOf("\n");
152
- }
153
- }
154
- ;
155
- return true;
156
- };
157
- const processQueryParams = (url, config) => {
158
- if (config && config.params) {
159
- const flattenParams = (params, prefix = '') => {
160
- const result = {};
161
- Object.keys(params).forEach(key => {
162
- const value = params[key];
163
- const fullKey = prefix ? `${prefix}[${key}]` : key;
164
- if (value && typeof value === 'object' && !Array.isArray(value)) {
165
- Object.assign(result, flattenParams(value, fullKey));
166
- }
167
- else if (value) {
168
- result[fullKey] = value.toString();
169
- }
170
- });
171
- return result;
172
- };
173
- const flattened = flattenParams(config.params);
174
- url += "?" + new URLSearchParams(flattened).toString();
175
- delete config.params;
176
- }
177
- return url;
178
- };
179
- const instance = {
180
- get: async (url, config) => {
181
- url = processQueryParams(url, config);
182
- const response = await fetchWithAuth(url, {
183
- method: 'GET',
184
- headers: config === null || config === void 0 ? void 0 : config.headers
185
- });
186
- return { data: await response.json() };
187
- },
188
- post: async (url, data, config) => {
189
- const response = await fetchWithAuth(url, {
190
- method: 'POST',
191
- headers: Object.assign({ 'Content-Type': 'application/json' }, config === null || config === void 0 ? void 0 : config.headers),
192
- body: JSON.stringify(data)
193
- });
194
- return { data: await response.json() };
195
- },
196
- getAndSave: async (url, config) => {
197
- var _a;
198
- url = processQueryParams(url, config);
199
- const response = await fetchWithAuth(url, {
200
- method: 'GET',
201
- headers: config === null || config === void 0 ? void 0 : config.headers
202
- });
203
- const blob = await response.blob();
204
- // 文件名解析逻辑
205
- const contentDisposition = response.headers.get('Content-Disposition');
206
- let filename = (_a = config === null || config === void 0 ? void 0 : config.fileName) !== null && _a !== void 0 ? _a : ""; // 默认文件名
207
- // 1. 优先使用响应头中的文件名
208
- if (filename == "") {
209
- if (contentDisposition) {
210
- const utf8FilenameMatch = contentDisposition.match(/filename\*=UTF-8''(.+)/i);
211
- if (utf8FilenameMatch) {
212
- filename = decodeURIComponent(utf8FilenameMatch[1]);
213
- }
214
- else {
215
- const filenameMatch = contentDisposition.match(/filename="?(.+?)"?(;|$)/i);
216
- if (filenameMatch)
217
- filename = filenameMatch[1];
218
- }
219
- }
220
- else {
221
- filename = "file";
222
- }
223
- }
224
- await this.saveBlob(blob, filename);
225
- return { data: blob };
226
- },
227
- getAndPreview: async (url, config) => {
228
- url = processQueryParams(url, config);
229
- return instance.getAndSave(url, config);
230
- },
231
- upload: async (url, option) => {
232
- return new Promise((resolve, reject) => {
233
- const button = document.createElement("input");
234
- button.type = "file";
235
- button.style.display = "none";
236
- button.multiple = (option === null || option === void 0 ? void 0 : option.multiple) || false;
237
- document.body.appendChild(button);
238
- button.click(); // 手动触发点击
239
- button.onchange = async (e) => {
240
- const files = e.target.files;
241
- if (files && files.length > 0) {
242
- const formData = new FormData();
243
- if (option === null || option === void 0 ? void 0 : option.multiple) {
244
- for (let i = 0; i < files.length; i++) {
245
- formData.append("files[]", files[i]);
246
- }
247
- }
248
- else {
249
- formData.append((option === null || option === void 0 ? void 0 : option["fileField"]) || "file", files[0]);
250
- }
251
- for (let key in option === null || option === void 0 ? void 0 : option["data"]) {
252
- formData.append(key, option["data"][key]);
253
- }
254
- const response = await fetchWithAuth(url, {
255
- method: 'POST',
256
- body: formData
257
- });
258
- button.remove();
259
- resolve({ data: await response.json() });
260
- }
261
- else {
262
- button.remove();
263
- resolve({ data: { Error: "没有选择文件" } });
264
- }
265
- };
266
- });
267
- },
268
- getAsSse: (url, fn, config) => {
269
- return new Promise((resolve, reject) => {
270
- streamWithAuth(url, {
271
- method: 'GET',
272
- }, fn);
273
- });
274
- }
275
- };
276
106
  // @ts-ignore
277
107
  this.axios = instance;
278
108
  }
279
109
  }
280
110
  _saveBlobAsBase64(blob, filename) {
281
- var that = this;
282
- return new Promise((resolve, reject) => {
283
- const reader = new FileReader();
284
- reader.readAsDataURL(blob);
285
- reader.onloadend = async () => {
286
- // @ts-ignoreconst reader = new FileReader();
287
- const base64 = reader.result;
288
- // @ts-ignore
289
- await that.saveBase64(base64, filename);
290
- resolve();
291
- };
292
- reader.onerror = (err) => {
293
- reject(err);
294
- };
295
- });
111
+ return this.platform.saveBlob(blob, filename);
296
112
  }
297
113
  //获取当前浏览器的域名
298
- getDomain() {
114
+ getDomain(baseURL, initSelectedFactory, initSelectedUnit) {
299
115
  const domain = window.location.hostname;
300
116
  console.log("load domain ", domain);
301
117
  if (domain == "miniapp") {
302
118
  this.mode = "miniapp_in_app";
303
- // @ts-ignore
304
- this.axios = getAxiosFromMiniApp();
305
- this.platformReady = Promise.resolve(true);
306
- // @ts-ignore
307
- this._getSelectedFarmFromMiniApp = window.getSelectedFarmFromMiniApp;
308
- // @ts-ignore
309
- this._getSelectedUnitFromMiniApp = window.getSelectedUnitFromMiniApp;
310
- // @ts-ignore
311
- this._jumpToMiniApp = window.miniapp.open;
312
- // @ts-ignore
313
- this.scanQrcode = window.miniapp.scanQrcode;
314
- // @ts-ignore
315
- this.setTitle = window.miniapp.setTitle;
316
- // @ts-ignore
317
- this.saveBase64 = window.miniapp.saveBase64;
318
- // @ts-ignore
319
- this.vibrate = window.miniapp.vibrate;
320
- // @ts-ignore
321
- this.reloadGroup = window.miniapp.reloadGroup;
322
- this.saveBlob = this._saveBlobAsBase64;
323
- // @ts-ignore
324
- this.getGeo = window.miniapp.getGeo;
325
- // @ts-ignore
326
- this.setResult = window.miniapp.setResult;
327
- // @ts-ignore
328
- this.setResultAs = window.miniapp.setResultAs;
329
- // @ts-ignore
330
- this.setError = window.miniapp.setError;
331
- // @ts-ignore
332
- this.setProgress = window.miniapp.setProgress;
333
- // @ts-ignore
334
- this.showInDeviceManager = window.miniapp.showInDeviceManager;
119
+ this.platform = new windows_platform_1.WindwosMiniAppPlatform();
335
120
  }
336
121
  else if (domain == "appassets.androidplatform.net" || domain == "webc.cpzxrobot.com" ||
337
122
  this.isIosMiniApp(window.location)) {
338
123
  this.mode = "miniapp_in_app";
339
- const platform =
340
- // @ts-ignore
341
- window.flutter_inappwebview;
342
- var that = this;
343
- this._getSelectedFarmFromMiniApp = function () {
344
- return platform.callHandler("getSelectedFarmFromMiniApp");
345
- };
346
- this._getSelectedUnitFromMiniApp = function () {
347
- return platform.callHandler("getSelectedUnitFromMiniApp");
348
- };
349
- this._jumpToMiniApp = function (url) {
350
- return platform.callHandler("app.openMiniapp", url);
351
- };
352
- this.scanQrcode = function () {
353
- return platform.callHandler("app.scanQrcode");
354
- };
355
- this.getGeo = async function () {
356
- var result = await platform.callHandler("app.getGeo");
357
- if (result.error) {
358
- throw result.error;
359
- }
360
- return {
361
- lat: result.lat,
362
- lng: result.lng
363
- };
364
- };
365
- this.setTitle = function (title) {
366
- platform.callHandler("app.setTitle", title);
367
- };
368
- this.saveBlob = this._saveBlobAsBase64;
369
- this.saveBase64 = function (base64, filename) {
370
- return platform.callHandler("app.saveBase64", base64, filename);
371
- };
372
- this.vibrate = function (time) {
373
- return platform.callHandler("app.vibrate", time);
374
- };
375
- this.showInDeviceManager = function (deviceId, type) {
376
- return platform.callHandler("app.showInDeviceManager", deviceId, type);
377
- };
378
- this.reloadGroup = function (group) {
379
- return platform.callHandler("app.reloadGroup", group);
380
- };
381
- this.setResult = function (name, value) {
382
- return platform.callHandler("app.setResult", name, value);
383
- };
384
- this.setResultAs = function (name, value, type) {
385
- return platform.callHandler("app.setResultAs", name, value, type);
386
- };
387
- this.setError = function (message) {
388
- return platform.callHandler("app.setError", message);
389
- };
390
- this.setProgress = function (precentage) {
391
- return platform.callHandler("app.setProgress", precentage);
392
- };
393
- this.axios = {
394
- get: function (url, data) {
395
- return platform.callHandler("axios_get", url, data);
396
- },
397
- post: function (url, data) {
398
- return platform.callHandler("axios_post", url, data);
399
- },
400
- getAndSave: function (url, config) {
401
- return platform.callHandler("axios_getAndSave", url, config);
402
- },
403
- getAndPreview: function (url, config) {
404
- if (config == undefined) {
405
- config = {};
406
- }
407
- if (config.preview == undefined) {
408
- config.preview = true;
409
- }
410
- return platform.callHandler("axios_getAndSave", url, config);
411
- },
412
- upload: function (url, option) {
413
- return platform.callHandler("axios_upload", url, option);
414
- },
415
- getAsSse: async function (url, fn, config) {
416
- var randomId = Math.random().toString(36).substring(2);
417
- that.sseCallbacks[randomId] = fn;
418
- console.log("getAsSse", url, fn, randomId);
419
- await platform.callHandler("axios_getAsSse", url, config, randomId);
420
- delete that.sseCallbacks[randomId];
421
- },
422
- };
423
- if (
424
- // @ts-ignore
425
- window.flutter_inappwebview != null &&
426
- // @ts-ignore
427
- window.flutter_inappwebview.callHandler != null) {
428
- this.platformReady = Promise.resolve(true);
429
- }
430
- else {
431
- this.platformReady = new Promise((resolve, reject) => {
432
- window.addEventListener("flutterInAppWebViewPlatformReady", function () {
433
- console.log("flutter android/ios platform is ready");
434
- resolve(true);
435
- });
436
- setTimeout(() => {
437
- console.log("flutter android/ios platform is timeout");
438
- reject("timeout");
439
- }, 1500);
440
- });
441
- }
442
- window.addEventListener('message', (event) => {
443
- if (event.data == 'capturePort') {
444
- console.log("capturePort", event);
445
- if (event.ports[0] != null) {
446
- this.messagePort = event.ports[0];
447
- this.messagePort.onmessage = (event) => {
448
- if (event.data.id != undefined) {
449
- var callback = this.sseCallbacks[event.data.id];
450
- callback(event.data.data);
451
- }
452
- };
453
- }
454
- }
455
- else {
456
- console.log("message", event);
457
- }
458
- }, false);
124
+ this.platform = new mobile_platform_1.MobilePlatform();
459
125
  }
460
126
  else {
461
127
  if (this.isLocalDomain(domain)) {
@@ -465,67 +131,10 @@ class Cpzxrobot {
465
131
  else {
466
132
  this.mode = "miniapp_in_web";
467
133
  }
468
- this.setTitle = function (title) {
469
- document.title = title;
470
- };
471
- this.saveBase64 = function (base64, filename) {
472
- //decode base64 to blob
473
- const byteCharacters = atob(base64);
474
- const byteNumbers = new Array(byteCharacters.length);
475
- for (let i = 0; i < byteCharacters.length; i++) {
476
- byteNumbers[i] = byteCharacters.charCodeAt(i);
477
- }
478
- const byteArray = new Uint8Array(byteNumbers);
479
- const blob = new Blob([byteArray], {
480
- type: "application/octet-stream",
481
- });
482
- return this.saveBlob(blob, filename);
483
- };
484
- this.saveBlob = function (blob, filename) {
485
- return new Promise((resolve, reject) => {
486
- try {
487
- const url = URL.createObjectURL(blob);
488
- const a = document.createElement("a");
489
- a.href = url;
490
- a.download = filename;
491
- document.body.appendChild(a);
492
- a.click();
493
- setTimeout(() => {
494
- URL.revokeObjectURL(url);
495
- document.body.removeChild(a);
496
- resolve();
497
- }, 0);
498
- }
499
- catch (error) {
500
- reject(error);
501
- }
502
- });
503
- };
504
- this.getGeo = async function () {
505
- return new Promise((resolve, reject) => {
506
- if (navigator.geolocation) {
507
- navigator.geolocation.getCurrentPosition((position) => {
508
- const lat = position.coords.latitude; // 获取纬度
509
- const lng = position.coords.longitude; // 获取经度
510
- // 完成位置获取,解析 Promise
511
- resolve({ lat, lng });
512
- }, (error) => {
513
- console.log("获取位置信息失败:" + error.message);
514
- // 位置获取失败,拒绝 Promise
515
- reject(error);
516
- });
517
- }
518
- else {
519
- console.log("浏览器不支持获取位置信息");
520
- // 浏览器不支持位置服务,拒绝 Promise
521
- reject(new Error("浏览器不支持获取位置信息"));
522
- }
523
- });
524
- };
525
- this.showInDeviceManager = function (deviceId, type) {
526
- return this.axios.get(`/api/v1/${type}/share/` + deviceId);
527
- };
134
+ this.platform = new web_platform_1.WebPlatform(this.token, this.appCode, baseURL, initSelectedFactory, initSelectedUnit);
528
135
  }
136
+ this.platformReady = this.platform.ready();
137
+ this.axios = this.platform.getAxiosFromMiniApp();
529
138
  }
530
139
  isIosMiniApp(location) {
531
140
  //hostname is 'localhost' and has search params starting with 'mode=ios'
@@ -549,7 +158,7 @@ class Cpzxrobot {
549
158
  }
550
159
  //打开其他小程序
551
160
  openMiniApp(url) {
552
- this._jumpToMiniApp(url);
161
+ this.platform.jumpToMiniApp(url);
553
162
  }
554
163
  setAuth(auth, args) {
555
164
  var logger = (msg, level) => {
@@ -726,7 +335,7 @@ function default_1(args = {
726
335
  // @ts-ignore
727
336
  var instance = window.single_cpzxrobot_instance;
728
337
  if (!instance) {
729
- instance = new Cpzxrobot(args.appCode);
338
+ instance = new Cpzxrobot(args.appCode, args.baseURL, args.selectedFarm, args.selectedUnit);
730
339
  // @ts-ignore
731
340
  window.single_cpzxrobot_instance = instance;
732
341
  instance.setAuth(args.devAuth, {
@@ -734,12 +343,6 @@ function default_1(args = {
734
343
  verbose: args.verbose,
735
344
  disableFactorySelector: (_b = args.disableFactorySelector) !== null && _b !== void 0 ? _b : false,
736
345
  });
737
- if (args.selectedFarm) {
738
- instance.user.selectedFarm = args.selectedFarm;
739
- }
740
- if (args.selectedUnit) {
741
- instance.user.selectedUnit = args.selectedUnit;
742
- }
743
346
  }
744
347
  return instance;
745
348
  }
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MobilePlatform = void 0;
4
+ class MobilePlatform {
5
+ constructor() {
6
+ this.sseCallbacks = {};
7
+ this.token = "";
8
+ this.appCode = "";
9
+ this.baseURL = "";
10
+ // @ts-ignore
11
+ this.platform = window.flutter_inappwebview;
12
+ window.addEventListener('message', (event) => {
13
+ if (event.data == 'capturePort') {
14
+ const port = event.ports[0];
15
+ if (port != null) {
16
+ port.onmessage = (event) => {
17
+ if (event.data.id != undefined) {
18
+ const callback = this.sseCallbacks[event.data.id];
19
+ callback === null || callback === void 0 ? void 0 : callback(event.data.data);
20
+ }
21
+ };
22
+ }
23
+ }
24
+ }, false);
25
+ }
26
+ setSelectedFarm(farm) {
27
+ throw new Error("Method not implemented.");
28
+ }
29
+ setSelectedUnit(unit) {
30
+ this.platform.callHandler("selectUnit", unit).then((_res) => {
31
+ var _a;
32
+ // @ts-ignore
33
+ (_a = window._notifyUnitChanged) === null || _a === void 0 ? void 0 : _a.call(window, unit);
34
+ });
35
+ }
36
+ ready() {
37
+ if (
38
+ // @ts-ignore
39
+ window.flutter_inappwebview != null &&
40
+ // @ts-ignore
41
+ window.flutter_inappwebview.callHandler != null) {
42
+ return Promise.resolve(true);
43
+ }
44
+ else {
45
+ return new Promise((resolve, reject) => {
46
+ window.addEventListener("flutterInAppWebViewPlatformReady", function () {
47
+ console.log("flutter android/ios platform is ready");
48
+ resolve(true);
49
+ });
50
+ setTimeout(() => {
51
+ console.log("flutter android/ios platform is timeout");
52
+ reject("timeout");
53
+ }, 1500);
54
+ });
55
+ }
56
+ }
57
+ getAxiosFromMiniApp() {
58
+ const that = this;
59
+ return {
60
+ get: function (url, data) {
61
+ return that.platform.callHandler("axios_get", url, data);
62
+ },
63
+ post: function (url, data) {
64
+ return that.platform.callHandler("axios_post", url, data);
65
+ },
66
+ getAndSave: function (url, config) {
67
+ return that.platform.callHandler("axios_getAndSave", url, config);
68
+ },
69
+ getAndPreview: function (url, config) {
70
+ if (config == undefined) {
71
+ config = {};
72
+ }
73
+ if (config.preview == undefined) {
74
+ config.preview = true;
75
+ }
76
+ return that.platform.callHandler("axios_getAndSave", url, config);
77
+ },
78
+ upload: function (url, option) {
79
+ return that.platform.callHandler("axios_upload", url, option);
80
+ },
81
+ getAsSse: async function (url, fn, config) {
82
+ var randomId = Math.random().toString(36).substring(2);
83
+ that.sseCallbacks[randomId] = fn;
84
+ console.log("getAsSse", url, fn, randomId);
85
+ await that.platform.callHandler("axios_getAsSse", url, config, randomId);
86
+ delete that.sseCallbacks[randomId];
87
+ },
88
+ };
89
+ }
90
+ async getSelectedFarmFromMiniApp() {
91
+ return this.platform.callHandler("getSelectedFarmFromMiniApp");
92
+ }
93
+ async getSelectedUnitFromMiniApp() {
94
+ return this.platform.callHandler("getSelectedUnitFromMiniApp");
95
+ }
96
+ async jumpToMiniApp(url) {
97
+ return this.platform.callHandler("app.openMiniapp", url);
98
+ }
99
+ async scanQrcode() {
100
+ return this.platform.callHandler("app.scanQrcode");
101
+ }
102
+ setTitle(title) {
103
+ this.platform.callHandler("app.setTitle", title);
104
+ }
105
+ async saveBase64(base64, filename) {
106
+ return this.platform.callHandler("app.saveBase64", base64, filename);
107
+ }
108
+ async saveBlob(blob, filename) {
109
+ const reader = new FileReader();
110
+ return new Promise((resolve, reject) => {
111
+ reader.readAsDataURL(blob);
112
+ reader.onloadend = async () => {
113
+ const base64 = reader.result;
114
+ await this.saveBase64(base64, filename);
115
+ resolve();
116
+ };
117
+ reader.onerror = (err) => {
118
+ reject(err);
119
+ };
120
+ });
121
+ }
122
+ vibrate(time) {
123
+ this.platform.callHandler("app.vibrate", time);
124
+ }
125
+ async showInDeviceManager(deviceId, type) {
126
+ return this.platform.callHandler("app.showInDeviceManager", deviceId, type);
127
+ }
128
+ reloadGroup(group) {
129
+ this.platform.callHandler("app.reloadGroup", group);
130
+ }
131
+ async getGeo() {
132
+ const result = await this.platform.callHandler("app.getGeo");
133
+ if (result.error) {
134
+ throw result.error;
135
+ }
136
+ return {
137
+ lat: result.lat,
138
+ lng: result.lng
139
+ };
140
+ }
141
+ setResult(name, value) {
142
+ this.platform.callHandler("app.setResult", name, value);
143
+ }
144
+ setResultAs(name, value, type) {
145
+ this.platform.callHandler("app.setResultAs", name, value, type);
146
+ }
147
+ setError(message) {
148
+ this.platform.callHandler("app.setError", message);
149
+ }
150
+ setProgress(precentage) {
151
+ this.platform.callHandler("app.setProgress", precentage);
152
+ }
153
+ }
154
+ exports.MobilePlatform = MobilePlatform;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlatformInterface = void 0;
4
+ class PlatformInterface {
5
+ //define constructor(token: string, appCode: string) {
6
+ constructor(token, appCode, baseURL) {
7
+ this.token = token;
8
+ this.appCode = appCode;
9
+ this.baseURL = baseURL;
10
+ }
11
+ }
12
+ exports.PlatformInterface = PlatformInterface;