@cutos/core 3.3.0 → 3.3.1

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 CHANGED
@@ -410,7 +410,7 @@ ipc.sendTo(channel, args, callback = null);
410
410
 
411
411
  * channel: channel name
412
412
  * args: information to send
413
- * callback: callback function
413
+ * callback: function callback(result)
414
414
 
415
415
  ### ipc.on
416
416
 
@@ -421,19 +421,8 @@ ipc.on(channel, listener);
421
421
  ```
422
422
 
423
423
  * channel: channel name
424
- * listener: listener function (args, context)
424
+ * listener: function listener(args, respond(result)). args is the data from sender, respond is used to send data(result) back to sender's callback
425
425
 
426
- ### ipc.sendResponse
427
-
428
- The receiver replies to the message
429
-
430
- ```js
431
- ipc.sendResponse(context, result, error = null);
432
- ```
433
-
434
- * context: context information
435
- * result: reply message content
436
- * error: error message
437
426
 
438
427
  ##### Local device communication example:
439
428
 
@@ -443,12 +432,16 @@ import {CoreAPI} from '@cutos/core';
443
432
  CoreAPI.init();
444
433
 
445
434
  let ipc = CoreAPI.getIPC();
446
- //Listen to IPC information
447
- ipc.on("channel-1", function (args, context) {
435
+ // listen
436
+ ipc.on("channel-1", function (args, respond) {
448
437
  console.log(args);
438
+ respond('received')
439
+ });
440
+
441
+ // send
442
+ ipc.sendTo("channel-1", {event: "event-1", msg: "msg-1"}, (result) => {
443
+ console.log(result)
449
444
  });
450
- //Send IPC information
451
- ipc.sendTo("channel-1", {event: "event-1", msg: "msg-1"});
452
445
  ```
453
446
 
454
447
  - Return result example:
@@ -468,13 +461,11 @@ IP:192.168.1.136
468
461
  import {CoreAPI} from '@cutos/core';
469
462
 
470
463
  CoreAPI.init();
471
- //Destination IP:192.168.1.149
464
+ // Destination IP:192.168.1.149
472
465
  let ipc = CoreAPI.getIPC("192.168.1.149");
473
- //Send IPC information
474
- ipc.sendTo("channel-2", {event: "event-2", msg: "msg-2"}, (result, error) => {
475
- if (!error) {
466
+ // Send IPC information
467
+ ipc.sendTo("channel-2", {event: "event-2", msg: "msg-2"}, (result) => {
476
468
  console.log(result)
477
- }
478
469
  });
479
470
  ```
480
471
  - Return result example:
@@ -489,14 +480,12 @@ IP:192.168.1.149
489
480
  import {CoreAPI} from '@cutos/core';
490
481
 
491
482
  CoreAPI.init();
492
- //Target IP:192.168.1.136
493
- let ipc = CoreAPI.getIPC("192.168.1.136");
494
- //Listen for IPC information
495
- let ipcListener = function (args, context) {
496
- console.log(args);
497
- ipc.sendResponse(context, "Received");
498
- }
499
- ipc.on("channel-2", ipcListener);
483
+
484
+ let ipc = CoreAPI.getIPC();
485
+ ipc.on("channel-2", (args, respond) => {
486
+ console.log(args);
487
+ respond('Received')
488
+ })
500
489
  ```
501
490
 
502
491
  - Return result example:
@@ -973,9 +962,9 @@ Receive device commands
973
962
  driver.onCommand(listener)
974
963
  ```
975
964
 
976
- - listener: listen callback function (command, [callback]), call callback after processing command
965
+ - listener: function listener(command, respond), call respond after processing command
977
966
  - command: command, example: {cmd: "connect", args: ""}
978
- - callback: callback function (result)
967
+ - respond: used to send data back to Device.sendCommand's callback function
979
968
 
980
969
  ## SDK
981
970
 
@@ -1000,7 +989,7 @@ device.init([opts], callback)
1000
989
 
1001
990
  * opts: optional parameters, passed to the driver loading process, refer
1002
991
  to [Driver Template](#download-project-template)
1003
- * callback: callback function
992
+ * callback: function(result, error)
1004
993
 
1005
994
  ##### Example:
1006
995
 
@@ -1023,7 +1012,7 @@ device.sendCommand(command, callback)
1023
1012
  ```
1024
1013
 
1025
1014
  - command: command, example: command = {cmd: "connect", args: ""}
1026
- - callback: callback function, you can pass a listening callback function to listen to the device status
1015
+ - callback: function callback(result), used to receive the response from driver
1027
1016
 
1028
1017
  ##### Example:
1029
1018
 
@@ -1039,8 +1028,7 @@ Receive data sent by the driver
1039
1028
  device.onData(listener)
1040
1029
  ```
1041
1030
 
1042
- - listener: listener callback function (data)
1043
- - data: data
1031
+ - listener: function listener(data)
1044
1032
 
1045
1033
  ## Device driver relationship
1046
1034
 
@@ -1220,37 +1208,37 @@ class DriverTemplate extends CoreClass.Driver {
1220
1208
  this.startBeat();
1221
1209
  this.updateStatusInfo(CoreDefine.HEARTBEAT_STATUS.ALIVE, "alive");
1222
1210
 
1223
- this.onCommand(({cmd, args}, callback) => {
1211
+ this.onCommand(({cmd, args}, respond) => {
1224
1212
  // Listen to the messages sent by the device SDK, process the different commands in the message body,
1225
1213
  // and respond back to the device SDK through the callback function.
1226
1214
  switch (cmd) {
1227
1215
  case CMD.CONNECT:
1228
- this.connect(args, callback);
1216
+ this.connect(args, respond);
1229
1217
  break;
1230
1218
  case CMD.CUSTOM_CMD:
1231
1219
  this.customCmd(cmd, args);
1232
1220
  break;
1233
1221
  default:
1234
- this.unsupported(cmd, args, callback);
1222
+ this.unsupported(cmd, args, respond);
1235
1223
  break;
1236
1224
  }
1237
1225
  });
1238
1226
  }
1239
1227
 
1240
- unsupported(cmd, args, callback) {
1228
+ unsupported(cmd, args, respond) {
1241
1229
  let result = {};
1242
1230
  result.msg = "cmd: " + cmd + " is unsupported.";
1243
1231
  result.status = false;
1244
1232
  console.log(result.msg);
1245
- callback(result);
1233
+ respond(result);
1246
1234
  }
1247
1235
 
1248
- connect(args, callback) {
1236
+ connect(args, respond) {
1249
1237
  console.log("connect: received.");
1250
1238
  let result = {};
1251
1239
  result.msg = "return success.";
1252
1240
  result.status = true;
1253
- callback(result);
1241
+ respond(result);
1254
1242
  }
1255
1243
 
1256
1244
  // no response
package/dist/cutos.cjs.js CHANGED
@@ -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.3.0";
401
+ var version = "3.3.1";
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";
@@ -918,7 +918,7 @@ class IPC {
918
918
  /**
919
919
  * listening channel
920
920
  * @param channel
921
- * @param listener (args, callback(result)) args is the data from sender, callback is used to response sender with the result
921
+ * @param listener (args, respond(result)) args is the data from sender, respond is used to send data back to sender's callback
922
922
  */
923
923
  on(channel, listener) {
924
924
  if (listener) {
@@ -1189,7 +1189,7 @@ class Driver {
1189
1189
 
1190
1190
  /**
1191
1191
  * Receive device commands
1192
- * @param listener(command, callback(result))
1192
+ * @param listener(command, respond(result))
1193
1193
  */
1194
1194
  onCommand(listener) {
1195
1195
  if (listener) {
package/dist/cutos.esm.js CHANGED
@@ -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.3.0";
693
+ var version = "3.3.1";
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";
@@ -1210,7 +1210,7 @@ class IPC {
1210
1210
  /**
1211
1211
  * listening channel
1212
1212
  * @param channel
1213
- * @param listener (args, callback(result)) args is the data from sender, callback is used to response sender with the result
1213
+ * @param listener (args, respond(result)) args is the data from sender, respond is used to send data back to sender's callback
1214
1214
  */
1215
1215
  on(channel, listener) {
1216
1216
  if (listener) {
@@ -1481,7 +1481,7 @@ class Driver {
1481
1481
 
1482
1482
  /**
1483
1483
  * Receive device commands
1484
- * @param listener(command, callback(result))
1484
+ * @param listener(command, respond(result))
1485
1485
  */
1486
1486
  onCommand(listener) {
1487
1487
  if (listener) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cutos/core",
3
- "version": "3.3.0",
3
+ "version": "3.3.1",
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",