wargerm 0.2.29 → 0.2.30
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/README.zh-CN.md +40 -40
- package/dist/components/WebsocketHeart/index.d.ts +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +192 -60
- package/dist/index.js +192 -59
- package/dist/utils/websocketHeart.d.ts +24 -0
- package/package.json +1 -1
package/README.zh-CN.md
CHANGED
@@ -1,40 +1,40 @@
|
|
1
|
-
<!--
|
2
|
-
* @Author: lijin
|
3
|
-
* @Date: 2021-10-18 15:22:28
|
4
|
-
* @LastEditTime: 2021-11-05 09:25:52
|
5
|
-
* @LastEditors: lijin
|
6
|
-
* @Description:
|
7
|
-
* @FilePath: \wargerm\README.zh-CN.md
|
8
|
-
* 可以输入预定的版权声明、个性签名、空行等
|
9
|
-
-->
|
10
|
-
|
11
|
-
## 📒 目录介绍
|
12
|
-
|
13
|
-
```
|
14
|
-
├── docs 文档存放路径
|
15
|
-
│ ├── index.md 首页展示
|
16
|
-
│ └── **.** 网站目录文档
|
17
|
-
├── src 组件主目录
|
18
|
-
│ ├── index.ts 组件注册
|
19
|
-
│ └── Foo 组件开发
|
20
|
-
├── .eslintrc.js eslint 配置
|
21
|
-
├── .fatherrc.ts father 配置
|
22
|
-
├── .umirc.ts dumi 配置
|
23
|
-
└── tsconfig.json typescript 配置
|
24
|
-
```
|
25
|
-
|
26
|
-
其余文件可自行查阅了解。
|
27
|
-
|
28
|
-
## 🤖 命令介绍
|
29
|
-
|
30
|
-
| 名称 | 描述 | 备注 |
|
31
|
-
| ----------------------- | -------------- | ----------------------------- |
|
32
|
-
| `npm run dev` | 项目启动 | - |
|
33
|
-
| `npm run test` | 组件测试 | - |
|
34
|
-
| `npm run test:coverage` | 代码覆盖率查看 | - |
|
35
|
-
| `npm run prettier` | 代码美化 | - |
|
36
|
-
| `npm run build` | 组件打包 | - |
|
37
|
-
| `npm run release` | 组件打包发布 | - |
|
38
|
-
| `npm run docs:build` | 文档打包 | - |
|
39
|
-
| `npm run docs:deploy` | 文档发布 | 这里默认是使用了 GitHub Pages |
|
40
|
-
| `npm run deploy` | 文档打包发布 | - |
|
1
|
+
<!--
|
2
|
+
* @Author: lijin
|
3
|
+
* @Date: 2021-10-18 15:22:28
|
4
|
+
* @LastEditTime: 2021-11-05 09:25:52
|
5
|
+
* @LastEditors: lijin
|
6
|
+
* @Description:
|
7
|
+
* @FilePath: \wargerm\README.zh-CN.md
|
8
|
+
* 可以输入预定的版权声明、个性签名、空行等
|
9
|
+
-->
|
10
|
+
|
11
|
+
## 📒 目录介绍
|
12
|
+
|
13
|
+
```
|
14
|
+
├── docs 文档存放路径
|
15
|
+
│ ├── index.md 首页展示
|
16
|
+
│ └── **.** 网站目录文档
|
17
|
+
├── src 组件主目录
|
18
|
+
│ ├── index.ts 组件注册
|
19
|
+
│ └── Foo 组件开发
|
20
|
+
├── .eslintrc.js eslint 配置
|
21
|
+
├── .fatherrc.ts father 配置
|
22
|
+
├── .umirc.ts dumi 配置
|
23
|
+
└── tsconfig.json typescript 配置
|
24
|
+
```
|
25
|
+
|
26
|
+
其余文件可自行查阅了解。
|
27
|
+
|
28
|
+
## 🤖 命令介绍
|
29
|
+
|
30
|
+
| 名称 | 描述 | 备注 |
|
31
|
+
| ----------------------- | -------------- | ----------------------------- |
|
32
|
+
| `npm run dev` | 项目启动 | - |
|
33
|
+
| `npm run test` | 组件测试 | - |
|
34
|
+
| `npm run test:coverage` | 代码覆盖率查看 | - |
|
35
|
+
| `npm run prettier` | 代码美化 | - |
|
36
|
+
| `npm run build` | 组件打包 | - |
|
37
|
+
| `npm run release` | 组件打包发布 | - |
|
38
|
+
| `npm run docs:build` | 文档打包 | - |
|
39
|
+
| `npm run docs:deploy` | 文档发布 | 这里默认是使用了 GitHub Pages |
|
40
|
+
| `npm run deploy` | 文档打包发布 | - |
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export default class WebsocketHeart {
|
2
|
+
WebSocket: any;
|
3
|
+
url: any;
|
4
|
+
options: any;
|
5
|
+
onopenCB: any;
|
6
|
+
onerrorCB: any;
|
7
|
+
onmessageCB: any;
|
8
|
+
oncloseCB: any;
|
9
|
+
HeartBeat: any;
|
10
|
+
stopTimer: any;
|
11
|
+
websock: any;
|
12
|
+
lockReconnect: any;
|
13
|
+
heartCheck: any;
|
14
|
+
constructor({ WebSocket, url, options, onopen, onerror, onmessage, onclose, HeartBeat, }: any);
|
15
|
+
init: () => void;
|
16
|
+
initWebSocket: () => void;
|
17
|
+
websocketOnopen: () => void;
|
18
|
+
websocketOnerror: (e: any) => void;
|
19
|
+
websocketOnmessage: (e: any) => void;
|
20
|
+
websocketOnclose: (e: string) => void;
|
21
|
+
send: (text: any) => void;
|
22
|
+
reconnect: () => void;
|
23
|
+
heartCheckFun: () => void;
|
24
|
+
}
|
package/dist/index.d.ts
CHANGED
@@ -23,3 +23,4 @@ export { default as Modal } from './components/Modal';
|
|
23
23
|
export { default as ModalForm } from './components/ModalForm';
|
24
24
|
export { default as TabelCard } from './components/TabelCard';
|
25
25
|
export { default as Cascader } from './components/Cascader';
|
26
|
+
export { default as WebsocketHeart } from './components/WebsocketHeart';
|
package/dist/index.esm.js
CHANGED
@@ -56,14 +56,9 @@ function ownKeys(object, enumerableOnly) {
|
|
56
56
|
|
57
57
|
if (Object.getOwnPropertySymbols) {
|
58
58
|
var symbols = Object.getOwnPropertySymbols(object);
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
63
|
-
});
|
64
|
-
}
|
65
|
-
|
66
|
-
keys.push.apply(keys, symbols);
|
59
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
60
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
61
|
+
})), keys.push.apply(keys, symbols);
|
67
62
|
}
|
68
63
|
|
69
64
|
return keys;
|
@@ -71,19 +66,12 @@ function ownKeys(object, enumerableOnly) {
|
|
71
66
|
|
72
67
|
function _objectSpread2(target) {
|
73
68
|
for (var i = 1; i < arguments.length; i++) {
|
74
|
-
var source = arguments[i]
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
81
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
82
|
-
} else {
|
83
|
-
ownKeys(Object(source)).forEach(function (key) {
|
84
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
85
|
-
});
|
86
|
-
}
|
69
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
70
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
71
|
+
_defineProperty(target, key, source[key]);
|
72
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
73
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
74
|
+
});
|
87
75
|
}
|
88
76
|
|
89
77
|
return target;
|
@@ -92,17 +80,11 @@ function _objectSpread2(target) {
|
|
92
80
|
function _typeof(obj) {
|
93
81
|
"@babel/helpers - typeof";
|
94
82
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
}
|
100
|
-
_typeof = function (obj) {
|
101
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
102
|
-
};
|
103
|
-
}
|
104
|
-
|
105
|
-
return _typeof(obj);
|
83
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
84
|
+
return typeof obj;
|
85
|
+
} : function (obj) {
|
86
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
87
|
+
}, _typeof(obj);
|
106
88
|
}
|
107
89
|
|
108
90
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
@@ -160,6 +142,9 @@ function _defineProperties(target, props) {
|
|
160
142
|
function _createClass(Constructor, protoProps, staticProps) {
|
161
143
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
162
144
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
145
|
+
Object.defineProperty(Constructor, "prototype", {
|
146
|
+
writable: false
|
147
|
+
});
|
163
148
|
return Constructor;
|
164
149
|
}
|
165
150
|
|
@@ -201,12 +186,15 @@ function _inherits(subClass, superClass) {
|
|
201
186
|
throw new TypeError("Super expression must either be null or a function");
|
202
187
|
}
|
203
188
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
189
|
+
Object.defineProperty(subClass, "prototype", {
|
190
|
+
value: Object.create(superClass && superClass.prototype, {
|
191
|
+
constructor: {
|
192
|
+
value: subClass,
|
193
|
+
writable: true,
|
194
|
+
configurable: true
|
195
|
+
}
|
196
|
+
}),
|
197
|
+
writable: false
|
210
198
|
});
|
211
199
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
212
200
|
}
|
@@ -10339,14 +10327,9 @@ function ownKeys$1(object, enumerableOnly) {
|
|
10339
10327
|
|
10340
10328
|
if (Object.getOwnPropertySymbols) {
|
10341
10329
|
var symbols = Object.getOwnPropertySymbols(object);
|
10342
|
-
|
10343
|
-
|
10344
|
-
|
10345
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
10346
|
-
});
|
10347
|
-
}
|
10348
|
-
|
10349
|
-
keys.push.apply(keys, symbols);
|
10330
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
10331
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
10332
|
+
})), keys.push.apply(keys, symbols);
|
10350
10333
|
}
|
10351
10334
|
|
10352
10335
|
return keys;
|
@@ -10354,19 +10337,12 @@ function ownKeys$1(object, enumerableOnly) {
|
|
10354
10337
|
|
10355
10338
|
function _objectSpread2$1(target) {
|
10356
10339
|
for (var i = 1; i < arguments.length; i++) {
|
10357
|
-
var source = arguments[i]
|
10358
|
-
|
10359
|
-
|
10360
|
-
|
10361
|
-
|
10362
|
-
|
10363
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
10364
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
10365
|
-
} else {
|
10366
|
-
ownKeys$1(Object(source)).forEach(function (key) {
|
10367
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
10368
|
-
});
|
10369
|
-
}
|
10340
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
10341
|
+
i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) {
|
10342
|
+
_defineProperty$1(target, key, source[key]);
|
10343
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) {
|
10344
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
10345
|
+
});
|
10370
10346
|
}
|
10371
10347
|
|
10372
10348
|
return target;
|
@@ -11523,4 +11499,160 @@ var TabelCard = function TabelCard(props, ref) {
|
|
11523
11499
|
|
11524
11500
|
var index$1 = /*#__PURE__*/React.forwardRef(TabelCard);
|
11525
11501
|
|
11526
|
-
|
11502
|
+
var WebsocketHeart = /*#__PURE__*/_createClass(function WebsocketHeart(_ref) {
|
11503
|
+
var _this = this;
|
11504
|
+
|
11505
|
+
var WebSocket = _ref.WebSocket,
|
11506
|
+
url = _ref.url,
|
11507
|
+
options = _ref.options,
|
11508
|
+
onopen = _ref.onopen,
|
11509
|
+
onerror = _ref.onerror,
|
11510
|
+
onmessage = _ref.onmessage,
|
11511
|
+
onclose = _ref.onclose,
|
11512
|
+
HeartBeat = _ref.HeartBeat;
|
11513
|
+
|
11514
|
+
_classCallCheck(this, WebsocketHeart);
|
11515
|
+
|
11516
|
+
this.WebSocket = void 0;
|
11517
|
+
this.url = void 0;
|
11518
|
+
this.options = void 0;
|
11519
|
+
this.onopenCB = void 0;
|
11520
|
+
this.onerrorCB = void 0;
|
11521
|
+
this.onmessageCB = void 0;
|
11522
|
+
this.oncloseCB = void 0;
|
11523
|
+
this.HeartBeat = void 0;
|
11524
|
+
this.stopTimer = void 0;
|
11525
|
+
this.websock = void 0;
|
11526
|
+
this.lockReconnect = void 0;
|
11527
|
+
this.heartCheck = void 0;
|
11528
|
+
|
11529
|
+
this.init = function () {
|
11530
|
+
_this.initWebSocket();
|
11531
|
+
|
11532
|
+
_this.heartCheckFun();
|
11533
|
+
};
|
11534
|
+
|
11535
|
+
this.initWebSocket = function () {
|
11536
|
+
_this.websock = new _this.WebSocket(_this.url, _this.options);
|
11537
|
+
|
11538
|
+
try {
|
11539
|
+
if ('WebSocket' in window) {
|
11540
|
+
_this.websock.onopen = _this.websocketOnopen;
|
11541
|
+
_this.websock.onerror = _this.websocketOnerror;
|
11542
|
+
_this.websock.onmessage = _this.websocketOnmessage;
|
11543
|
+
_this.websock.onclose = _this.websocketOnclose;
|
11544
|
+
}
|
11545
|
+
} catch (error) {
|
11546
|
+
_this.websock.on('open', _this.websocketOnopen);
|
11547
|
+
|
11548
|
+
_this.websock.on('error', _this.websocketOnerror);
|
11549
|
+
|
11550
|
+
_this.websock.on('close', _this.websocketOnclose);
|
11551
|
+
|
11552
|
+
_this.websock.on('message', _this.websocketOnmessage);
|
11553
|
+
}
|
11554
|
+
};
|
11555
|
+
|
11556
|
+
this.websocketOnopen = function () {
|
11557
|
+
console.log('WebSocket连接成功');
|
11558
|
+
|
11559
|
+
_this.onopenCB(); //心跳检测重置
|
11560
|
+
|
11561
|
+
|
11562
|
+
_this.heartCheck.reset().start();
|
11563
|
+
};
|
11564
|
+
|
11565
|
+
this.websocketOnerror = function (e) {
|
11566
|
+
console.log('WebSocket连接发生错误', e);
|
11567
|
+
|
11568
|
+
_this.onerrorCB(e);
|
11569
|
+
|
11570
|
+
_this.reconnect();
|
11571
|
+
};
|
11572
|
+
|
11573
|
+
this.websocketOnmessage = function (e) {
|
11574
|
+
console.log('-----接收消息-------', e); // const data = e.data //解析对象
|
11575
|
+
// To handle
|
11576
|
+
|
11577
|
+
_this.onmessageCB(e); //心跳检测重置
|
11578
|
+
|
11579
|
+
|
11580
|
+
_this.heartCheck.reset().start();
|
11581
|
+
};
|
11582
|
+
|
11583
|
+
this.websocketOnclose = function (e) {
|
11584
|
+
_this.oncloseCB(e);
|
11585
|
+
|
11586
|
+
if (e) {
|
11587
|
+
console.log('connection closed (' + e + ')');
|
11588
|
+
}
|
11589
|
+
|
11590
|
+
_this.reconnect();
|
11591
|
+
};
|
11592
|
+
|
11593
|
+
this.send = function (text) {
|
11594
|
+
// 数据发送
|
11595
|
+
try {
|
11596
|
+
_this.websock.send(text);
|
11597
|
+
} catch (err) {
|
11598
|
+
console.log('send failed (' + err + ')');
|
11599
|
+
}
|
11600
|
+
};
|
11601
|
+
|
11602
|
+
this.reconnect = function () {
|
11603
|
+
var that = _this;
|
11604
|
+
if (that.lockReconnect) return;
|
11605
|
+
that.lockReconnect = true; //没连接上会一直重连,设置延迟避免请求过多
|
11606
|
+
|
11607
|
+
setTimeout(function () {
|
11608
|
+
console.info('尝试重连...');
|
11609
|
+
that.initWebSocket();
|
11610
|
+
that.lockReconnect = false;
|
11611
|
+
}, 5000);
|
11612
|
+
};
|
11613
|
+
|
11614
|
+
this.heartCheckFun = function () {
|
11615
|
+
var that = _this; //心跳检测,每20s心跳一次
|
11616
|
+
|
11617
|
+
that.heartCheck = {
|
11618
|
+
timeout: 20000,
|
11619
|
+
timeoutObj: null,
|
11620
|
+
serverTimeoutObj: null,
|
11621
|
+
reset: function reset() {
|
11622
|
+
clearTimeout(this.timeoutObj); //clearTimeout(this.serverTimeoutObj);
|
11623
|
+
|
11624
|
+
return this;
|
11625
|
+
},
|
11626
|
+
start: function start() {
|
11627
|
+
this.timeoutObj = setTimeout(function () {
|
11628
|
+
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
11629
|
+
//onmessage拿到返回的心跳就说明连接正常
|
11630
|
+
that.send(that.HeartBeat);
|
11631
|
+
console.info('客户端发送心跳'); //self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
|
11632
|
+
// that.websock.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
|
11633
|
+
//}, self.timeout)
|
11634
|
+
}, this.timeout);
|
11635
|
+
}
|
11636
|
+
};
|
11637
|
+
};
|
11638
|
+
|
11639
|
+
this.WebSocket = WebSocket || WebSocket;
|
11640
|
+
this.url = url;
|
11641
|
+
this.options = options !== null && options !== void 0 ? options : [];
|
11642
|
+
|
11643
|
+
this.onopenCB = onopen || function () {};
|
11644
|
+
|
11645
|
+
this.onerrorCB = onerror || function () {};
|
11646
|
+
|
11647
|
+
this.onmessageCB = onmessage || function () {};
|
11648
|
+
|
11649
|
+
this.oncloseCB = onclose || function () {};
|
11650
|
+
|
11651
|
+
this.HeartBeat = HeartBeat || 'HeartBeat';
|
11652
|
+
this.stopTimer = false;
|
11653
|
+
this.websock = null;
|
11654
|
+
this.lockReconnect = false;
|
11655
|
+
this.heartCheck = null;
|
11656
|
+
});
|
11657
|
+
|
11658
|
+
export { Index$9 as AutoScroll, Index$b as Breadcrumb, WButton as Button, Index$c as Card, WCascader as Cascader, Index$4 as Checkbox, Index$8 as CountUp, Index$2 as DatePicker, index as IconFont, Index as Input, WInputNumber as InputNumber, Modal, ModalForm$1 as ModalForm, Index$7 as Number, NumericInput, Index$3 as Radio, Index$1 as Select, Index$a as Swiper, WSwitch as Switch, index$1 as TabelCard, Table, Index$5 as TreeSelect, Index$6 as WDatePicker, WForm$1 as WForm, WebsocketHeart };
|
package/dist/index.js
CHANGED
@@ -90,14 +90,9 @@ function ownKeys(object, enumerableOnly) {
|
|
90
90
|
|
91
91
|
if (Object.getOwnPropertySymbols) {
|
92
92
|
var symbols = Object.getOwnPropertySymbols(object);
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
97
|
-
});
|
98
|
-
}
|
99
|
-
|
100
|
-
keys.push.apply(keys, symbols);
|
93
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
94
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
95
|
+
})), keys.push.apply(keys, symbols);
|
101
96
|
}
|
102
97
|
|
103
98
|
return keys;
|
@@ -105,19 +100,12 @@ function ownKeys(object, enumerableOnly) {
|
|
105
100
|
|
106
101
|
function _objectSpread2(target) {
|
107
102
|
for (var i = 1; i < arguments.length; i++) {
|
108
|
-
var source = arguments[i]
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
115
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
116
|
-
} else {
|
117
|
-
ownKeys(Object(source)).forEach(function (key) {
|
118
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
119
|
-
});
|
120
|
-
}
|
103
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
104
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
105
|
+
_defineProperty(target, key, source[key]);
|
106
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
107
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
108
|
+
});
|
121
109
|
}
|
122
110
|
|
123
111
|
return target;
|
@@ -126,17 +114,11 @@ function _objectSpread2(target) {
|
|
126
114
|
function _typeof(obj) {
|
127
115
|
"@babel/helpers - typeof";
|
128
116
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
}
|
134
|
-
_typeof = function (obj) {
|
135
|
-
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
136
|
-
};
|
137
|
-
}
|
138
|
-
|
139
|
-
return _typeof(obj);
|
117
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
118
|
+
return typeof obj;
|
119
|
+
} : function (obj) {
|
120
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
121
|
+
}, _typeof(obj);
|
140
122
|
}
|
141
123
|
|
142
124
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
@@ -194,6 +176,9 @@ function _defineProperties(target, props) {
|
|
194
176
|
function _createClass(Constructor, protoProps, staticProps) {
|
195
177
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
196
178
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
179
|
+
Object.defineProperty(Constructor, "prototype", {
|
180
|
+
writable: false
|
181
|
+
});
|
197
182
|
return Constructor;
|
198
183
|
}
|
199
184
|
|
@@ -235,12 +220,15 @@ function _inherits(subClass, superClass) {
|
|
235
220
|
throw new TypeError("Super expression must either be null or a function");
|
236
221
|
}
|
237
222
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
223
|
+
Object.defineProperty(subClass, "prototype", {
|
224
|
+
value: Object.create(superClass && superClass.prototype, {
|
225
|
+
constructor: {
|
226
|
+
value: subClass,
|
227
|
+
writable: true,
|
228
|
+
configurable: true
|
229
|
+
}
|
230
|
+
}),
|
231
|
+
writable: false
|
244
232
|
});
|
245
233
|
if (superClass) _setPrototypeOf(subClass, superClass);
|
246
234
|
}
|
@@ -10373,14 +10361,9 @@ function ownKeys$1(object, enumerableOnly) {
|
|
10373
10361
|
|
10374
10362
|
if (Object.getOwnPropertySymbols) {
|
10375
10363
|
var symbols = Object.getOwnPropertySymbols(object);
|
10376
|
-
|
10377
|
-
|
10378
|
-
|
10379
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
10380
|
-
});
|
10381
|
-
}
|
10382
|
-
|
10383
|
-
keys.push.apply(keys, symbols);
|
10364
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
10365
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
10366
|
+
})), keys.push.apply(keys, symbols);
|
10384
10367
|
}
|
10385
10368
|
|
10386
10369
|
return keys;
|
@@ -10388,19 +10371,12 @@ function ownKeys$1(object, enumerableOnly) {
|
|
10388
10371
|
|
10389
10372
|
function _objectSpread2$1(target) {
|
10390
10373
|
for (var i = 1; i < arguments.length; i++) {
|
10391
|
-
var source = arguments[i]
|
10392
|
-
|
10393
|
-
|
10394
|
-
|
10395
|
-
|
10396
|
-
|
10397
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
10398
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
10399
|
-
} else {
|
10400
|
-
ownKeys$1(Object(source)).forEach(function (key) {
|
10401
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
10402
|
-
});
|
10403
|
-
}
|
10374
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
10375
|
+
i % 2 ? ownKeys$1(Object(source), !0).forEach(function (key) {
|
10376
|
+
_defineProperty$1(target, key, source[key]);
|
10377
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$1(Object(source)).forEach(function (key) {
|
10378
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
10379
|
+
});
|
10404
10380
|
}
|
10405
10381
|
|
10406
10382
|
return target;
|
@@ -11557,6 +11533,162 @@ var TabelCard = function TabelCard(props, ref) {
|
|
11557
11533
|
|
11558
11534
|
var index$1 = /*#__PURE__*/React__default['default'].forwardRef(TabelCard);
|
11559
11535
|
|
11536
|
+
var WebsocketHeart = /*#__PURE__*/_createClass(function WebsocketHeart(_ref) {
|
11537
|
+
var _this = this;
|
11538
|
+
|
11539
|
+
var WebSocket = _ref.WebSocket,
|
11540
|
+
url = _ref.url,
|
11541
|
+
options = _ref.options,
|
11542
|
+
onopen = _ref.onopen,
|
11543
|
+
onerror = _ref.onerror,
|
11544
|
+
onmessage = _ref.onmessage,
|
11545
|
+
onclose = _ref.onclose,
|
11546
|
+
HeartBeat = _ref.HeartBeat;
|
11547
|
+
|
11548
|
+
_classCallCheck(this, WebsocketHeart);
|
11549
|
+
|
11550
|
+
this.WebSocket = void 0;
|
11551
|
+
this.url = void 0;
|
11552
|
+
this.options = void 0;
|
11553
|
+
this.onopenCB = void 0;
|
11554
|
+
this.onerrorCB = void 0;
|
11555
|
+
this.onmessageCB = void 0;
|
11556
|
+
this.oncloseCB = void 0;
|
11557
|
+
this.HeartBeat = void 0;
|
11558
|
+
this.stopTimer = void 0;
|
11559
|
+
this.websock = void 0;
|
11560
|
+
this.lockReconnect = void 0;
|
11561
|
+
this.heartCheck = void 0;
|
11562
|
+
|
11563
|
+
this.init = function () {
|
11564
|
+
_this.initWebSocket();
|
11565
|
+
|
11566
|
+
_this.heartCheckFun();
|
11567
|
+
};
|
11568
|
+
|
11569
|
+
this.initWebSocket = function () {
|
11570
|
+
_this.websock = new _this.WebSocket(_this.url, _this.options);
|
11571
|
+
|
11572
|
+
try {
|
11573
|
+
if ('WebSocket' in window) {
|
11574
|
+
_this.websock.onopen = _this.websocketOnopen;
|
11575
|
+
_this.websock.onerror = _this.websocketOnerror;
|
11576
|
+
_this.websock.onmessage = _this.websocketOnmessage;
|
11577
|
+
_this.websock.onclose = _this.websocketOnclose;
|
11578
|
+
}
|
11579
|
+
} catch (error) {
|
11580
|
+
_this.websock.on('open', _this.websocketOnopen);
|
11581
|
+
|
11582
|
+
_this.websock.on('error', _this.websocketOnerror);
|
11583
|
+
|
11584
|
+
_this.websock.on('close', _this.websocketOnclose);
|
11585
|
+
|
11586
|
+
_this.websock.on('message', _this.websocketOnmessage);
|
11587
|
+
}
|
11588
|
+
};
|
11589
|
+
|
11590
|
+
this.websocketOnopen = function () {
|
11591
|
+
console.log('WebSocket连接成功');
|
11592
|
+
|
11593
|
+
_this.onopenCB(); //心跳检测重置
|
11594
|
+
|
11595
|
+
|
11596
|
+
_this.heartCheck.reset().start();
|
11597
|
+
};
|
11598
|
+
|
11599
|
+
this.websocketOnerror = function (e) {
|
11600
|
+
console.log('WebSocket连接发生错误', e);
|
11601
|
+
|
11602
|
+
_this.onerrorCB(e);
|
11603
|
+
|
11604
|
+
_this.reconnect();
|
11605
|
+
};
|
11606
|
+
|
11607
|
+
this.websocketOnmessage = function (e) {
|
11608
|
+
console.log('-----接收消息-------', e); // const data = e.data //解析对象
|
11609
|
+
// To handle
|
11610
|
+
|
11611
|
+
_this.onmessageCB(e); //心跳检测重置
|
11612
|
+
|
11613
|
+
|
11614
|
+
_this.heartCheck.reset().start();
|
11615
|
+
};
|
11616
|
+
|
11617
|
+
this.websocketOnclose = function (e) {
|
11618
|
+
_this.oncloseCB(e);
|
11619
|
+
|
11620
|
+
if (e) {
|
11621
|
+
console.log('connection closed (' + e + ')');
|
11622
|
+
}
|
11623
|
+
|
11624
|
+
_this.reconnect();
|
11625
|
+
};
|
11626
|
+
|
11627
|
+
this.send = function (text) {
|
11628
|
+
// 数据发送
|
11629
|
+
try {
|
11630
|
+
_this.websock.send(text);
|
11631
|
+
} catch (err) {
|
11632
|
+
console.log('send failed (' + err + ')');
|
11633
|
+
}
|
11634
|
+
};
|
11635
|
+
|
11636
|
+
this.reconnect = function () {
|
11637
|
+
var that = _this;
|
11638
|
+
if (that.lockReconnect) return;
|
11639
|
+
that.lockReconnect = true; //没连接上会一直重连,设置延迟避免请求过多
|
11640
|
+
|
11641
|
+
setTimeout(function () {
|
11642
|
+
console.info('尝试重连...');
|
11643
|
+
that.initWebSocket();
|
11644
|
+
that.lockReconnect = false;
|
11645
|
+
}, 5000);
|
11646
|
+
};
|
11647
|
+
|
11648
|
+
this.heartCheckFun = function () {
|
11649
|
+
var that = _this; //心跳检测,每20s心跳一次
|
11650
|
+
|
11651
|
+
that.heartCheck = {
|
11652
|
+
timeout: 20000,
|
11653
|
+
timeoutObj: null,
|
11654
|
+
serverTimeoutObj: null,
|
11655
|
+
reset: function reset() {
|
11656
|
+
clearTimeout(this.timeoutObj); //clearTimeout(this.serverTimeoutObj);
|
11657
|
+
|
11658
|
+
return this;
|
11659
|
+
},
|
11660
|
+
start: function start() {
|
11661
|
+
this.timeoutObj = setTimeout(function () {
|
11662
|
+
//这里发送一个心跳,后端收到后,返回一个心跳消息,
|
11663
|
+
//onmessage拿到返回的心跳就说明连接正常
|
11664
|
+
that.send(that.HeartBeat);
|
11665
|
+
console.info('客户端发送心跳'); //self.serverTimeoutObj = setTimeout(function(){//如果超过一定时间还没重置,说明后端主动断开了
|
11666
|
+
// that.websock.close();//如果onclose会执行reconnect,我们执行ws.close()就行了.如果直接执行reconnect 会触发onclose导致重连两次
|
11667
|
+
//}, self.timeout)
|
11668
|
+
}, this.timeout);
|
11669
|
+
}
|
11670
|
+
};
|
11671
|
+
};
|
11672
|
+
|
11673
|
+
this.WebSocket = WebSocket || WebSocket;
|
11674
|
+
this.url = url;
|
11675
|
+
this.options = options !== null && options !== void 0 ? options : [];
|
11676
|
+
|
11677
|
+
this.onopenCB = onopen || function () {};
|
11678
|
+
|
11679
|
+
this.onerrorCB = onerror || function () {};
|
11680
|
+
|
11681
|
+
this.onmessageCB = onmessage || function () {};
|
11682
|
+
|
11683
|
+
this.oncloseCB = onclose || function () {};
|
11684
|
+
|
11685
|
+
this.HeartBeat = HeartBeat || 'HeartBeat';
|
11686
|
+
this.stopTimer = false;
|
11687
|
+
this.websock = null;
|
11688
|
+
this.lockReconnect = false;
|
11689
|
+
this.heartCheck = null;
|
11690
|
+
});
|
11691
|
+
|
11560
11692
|
exports.AutoScroll = Index$9;
|
11561
11693
|
exports.Breadcrumb = Index$b;
|
11562
11694
|
exports.Button = WButton;
|
@@ -11581,3 +11713,4 @@ exports.Table = Table;
|
|
11581
11713
|
exports.TreeSelect = Index$5;
|
11582
11714
|
exports.WDatePicker = Index$6;
|
11583
11715
|
exports.WForm = WForm$1;
|
11716
|
+
exports.WebsocketHeart = WebsocketHeart;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export default class WebsocketHeart {
|
2
|
+
WebSocket: any;
|
3
|
+
url: any;
|
4
|
+
options: any;
|
5
|
+
onopenCB: any;
|
6
|
+
onerrorCB: any;
|
7
|
+
onmessageCB: any;
|
8
|
+
oncloseCB: any;
|
9
|
+
HeartBeat: any;
|
10
|
+
stopTimer: any;
|
11
|
+
websock: any;
|
12
|
+
lockReconnect: any;
|
13
|
+
heartCheck: any;
|
14
|
+
constructor({ WebSocket, url, options, onopen, onerror, onmessage, onclose, HeartBeat, }: any);
|
15
|
+
init: () => void;
|
16
|
+
initWebSocket: () => void;
|
17
|
+
websocketOnopen: () => void;
|
18
|
+
websocketOnerror: (e: any) => void;
|
19
|
+
websocketOnmessage: (e: any) => void;
|
20
|
+
websocketOnclose: (e: string) => void;
|
21
|
+
send: (text: any) => void;
|
22
|
+
reconnect: () => void;
|
23
|
+
heartCheckFun: () => void;
|
24
|
+
}
|