@zgfe/business-lib 1.1.29-visual.0 → 1.1.29-visual.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.
@@ -28,6 +28,7 @@ export default (function () {
28
28
  }, []);
29
29
  useEffect(function () {
30
30
  if (!client) return;
31
+ client.openLog(true);
31
32
  client.onConnected(onConnected);
32
33
  client.onError(onError);
33
34
  }, [client]);
@@ -5,6 +5,8 @@ declare class SocketClient {
5
5
  private params?;
6
6
  private listeners;
7
7
  private catch;
8
+ private showLog;
9
+ private pingTimer?;
8
10
  constructor(url: string, params?: Record<string, any>);
9
11
  emit(event: string, payload: SocketClientTypes.Message['data']['payload']): void;
10
12
  on(type: string, handle: SocketClientTypes.Handler): void;
@@ -23,5 +25,6 @@ declare class SocketClient {
23
25
  close(): void;
24
26
  destroy(): void;
25
27
  private log;
28
+ openLog(open: boolean): void;
26
29
  }
27
30
  export default SocketClient;
@@ -23,6 +23,8 @@ var SocketClient = /*#__PURE__*/function () {
23
23
  this.params = void 0;
24
24
  this.listeners = {};
25
25
  this.catch = [];
26
+ this.showLog = false;
27
+ this.pingTimer = void 0;
26
28
  this.url = url;
27
29
  this.params = params;
28
30
  this.open();
@@ -99,6 +101,7 @@ var SocketClient = /*#__PURE__*/function () {
99
101
  (_this$listeners$disco = this.listeners['disconnected']) === null || _this$listeners$disco === void 0 ? void 0 : _this$listeners$disco.forEach(function (handle) {
100
102
  handle.call(undefined);
101
103
  });
104
+ clearInterval(this.pingTimer);
102
105
  }
103
106
  }, {
104
107
  key: "_onOpen",
@@ -129,8 +132,11 @@ var SocketClient = /*#__PURE__*/function () {
129
132
  } catch (e) {
130
133
  this.log('info', '非json响应', res_);
131
134
  }
135
+ if (res_.type === SocketClientTypes.RequestType.login) {
136
+ this.log('info', '登录成功');
137
+ return;
138
+ }
132
139
  var data = res_.data;
133
- if (!data || !data.event) return;
134
140
  if (this.listeners[data.event]) {
135
141
  this.listeners[data.event].forEach(function (handle) {
136
142
  handle.call(undefined, data.payload);
@@ -141,7 +147,7 @@ var SocketClient = /*#__PURE__*/function () {
141
147
  key: "ping",
142
148
  value: function ping() {
143
149
  var _this2 = this;
144
- setInterval(function () {
150
+ this.pingTimer = setInterval(function () {
145
151
  var _this2$client;
146
152
  (_this2$client = _this2.client) === null || _this2$client === void 0 ? void 0 : _this2$client.send(JSON.stringify({
147
153
  type: SocketClientTypes.RequestType.ping
@@ -209,7 +215,12 @@ var SocketClient = /*#__PURE__*/function () {
209
215
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
210
216
  args[_key - 1] = arguments[_key];
211
217
  }
212
- (_console = console)[type].apply(_console, args);
218
+ if (this.showLog) (_console = console).log.apply(_console, ["%c\u3010socketClient\u3011:".concat(type), "color: ".concat(type === 'error' ? 'red' : '#1890ff')].concat(args));
219
+ }
220
+ }, {
221
+ key: "openLog",
222
+ value: function openLog(open) {
223
+ this.showLog = open;
213
224
  }
214
225
  }]);
215
226
  return SocketClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgfe/business-lib",
3
- "version": "1.1.29-visual.0",
3
+ "version": "1.1.29-visual.1",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",
@@ -59,5 +59,5 @@
59
59
  "react": "^16.12.0 || ^17.0.0",
60
60
  "yorkie": "^2.0.0"
61
61
  },
62
- "gitHead": "11e762a9146e1f1d9259774458ba80df10fce4e0"
62
+ "gitHead": "50cb592d16995908023914177748445ece01c2b0"
63
63
  }