@xuda.io/xuda-worker-bundle-min 1.3.487 → 1.3.488

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.
Files changed (2) hide show
  1. package/index.js +95 -79
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1019,34 +1019,48 @@ func.common.perform_rpi_request = async function (
1019
1019
  opt = {},
1020
1020
  data
1021
1021
  ) {
1022
- var url = func.common.get_url(SESSION_ID, "rpi", "");
1023
- var _session = SESSION_OBJ[SESSION_ID];
1024
- const app_id = _session.APP_ID;
1022
+ const http = async function () {
1023
+ var url = func.common.get_url(SESSION_ID, "rpi", "");
1024
+ var _session = SESSION_OBJ[SESSION_ID];
1025
+ const app_id = _session.APP_ID;
1025
1026
 
1026
- if (
1027
- APP_OBJ[app_id].is_deployment &&
1028
- _session.rpi_http_methods?.includes(serviceP)
1029
- ) {
1030
- url = "https://" + _session.host + "/rpi/";
1031
- }
1027
+ if (
1028
+ APP_OBJ[app_id].is_deployment &&
1029
+ _session.rpi_http_methods?.includes(serviceP)
1030
+ ) {
1031
+ url = "https://" + _session.host + "/rpi/";
1032
+ }
1032
1033
 
1033
- url += serviceP;
1034
+ url += serviceP;
1034
1035
 
1035
- try {
1036
- const response = await fetch(url, {
1037
- method: opt.type ? opt.type : "POST",
1038
- headers: {
1039
- Accept: "application/json",
1040
- "Content-Type": "application/json",
1041
- },
1042
- body: JSON.stringify(data),
1036
+ try {
1037
+ const response = await fetch(url, {
1038
+ method: opt.type ? opt.type : "POST",
1039
+ headers: {
1040
+ Accept: "application/json",
1041
+ "Content-Type": "application/json",
1042
+ },
1043
+ body: JSON.stringify(data),
1044
+ });
1045
+ if (!response.ok) throw "";
1046
+ const json = await response.json();
1047
+ return json;
1048
+ } catch (err) {
1049
+ console.error(err);
1050
+ return {};
1051
+ }
1052
+ };
1053
+ const ws = async function () {
1054
+ RUNTIME_SERVER_WEBSOCKET.emit("message", {
1055
+ service: serviceP,
1056
+ data,
1043
1057
  });
1044
- if (!response.ok) throw "";
1045
- const json = await response.json();
1046
- return json;
1047
- } catch (err) {
1048
- console.error(err);
1049
- return {};
1058
+ };
1059
+
1060
+ if (RUNTIME_SERVER_WEBSOCKET && RUNTIME_SERVER_WEBSOCKET_CONNECTED) {
1061
+ return await ws();
1062
+ } else {
1063
+ return await http();
1050
1064
  }
1051
1065
  };
1052
1066
  glb.DEBUG_INFO_OBJ = {};
@@ -5047,15 +5061,17 @@ func.utils.job_worker = function (session_id) {
5047
5061
  _this._was_busy = true;
5048
5062
  } else {
5049
5063
  // idle
5050
- if (glb.IS_WORKER) {
5051
- func.utils.post_back_to_client(
5052
- SESSION_ID,
5053
- "worker_busy_off",
5054
- _session.worker_id,
5055
- null
5056
- );
5057
- } else {
5058
- func.UI.utils.indicator.worker.normal();
5064
+ if (_this._was_busy) {
5065
+ if (glb.IS_WORKER) {
5066
+ func.utils.post_back_to_client(
5067
+ SESSION_ID,
5068
+ "worker_busy_off",
5069
+ _session.worker_id,
5070
+ null
5071
+ );
5072
+ } else {
5073
+ func.UI.utils.indicator.worker.normal();
5074
+ }
5059
5075
  }
5060
5076
  _this._was_busy = false;
5061
5077
  }
@@ -5729,54 +5745,54 @@ func.utils.ws_worker.functions = {
5729
5745
  data: params,
5730
5746
  });
5731
5747
  },
5732
- heartbeat: async function (params) {
5733
- var SESSION_ID = params.session_id;
5748
+ // heartbeat: async function (params) {
5749
+ // var SESSION_ID = params.session_id;
5734
5750
 
5735
- try {
5736
- const do_heartbeat = async function (
5737
- app_replicate,
5738
- app_id,
5739
- token_id,
5740
- fingerprint,
5741
- device_name,
5742
- stat
5743
- ) {
5744
- try {
5745
- module.exports.close_expired_device_log_sessions(app_id);
5746
-
5747
- return await update_device(
5748
- app_replicate,
5749
- app_id,
5750
- token_id,
5751
- fingerprint,
5752
- device_name,
5753
- stat
5754
- );
5755
- } catch (err) {
5756
- return { code: -400, data: err.message };
5757
- }
5758
- };
5759
- let ret = await do_heartbeat(
5760
- params.app_replicate,
5761
- params.app_id,
5762
- params.gtp_token || req.body.token,
5763
- params.fingerprint,
5764
- params.device_name,
5765
- params.stat
5766
- );
5751
+ // try {
5752
+ // const do_heartbeat = async function (
5753
+ // app_replicate,
5754
+ // app_id,
5755
+ // token_id,
5756
+ // fingerprint,
5757
+ // device_name,
5758
+ // stat
5759
+ // ) {
5760
+ // try {
5761
+ // module.exports.close_expired_device_log_sessions(app_id);
5762
+
5763
+ // return await update_device(
5764
+ // app_replicate,
5765
+ // app_id,
5766
+ // token_id,
5767
+ // fingerprint,
5768
+ // device_name,
5769
+ // stat
5770
+ // );
5771
+ // } catch (err) {
5772
+ // return { code: -400, data: err.message };
5773
+ // }
5774
+ // };
5775
+ // let ret = await do_heartbeat(
5776
+ // params.app_replicate,
5777
+ // params.app_id,
5778
+ // params.gtp_token || req.body.token,
5779
+ // params.fingerprint,
5780
+ // params.device_name,
5781
+ // params.stat
5782
+ // );
5767
5783
 
5768
- // session_status: ret_session.data.stat
5769
- if (params.token) {
5770
- try {
5771
- const couch = await __.rpi.get_app_couch(req.body.app_id);
5772
- const session_doc = await couch.get(req.body.token);
5773
- ret.session_stat = session_doc.stat;
5774
- } catch (error) {}
5775
- }
5776
- } catch (error) {
5777
- debugger;
5778
- }
5779
- },
5784
+ // // session_status: ret_session.data.stat
5785
+ // if (params.token) {
5786
+ // try {
5787
+ // const couch = await __.rpi.get_app_couch(req.body.app_id);
5788
+ // const session_doc = await couch.get(req.body.token);
5789
+ // ret.session_stat = session_doc.stat;
5790
+ // } catch (error) {}
5791
+ // }
5792
+ // } catch (error) {
5793
+ // debugger;
5794
+ // }
5795
+ // },
5780
5796
  return_rpi_request_from_studio: function (params) {
5781
5797
  var SESSION_ID = params.session_id;
5782
5798
  function emitCustomEvent(eventName, detail) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.487",
3
+ "version": "1.3.488",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {