ws-process 0.3.42 → 0.3.44

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/actions.js CHANGED
@@ -4,9 +4,10 @@ export const newWSInstance = (wSocket) => ({
4
4
  wSocket,
5
5
  });
6
6
  export const REMOVE_WS_INSTANCE = 'REMOVE_WS_INSTANCE';
7
- export const removeWSInstance = (wSocket) => ({
7
+ export const removeWSInstance = (wSocket, doNotClose) => ({
8
8
  type: REMOVE_WS_INSTANCE,
9
9
  wSocket,
10
+ doNotClose,
10
11
  });
11
12
 
12
13
  export const STORE_SPLITTED_DATA = 'STORE_SPLITTED_DATA';
package/index.js CHANGED
@@ -65,6 +65,10 @@ function getUSP(url) {
65
65
  return [usp, urlPath];
66
66
  }
67
67
 
68
+ function isPreviewMode() {
69
+ return window.location.pathname.startsWith('/lc-ui5/preview/');
70
+ }
71
+
68
72
  function getWebSocket() {
69
73
  return (dispatch) => new Promise((resolve, reject) => {
70
74
  const existWS = local.wsProcess.wSocket;
@@ -78,13 +82,34 @@ function getWebSocket() {
78
82
  }),
79
83
  );
80
84
  }
85
+ /*
86
+ 현재 프리뷰 모드인데
87
+ 이미 생성한 웹소켓이 프리뷰 모드가 아닐때 만들어진것일 경우에는
88
+ 제거하고 다시 만들어준다. 단 close()는 하지 않는다.
89
+ close()하면 onmessage 이벤트핸들러가 실행중에 중단되어
90
+ 프로그램이 정상적으로 동작하지 않는다.
91
+ */
92
+ if (isPreviewMode() && !existWS.url.endsWith('/dev')) {
93
+ //
94
+ if (existWS.readyState === existWS.OPEN) {
95
+ // existWS.close();
96
+ local.dispatch(removeWSInstance(existWS, true));
97
+ }
98
+ return resolve(
99
+ new Promise((resolveInner) => {
100
+ setTimeout(() => {
101
+ resolveInner(dispatch(getWebSocket()));
102
+ }, 500);
103
+ }),
104
+ );
105
+ }
81
106
  return resolve(existWS);
82
107
  }
83
108
  if (!local.wsURL) {
84
109
  console.error('URL of WebSocket is undefined');
85
110
  return reject(new Error('URL of WebSocket is undefined'));
86
111
  }
87
- const newWsUrl = window.location.pathname.startsWith('/lc-ui5/preview/') ? local.wsURL.replace(/\/(prod){1}$/, '/dev') : local.wsURL;
112
+ const newWsUrl = isPreviewMode() ? local.wsURL.replace(/\/(prod){1}$/, '/dev') : local.wsURL;
88
113
  const wSocket = new WebSocket(newWsUrl);
89
114
 
90
115
  wSocket.onopen = (event) => {
@@ -600,7 +625,7 @@ function asyncSend(msg) {
600
625
  const headers = {};
601
626
  headers['bsg-support-process-id'] = msg.processID;
602
627
  headers['bsg-support-api-key'] = user.apiKey || undefined;
603
- headers['bsg-support-stage'] = window.location.pathname.startsWith('/lc-ui5/preview/') ? 'dev' : local.stage;
628
+ headers['bsg-support-stage'] = isPreviewMode() ? 'dev' : local.stage;
604
629
  headers['bsg-support-token'] = user.token;
605
630
  headers['bsg-support-session'] = user.session;
606
631
  headers['bsg-support-user-id'] = user.id;
@@ -693,7 +718,7 @@ function asyncSend(msg) {
693
718
  callback.afterFailed(newData);
694
719
  }
695
720
  if (callback.always) {
696
- callback.always();
721
+ callback.always(newData);
697
722
  }
698
723
  }
699
724
  if (cProcessItem.reject) {
@@ -955,7 +980,7 @@ function asyncSend(msg) {
955
980
  callback.afterFailed(jsonResponse);
956
981
  }
957
982
  if (callback.always) {
958
- callback.always();
983
+ callback.always(jsonResponse);
959
984
  }
960
985
  }
961
986
  if (cProcessItem.reject) {
@@ -1208,7 +1233,7 @@ function runProcess(processID, data) {
1208
1233
  } else {
1209
1234
  local.afterEachProcess(prcInner, local.wsProcess.processes);
1210
1235
 
1211
- // prcInner.reject(error);
1236
+ prcInner.reject(error);
1212
1237
  wrapClearWSProcess(error.processID);
1213
1238
  }
1214
1239
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ws-process",
3
- "version": "0.3.42",
3
+ "version": "0.3.44",
4
4
  "description": "Process Management for Web Socket Client",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/reducer.js CHANGED
@@ -1,5 +1,6 @@
1
+ /* eslint-disable import/no-unresolved */
1
2
  /* eslint-disable no-param-reassign */
2
- import { tryit } from 'ui5-lib-rc';
3
+ import { tryit } from '@bsgp/lib-core';
3
4
  import produce from 'immer';
4
5
  import {
5
6
  ADD_WS_PROCESS,
@@ -36,7 +37,11 @@ export default function (state = initialState, action) {
36
37
  (stt) => stt === action.wSocket.readyState,
37
38
  ).length === 0
38
39
  ) {
39
- action.wSocket.close();
40
+ if (action.doNotClose === true) {
41
+ // pass
42
+ } else {
43
+ action.wSocket.close();
44
+ }
40
45
  }
41
46
  }
42
47
  draft.wSocket = null;