@zgfe/business-lib 1.1.29-visual.0 → 1.1.29-visual.2

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",
@@ -123,14 +126,18 @@ var SocketClient = /*#__PURE__*/function () {
123
126
  key: "onMessage",
124
127
  value: function onMessage(event) {
125
128
  var res = JSON.parse(event.data);
129
+ if (res.type === SocketClientTypes.RequestType.pong) return;
126
130
  var res_ = res.data;
127
131
  try {
128
132
  res_ = JSON.parse(res.data);
129
133
  } catch (e) {
130
134
  this.log('info', '非json响应', res_);
131
135
  }
136
+ if (res_.type === SocketClientTypes.RequestType.login) {
137
+ this.log('info', '登录成功');
138
+ return;
139
+ }
132
140
  var data = res_.data;
133
- if (!data || !data.event) return;
134
141
  if (this.listeners[data.event]) {
135
142
  this.listeners[data.event].forEach(function (handle) {
136
143
  handle.call(undefined, data.payload);
@@ -141,7 +148,7 @@ var SocketClient = /*#__PURE__*/function () {
141
148
  key: "ping",
142
149
  value: function ping() {
143
150
  var _this2 = this;
144
- setInterval(function () {
151
+ this.pingTimer = setInterval(function () {
145
152
  var _this2$client;
146
153
  (_this2$client = _this2.client) === null || _this2$client === void 0 ? void 0 : _this2$client.send(JSON.stringify({
147
154
  type: SocketClientTypes.RequestType.ping
@@ -209,7 +216,12 @@ var SocketClient = /*#__PURE__*/function () {
209
216
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
210
217
  args[_key - 1] = arguments[_key];
211
218
  }
212
- (_console = console)[type].apply(_console, args);
219
+ if (this.showLog) (_console = console).log.apply(_console, ["%c\u3010socketClient\u3011:".concat(type), "color: ".concat(type === 'error' ? 'red' : '#1890ff')].concat(args));
220
+ }
221
+ }, {
222
+ key: "openLog",
223
+ value: function openLog(open) {
224
+ this.showLog = open;
213
225
  }
214
226
  }]);
215
227
  return SocketClient;
@@ -7,6 +7,7 @@ declare namespace SocketClientTypes {
7
7
  enum RequestType {
8
8
  common = 0,
9
9
  ping = 1,
10
+ pong = 2,
10
11
  login = 3,
11
12
  normal = 5,
12
13
  img = 6
@@ -10,6 +10,7 @@ var SocketClientTypes;
10
10
  (function (RequestType) {
11
11
  RequestType[RequestType["common"] = 0] = "common";
12
12
  RequestType[RequestType["ping"] = 1] = "ping";
13
+ RequestType[RequestType["pong"] = 2] = "pong";
13
14
  RequestType[RequestType["login"] = 3] = "login";
14
15
  RequestType[RequestType["normal"] = 5] = "normal";
15
16
  RequestType[RequestType["img"] = 6] = "img";
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.2",
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": "4b4aab8d962968da9a435213ac26f8e7d7473262"
63
63
  }