@cutos/core 3.3.1 → 3.4.0
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 +80 -55
- package/dist/cutos.cjs.js +2 -2
- package/dist/cutos.esm.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ CoreAPI.getVersion();
|
|
|
112
112
|
- Return result example:
|
|
113
113
|
|
|
114
114
|
```
|
|
115
|
-
"3.
|
|
115
|
+
"3.4.0"
|
|
116
116
|
```
|
|
117
117
|
|
|
118
118
|
### CoreAPI.getPlatform
|
|
@@ -388,6 +388,18 @@ CoreAPI.shell('pwd', (result, error) => {
|
|
|
388
388
|
|
|
389
389
|
# IPC API
|
|
390
390
|
|
|
391
|
+
### Installation
|
|
392
|
+
|
|
393
|
+
`
|
|
394
|
+
npm install @cutos/core
|
|
395
|
+
`
|
|
396
|
+
|
|
397
|
+
### Introduce dependencies
|
|
398
|
+
|
|
399
|
+
```js
|
|
400
|
+
import {CoreAPI} from '@cutos/core';
|
|
401
|
+
```
|
|
402
|
+
|
|
391
403
|
### CoreAPI.getIPC
|
|
392
404
|
|
|
393
405
|
Get IPC instance object
|
|
@@ -396,7 +408,7 @@ Get IPC instance object
|
|
|
396
408
|
let ipc = CoreAPI.getIPC([destAddress]);
|
|
397
409
|
```
|
|
398
410
|
|
|
399
|
-
* destAddress:
|
|
411
|
+
* destAddress: Optional parameter, target IP address, used for inter-device process communication
|
|
400
412
|
|
|
401
413
|

|
|
402
414
|
|
|
@@ -409,93 +421,107 @@ ipc.sendTo(channel, args, callback = null);
|
|
|
409
421
|
```
|
|
410
422
|
|
|
411
423
|
* channel: channel name
|
|
412
|
-
* args: information to
|
|
413
|
-
* callback: function
|
|
424
|
+
* args: information to be sent
|
|
425
|
+
* callback: callback function
|
|
414
426
|
|
|
415
427
|
### ipc.on
|
|
416
428
|
|
|
417
|
-
|
|
429
|
+
Monitor IPC
|
|
418
430
|
|
|
419
431
|
```js
|
|
420
432
|
ipc.on(channel, listener);
|
|
421
433
|
```
|
|
422
434
|
|
|
423
435
|
* channel: channel name
|
|
424
|
-
* listener: function
|
|
425
|
-
|
|
436
|
+
* listener: listener function (args, respond)
|
|
426
437
|
|
|
427
438
|
##### Local device communication example:
|
|
428
439
|
|
|
440
|
+
##### Example 1 (without return value):
|
|
441
|
+
|
|
429
442
|
```js
|
|
430
443
|
import {CoreAPI} from '@cutos/core';
|
|
431
444
|
|
|
432
445
|
CoreAPI.init();
|
|
433
446
|
|
|
434
|
-
let
|
|
435
|
-
// listen
|
|
436
|
-
ipc.on("channel-1", function (args, respond) {
|
|
437
|
-
console.log(args);
|
|
438
|
-
respond('received')
|
|
439
|
-
});
|
|
447
|
+
let channel1 = 'channel1';
|
|
440
448
|
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
449
|
+
let ipc = CoreAPI.getIPC();
|
|
450
|
+
//Listen for IPC information
|
|
451
|
+
ipc.on(channel1, (args) => {
|
|
452
|
+
console.log('on', channel1, 'received', args);
|
|
453
|
+
})
|
|
454
|
+
//Send IPC information
|
|
455
|
+
ipc.sendTo(channel1, 'no callback');
|
|
445
456
|
```
|
|
446
457
|
|
|
447
458
|
- Return result example:
|
|
448
459
|
|
|
449
|
-
```
|
|
450
|
-
|
|
451
|
-
"event": "event-1",
|
|
452
|
-
"msg": "msg-1"
|
|
453
|
-
}
|
|
460
|
+
```
|
|
461
|
+
on channel1 received: "no callback"
|
|
454
462
|
```
|
|
455
463
|
|
|
456
|
-
##### Example
|
|
464
|
+
##### Example 2 (with return value):
|
|
457
465
|
|
|
458
|
-
##### Sender
|
|
459
|
-
IP:192.168.1.136
|
|
460
466
|
```js
|
|
461
467
|
import {CoreAPI} from '@cutos/core';
|
|
462
468
|
|
|
463
469
|
CoreAPI.init();
|
|
464
|
-
|
|
465
|
-
let ipc = CoreAPI.getIPC(
|
|
466
|
-
//
|
|
467
|
-
ipc.
|
|
468
|
-
console.log(
|
|
470
|
+
let channel2 = 'channel2';
|
|
471
|
+
let ipc = CoreAPI.getIPC();
|
|
472
|
+
//Monitor IPC information
|
|
473
|
+
ipc.on(channel2, (args, respond) => {
|
|
474
|
+
console.log('on ' + channel2 + ' received: ' + JSON.stringify(args));
|
|
475
|
+
respond({sum: args.opt1 + args.opt2})
|
|
476
|
+
})
|
|
477
|
+
//Sending IPC information
|
|
478
|
+
ipc.sendTo(channel2, {opt1: 2, opt2: 2}, (result) => {
|
|
479
|
+
console.log('on ' + channel2 + ' callback: ' + JSON.stringify(result))
|
|
469
480
|
});
|
|
470
481
|
```
|
|
471
482
|
- Return result example:
|
|
472
483
|
|
|
473
|
-
```json
|
|
474
|
-
"Received"
|
|
475
484
|
```
|
|
485
|
+
on channel2 received: {"opt1":2,"opt2":2}
|
|
486
|
+
on channel2 callback: {"sum":4}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
##### Example of inter-device process communication:
|
|
490
|
+
|
|
491
|
+
##### Sender (IP: 192.168.1.136)
|
|
476
492
|
|
|
477
|
-
##### Receiver
|
|
478
|
-
IP:192.168.1.149
|
|
479
493
|
```js
|
|
480
494
|
import {CoreAPI} from '@cutos/core';
|
|
481
495
|
|
|
482
496
|
CoreAPI.init();
|
|
497
|
+
let channel1 = 'channel1';
|
|
498
|
+
//Destination IP: 192.168.1.149
|
|
499
|
+
let ipc = CoreAPI.getIPC("192.168.1.149");
|
|
500
|
+
//Send IPC information
|
|
501
|
+
ipc.sendTo(channel1, 'no callback');
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
##### Receiver (IP: 192.168.1.149)
|
|
505
|
+
|
|
506
|
+
```js
|
|
507
|
+
import {CoreAPI} from '@cutos/core';
|
|
483
508
|
|
|
509
|
+
CoreAPI.init();
|
|
510
|
+
let channel1 = 'channel1';
|
|
484
511
|
let ipc = CoreAPI.getIPC();
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
512
|
+
//Listen for IPC information
|
|
513
|
+
let ipcListener = function (args) {
|
|
514
|
+
console.log('on', channel1, 'received', args);
|
|
515
|
+
}
|
|
516
|
+
ipc.on(channel1, ipcListener);
|
|
489
517
|
```
|
|
490
518
|
|
|
491
519
|
- Return result example:
|
|
492
520
|
|
|
493
|
-
```json
|
|
494
|
-
{
|
|
495
|
-
"event": "event-2",
|
|
496
|
-
"msg": "msg-2"
|
|
497
|
-
}
|
|
498
521
|
```
|
|
522
|
+
on channel1 received: "no callback"
|
|
523
|
+
```
|
|
524
|
+
|
|
499
525
|
|
|
500
526
|
|
|
501
527
|
# Database API
|
|
@@ -1297,20 +1323,19 @@ import {CoreAPI} from '@cutos/core';
|
|
|
1297
1323
|
import {DriverTemplate} from '../src/driver-template.js';
|
|
1298
1324
|
|
|
1299
1325
|
CoreAPI.init(null, () => {
|
|
1300
|
-
|
|
1301
|
-
let device = new DriverTemplate('driver-template', ({result, msg}) => {
|
|
1326
|
+
let device = new DriverTemplate('driver-template')
|
|
1302
1327
|
console.log("driver template init", result, msg ? " error:" + msg : "");
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1328
|
+
device.init((result, error) => {
|
|
1329
|
+
device.onData((data) => {
|
|
1330
|
+
console.log("on data", data)
|
|
1331
|
+
});
|
|
1332
|
+
|
|
1333
|
+
device.connect((result) => {
|
|
1334
|
+
console.log("connect: ", result)
|
|
1335
|
+
});
|
|
1336
|
+
device.customCmd();
|
|
1337
|
+
device.sendCommand({cmd: "unknown", args: ""});
|
|
1310
1338
|
});
|
|
1311
|
-
device.customCmd();
|
|
1312
|
-
device.sendCommand({cmd: "unknown", args: ""});
|
|
1313
|
-
});
|
|
1314
1339
|
});
|
|
1315
1340
|
```
|
|
1316
1341
|
|
package/dist/cutos.cjs.js
CHANGED
|
@@ -385,7 +385,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
385
385
|
NFC: 'device-nfc',
|
|
386
386
|
FINGERPRINT: 'device-fingerprint',
|
|
387
387
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
388
|
-
PRINTER: 'device-printer'
|
|
388
|
+
PRINTER: 'device-printer',
|
|
389
389
|
});
|
|
390
390
|
|
|
391
391
|
const HEARTBEAT_STATUS = Object.freeze({
|
|
@@ -398,7 +398,7 @@ const cutosAPI$2 = {
|
|
|
398
398
|
var cutosApi = cutosAPI$2;
|
|
399
399
|
|
|
400
400
|
var name = "@cutos/core";
|
|
401
|
-
var version = "3.
|
|
401
|
+
var version = "3.4.0";
|
|
402
402
|
var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
|
|
403
403
|
var main = "dist/cutos.cjs.js";
|
|
404
404
|
var module$1 = "dist/cutos.esm.js";
|
package/dist/cutos.esm.js
CHANGED
|
@@ -677,7 +677,7 @@ const DEVICE = Object.freeze({ // core level api
|
|
|
677
677
|
NFC: 'device-nfc',
|
|
678
678
|
FINGERPRINT: 'device-fingerprint',
|
|
679
679
|
QR_CODE_SCANNER: 'device-qr-code-scanner',
|
|
680
|
-
PRINTER: 'device-printer'
|
|
680
|
+
PRINTER: 'device-printer',
|
|
681
681
|
});
|
|
682
682
|
|
|
683
683
|
const HEARTBEAT_STATUS = Object.freeze({
|
|
@@ -690,7 +690,7 @@ const cutosAPI$2 = {
|
|
|
690
690
|
var cutosApi = cutosAPI$2;
|
|
691
691
|
|
|
692
692
|
var name = "@cutos/core";
|
|
693
|
-
var version = "3.
|
|
693
|
+
var version = "3.4.0";
|
|
694
694
|
var description = "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ";
|
|
695
695
|
var main = "dist/cutos.cjs.js";
|
|
696
696
|
var module = "dist/cutos.esm.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cutos/core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "The CUTOS (CUT Operating System) Core API is a JavaScript library that provides essential functionalities for LWA (Local Web Application) edge computing and communication in the CUTOS ecosystem. ",
|
|
5
5
|
"main": "dist/cutos.cjs.js",
|
|
6
6
|
"module": "dist/cutos.esm.js",
|