@xuda.io/xuda-worker-bundle-min 1.3.515 → 1.3.517

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 +52 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -873,6 +873,7 @@ var RUNTIME_SERVER_WEBSOCKET_CONNECTED = null;
873
873
  var WEBSOCKET_PROCESS_PID = null;
874
874
 
875
875
  glb.worker_queue_num = 0;
876
+ glb.websocket_queue_num = 0;
876
877
 
877
878
  func.common.get_module = async function (SESSION_ID, module, paramsP = {}) {
878
879
  let ret;
@@ -1120,27 +1121,74 @@ func.common.perform_rpi_request = async function (
1120
1121
  }
1121
1122
  };
1122
1123
  const ws = async function () {
1124
+ glb.websocket_queue_num++;
1123
1125
  RUNTIME_SERVER_WEBSOCKET.emit("message", {
1124
1126
  service: serviceP,
1125
1127
  data,
1128
+ websocket_queue_num: glb.websocket_queue_num,
1126
1129
  });
1127
1130
  throw new Error("fail to fetch from ws");
1128
1131
  };
1129
1132
 
1130
1133
  try {
1131
1134
  if (
1132
- RUNTIME_SERVER_WEBSOCKET &&
1133
- RUNTIME_SERVER_WEBSOCKET_CONNECTED &&
1135
+ // RUNTIME_SERVER_WEBSOCKET &&
1136
+ // RUNTIME_SERVER_WEBSOCKET_CONNECTED &&
1134
1137
  SESSION_OBJ?.[SESSION_ID]?.rpi_http_methods?.includes(serviceP)
1135
1138
  ) {
1136
- return await ws();
1139
+ // return await ws();
1140
+ return await func.common.get_data_from_websocket(
1141
+ SESSION_ID,
1142
+ serviceP,
1143
+ data
1144
+ );
1137
1145
  } else {
1138
- throw new Error("fail to fetch from ws websocket inactive");
1146
+ throw new Error("method not found in rpi_http_methods");
1139
1147
  }
1140
1148
  } catch (err) {
1141
1149
  return await http();
1142
1150
  }
1143
1151
  };
1152
+
1153
+ func.common.get_data_from_websocket = async function (
1154
+ SESSION_ID,
1155
+ serviceP,
1156
+ data
1157
+ ) {
1158
+ var _session = _this.SESSION_OBJ[SESSION_ID];
1159
+ return new Promise(function (resolve, reject) {
1160
+ glb.websocket_queue_num++;
1161
+ if (glb.IS_WORKER) {
1162
+ func.utils.post_back_to_client(
1163
+ SESSION_ID,
1164
+ "get_doc_from_websocket",
1165
+ _session.worker_id,
1166
+ { doc_id: idP }
1167
+ );
1168
+
1169
+ self.addEventListener("get_doc_obj_from_build_worker_" + idP, (event) => {
1170
+ resolve(event.detail.data);
1171
+ });
1172
+ } else {
1173
+ if (RUNTIME_SERVER_WEBSOCKET && RUNTIME_SERVER_WEBSOCKET_CONNECTED) {
1174
+ RUNTIME_SERVER_WEBSOCKET.emit("message", {
1175
+ service: serviceP,
1176
+ data,
1177
+ websocket_queue_num: glb.websocket_queue_num,
1178
+ });
1179
+ $("body").on(
1180
+ "get_ws_data_response_" + glb.websocket_queue_num,
1181
+ (e, data) => {
1182
+ resolve(data.data);
1183
+ $("body").off("get_ws_data_response_" + glb.websocket_queue_num);
1184
+ }
1185
+ );
1186
+ } else {
1187
+ throw new Error("fail to fetch from ws websocket inactive");
1188
+ }
1189
+ }
1190
+ });
1191
+ };
1144
1192
  glb.DEBUG_INFO_OBJ = {};
1145
1193
  // var CONNECTION_ATTEMPTS = 0;
1146
1194
  glb.APP_INFO = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.515",
3
+ "version": "1.3.517",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {