@zgfe/business-lib 1.1.29-visual.0 → 1.1.29-visual.10
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/es/constants/apis.d.ts +1 -0
- package/es/constants/apis.js +2 -1
- package/es/demoWrapper/content.d.ts +2 -1
- package/es/demoWrapper/content.js +15 -12
- package/es/demoWrapper/demo/index.js +5 -3
- package/es/demoWrapper/head.d.ts +3 -1
- package/es/demoWrapper/head.js +17 -5
- package/es/demoWrapper/index.js +18 -10
- package/es/socket/demo/demo.js +115 -24
- package/es/socket/demo/index.less +23 -0
- package/es/socket/index.d.ts +7 -3
- package/es/socket/index.js +101 -40
- package/es/socket/types.d.ts +13 -3
- package/es/socket/types.js +9 -1
- package/package.json +2 -2
package/es/constants/apis.d.ts
CHANGED
package/es/constants/apis.js
CHANGED
|
@@ -6,6 +6,7 @@ var Apis = {
|
|
|
6
6
|
updatePanelTarget: '/apppanel/updateElemet.jsp',
|
|
7
7
|
queryPanelGroup: '/apppanel/panels.jsp',
|
|
8
8
|
queryDatasetList: '/zg/web/cdp/inner/dataset/list',
|
|
9
|
-
queryDatasetDetail: '/zg/web/cdp/inner/dataset/detail'
|
|
9
|
+
queryDatasetDetail: '/zg/web/cdp/inner/dataset/detail',
|
|
10
|
+
getSocketToken: '/zg/web/v2/tracking/view/websocket/token'
|
|
10
11
|
};
|
|
11
12
|
export default Apis;
|
|
@@ -82,10 +82,16 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
82
82
|
setStore = _useState18[1];
|
|
83
83
|
useEffect(function () {
|
|
84
84
|
if (!needMeta || !currentApp) return;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
if (currentApp.appsHasData && currentApp.appsHasData.length) {
|
|
86
|
+
loadUserProps();
|
|
87
|
+
loadEvents();
|
|
88
|
+
loadEnvList();
|
|
89
|
+
loadUserGroup();
|
|
90
|
+
} else {
|
|
91
|
+
setLoadEnv(false);
|
|
92
|
+
setLoadEvent(false);
|
|
93
|
+
setLoadUsers(false);
|
|
94
|
+
}
|
|
89
95
|
}, [currentApp, needMeta]);
|
|
90
96
|
useEffect(function () {
|
|
91
97
|
if (loadEnv || loadEvent || loadUsers || loadUserGroups) return;
|
|
@@ -100,7 +106,7 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
100
106
|
ajax('/analysis/api/common/proxy/usergroup/getAll.jsp', {
|
|
101
107
|
method: 'post',
|
|
102
108
|
params: {
|
|
103
|
-
appId: currentApp,
|
|
109
|
+
appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
104
110
|
platform: 0,
|
|
105
111
|
includeDefault: true,
|
|
106
112
|
includeToday: true
|
|
@@ -115,7 +121,7 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
115
121
|
ajax('/analysis/api/common/proxy/appusergroup/getUserPropMeta.jsp', {
|
|
116
122
|
method: 'post',
|
|
117
123
|
params: {
|
|
118
|
-
app_id: currentApp,
|
|
124
|
+
app_id: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
119
125
|
platform: 0
|
|
120
126
|
}
|
|
121
127
|
}).then(function (res) {
|
|
@@ -128,7 +134,7 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
128
134
|
ajax('/analysis/api/common/proxy/data/queryEventMetasOfGroup.jsp', {
|
|
129
135
|
method: 'post',
|
|
130
136
|
params: {
|
|
131
|
-
app_id: currentApp,
|
|
137
|
+
app_id: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
132
138
|
platform: 0,
|
|
133
139
|
is_all: true
|
|
134
140
|
}
|
|
@@ -142,7 +148,7 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
142
148
|
ajax('/analysis/api/common/proxy/appusergroup/getEventEnvData.jsp', {
|
|
143
149
|
method: 'post',
|
|
144
150
|
params: {
|
|
145
|
-
app_id: currentApp,
|
|
151
|
+
app_id: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
146
152
|
platform: 0
|
|
147
153
|
}
|
|
148
154
|
}).then(function (res) {
|
|
@@ -157,10 +163,7 @@ var DemoContent = function DemoContent(_ref3) {
|
|
|
157
163
|
}
|
|
158
164
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BizGlobalDataContext.Provider, {
|
|
159
165
|
value: {
|
|
160
|
-
currentApp:
|
|
161
|
-
appId: currentApp,
|
|
162
|
-
platform: 0
|
|
163
|
-
},
|
|
166
|
+
currentApp: currentApp,
|
|
164
167
|
eventGroupList: store === null || store === void 0 ? void 0 : store.eventGroupList,
|
|
165
168
|
userPropList: store === null || store === void 0 ? void 0 : store.userPropList,
|
|
166
169
|
eventEnvList: store === null || store === void 0 ? void 0 : store.envPropList,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DemoWrapper } from '@zgfe/business-lib';
|
|
2
|
+
import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
|
|
3
3
|
export default (function () {
|
|
4
4
|
return /*#__PURE__*/React.createElement(DemoWrapper, {
|
|
5
|
-
defaultApp: 3,
|
|
6
5
|
needMeta: true
|
|
7
|
-
},
|
|
6
|
+
}, /*#__PURE__*/React.createElement(BizGlobalDataContext.Consumer, null, function (_ref) {
|
|
7
|
+
var currentApp = _ref.currentApp;
|
|
8
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, "\u5F53\u524D\u5E94\u7528\uFF1A", currentApp.appName, "(id: ", currentApp.id, ")");
|
|
9
|
+
}));
|
|
8
10
|
});
|
package/es/demoWrapper/head.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { AppInfoProps } from '../context';
|
|
2
3
|
declare const DemoHeader: React.FC<{
|
|
3
4
|
defaultApp?: number;
|
|
4
|
-
onChangeApp?: (
|
|
5
|
+
onChangeApp?: (app: AppInfoProps) => void;
|
|
6
|
+
onLoading?: (loading: boolean) => void;
|
|
5
7
|
}>;
|
|
6
8
|
export default DemoHeader;
|
package/es/demoWrapper/head.js
CHANGED
|
@@ -9,7 +9,8 @@ import React, { useEffect, useState } from 'react';
|
|
|
9
9
|
import request from '../utils/ajax';
|
|
10
10
|
var DemoHeader = function DemoHeader(_ref) {
|
|
11
11
|
var defaultApp = _ref.defaultApp,
|
|
12
|
-
onChangeApp = _ref.onChangeApp
|
|
12
|
+
onChangeApp = _ref.onChangeApp,
|
|
13
|
+
onLoading = _ref.onLoading;
|
|
13
14
|
var _useState = useState([]),
|
|
14
15
|
_useState2 = _slicedToArray(_useState, 2),
|
|
15
16
|
appList = _useState2[0],
|
|
@@ -21,17 +22,25 @@ var DemoHeader = function DemoHeader(_ref) {
|
|
|
21
22
|
useEffect(function () {
|
|
22
23
|
queryAppList();
|
|
23
24
|
}, []);
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
if (onLoading) onLoading(loading);
|
|
27
|
+
}, [loading, appList]);
|
|
24
28
|
function queryAppList() {
|
|
25
29
|
setLoading(true);
|
|
26
30
|
request('/analysis/api/common/proxy/data/v2ajaxGetDataByApp.jsp').then(function (res) {
|
|
27
31
|
setAppList(res.applist);
|
|
28
|
-
if (
|
|
32
|
+
if (defaultApp) {
|
|
33
|
+
_onChange(res.applist.find(function (item) {
|
|
34
|
+
return item.id === defaultApp;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
if (!defaultApp && res.applist.length) _onChange(res.applist[0]);
|
|
29
38
|
}).finally(function () {
|
|
30
39
|
setLoading(false);
|
|
31
40
|
});
|
|
32
41
|
}
|
|
33
|
-
function
|
|
34
|
-
if (onChangeApp) onChangeApp(
|
|
42
|
+
function _onChange(item) {
|
|
43
|
+
if (onChangeApp) onChangeApp(item);
|
|
35
44
|
}
|
|
36
45
|
if (loading) return /*#__PURE__*/React.createElement(Skeleton.Input, null);
|
|
37
46
|
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Select, {
|
|
@@ -41,7 +50,10 @@ var DemoHeader = function DemoHeader(_ref) {
|
|
|
41
50
|
label: 'appName',
|
|
42
51
|
value: 'id'
|
|
43
52
|
},
|
|
44
|
-
onChange: onChange,
|
|
53
|
+
onChange: function onChange(_id, app) {
|
|
54
|
+
console.log('默认应用', app);
|
|
55
|
+
_onChange(app);
|
|
56
|
+
},
|
|
45
57
|
style: {
|
|
46
58
|
width: '200px'
|
|
47
59
|
}
|
package/es/demoWrapper/index.js
CHANGED
|
@@ -20,14 +20,18 @@ var DemoWrapper = function DemoWrapper(_ref) {
|
|
|
20
20
|
_useState2 = _slicedToArray(_useState, 2),
|
|
21
21
|
loading = _useState2[0],
|
|
22
22
|
setLoading = _useState2[1];
|
|
23
|
-
var _useState3 = useState(
|
|
23
|
+
var _useState3 = useState(true),
|
|
24
24
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var _useState5 = useState(
|
|
25
|
+
appListLoading = _useState4[0],
|
|
26
|
+
setAppListLoading = _useState4[1];
|
|
27
|
+
var _useState5 = useState(false),
|
|
28
28
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
notLogin = _useState6[0],
|
|
30
|
+
setNotLogin = _useState6[1];
|
|
31
|
+
var _useState7 = useState(),
|
|
32
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
33
|
+
app = _useState8[0],
|
|
34
|
+
setApp = _useState8[1];
|
|
31
35
|
useEffect(function () {
|
|
32
36
|
getCurrentUser();
|
|
33
37
|
}, []);
|
|
@@ -53,15 +57,19 @@ var DemoWrapper = function DemoWrapper(_ref) {
|
|
|
53
57
|
return /*#__PURE__*/React.createElement(Card, {
|
|
54
58
|
title: /*#__PURE__*/React.createElement(DemoHeader, {
|
|
55
59
|
defaultApp: defaultApp,
|
|
56
|
-
onChangeApp:
|
|
60
|
+
onChangeApp: setApp,
|
|
61
|
+
onLoading: setAppListLoading
|
|
57
62
|
}),
|
|
58
63
|
className: className,
|
|
59
64
|
bodyStyle: {
|
|
60
65
|
background: '#FAFAFB'
|
|
61
66
|
}
|
|
62
|
-
}, /*#__PURE__*/React.createElement(
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
}, appListLoading ? /*#__PURE__*/React.createElement(Spin, {
|
|
68
|
+
tip: "\u5E94\u7528\u4FE1\u606F\u521D\u59CB\u5316\u4E2D"
|
|
69
|
+
}) : /*#__PURE__*/React.createElement(DemoContent, {
|
|
70
|
+
currentApp: app,
|
|
71
|
+
needMeta: needMeta,
|
|
72
|
+
key: app === null || app === void 0 ? void 0 : app.appId
|
|
65
73
|
}, children));
|
|
66
74
|
};
|
|
67
75
|
export default DemoWrapper;
|
package/es/socket/demo/demo.js
CHANGED
|
@@ -1,51 +1,142 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
4
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
1
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
8
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
5
9
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
11
|
+
import React, { useContext, useEffect, useRef, useState } from 'react';
|
|
8
12
|
import { SocketClient } from '@zgfe/business-lib';
|
|
9
|
-
import { notification } from 'antd';
|
|
10
|
-
|
|
13
|
+
import { Button, Card, Form, Input, notification } from 'antd';
|
|
14
|
+
import styles from './index.less';
|
|
15
|
+
import { DemoWrapper, BizGlobalDataContext } from '@zgfe/business-lib';
|
|
16
|
+
var ChatPanel = function ChatPanel(_ref) {
|
|
17
|
+
var name = _ref.name,
|
|
18
|
+
param = _ref.param;
|
|
11
19
|
var _useState = useState(),
|
|
12
20
|
_useState2 = _slicedToArray(_useState, 2),
|
|
13
21
|
client = _useState2[0],
|
|
14
22
|
setClient = _useState2[1];
|
|
23
|
+
var _useState3 = useState([]),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
+
history = _useState4[0],
|
|
26
|
+
setHistory = _useState4[1];
|
|
27
|
+
var _useState5 = useState(true),
|
|
28
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
29
|
+
online = _useState6[0],
|
|
30
|
+
setOnline = _useState6[1];
|
|
31
|
+
var formRef = useRef();
|
|
32
|
+
var historyRef = useRef();
|
|
33
|
+
var _useContext = useContext(BizGlobalDataContext),
|
|
34
|
+
currentApp = _useContext.currentApp;
|
|
15
35
|
useEffect(function () {
|
|
16
|
-
setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws',
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
payload: {
|
|
24
|
-
unionid: 'hjadfhdskji884bdfd',
|
|
25
|
-
username: 'zhangsan'
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
36
|
+
setClient(new SocketClient('wss://rt2.zhugeio.com/eventtracking/ws', currentApp === null || currentApp === void 0 ? void 0 : currentApp.appKey, param));
|
|
37
|
+
return function () {
|
|
38
|
+
console.log('销毁chat', param);
|
|
39
|
+
if (!client) return;
|
|
40
|
+
client.destroy();
|
|
41
|
+
setClient(undefined);
|
|
42
|
+
};
|
|
28
43
|
}, []);
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
var _historyRef$current;
|
|
46
|
+
if (historyRef.current) historyRef.current.scrollTop = (_historyRef$current = historyRef.current) === null || _historyRef$current === void 0 ? void 0 : _historyRef$current.scrollHeight;
|
|
47
|
+
}, [history]);
|
|
29
48
|
useEffect(function () {
|
|
30
49
|
if (!client) return;
|
|
50
|
+
client.openLog(true);
|
|
31
51
|
client.onConnected(onConnected);
|
|
32
52
|
client.onError(onError);
|
|
53
|
+
client.on('offline', function () {
|
|
54
|
+
setHistory(function (list) {
|
|
55
|
+
return [].concat(_toConsumableArray(list), [{
|
|
56
|
+
type: 'he',
|
|
57
|
+
message: '对方已下线'
|
|
58
|
+
}]);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
client.on('exist', function () {
|
|
62
|
+
console.log('连接已存在');
|
|
63
|
+
});
|
|
64
|
+
client.on('message', function (message) {
|
|
65
|
+
setHistory(function (list) {
|
|
66
|
+
return [].concat(_toConsumableArray(list), [{
|
|
67
|
+
type: 'he',
|
|
68
|
+
message: message
|
|
69
|
+
}]);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
33
72
|
}, [client]);
|
|
34
73
|
function onConnected() {
|
|
35
74
|
notification.success({
|
|
36
75
|
message: '连接成功'
|
|
37
76
|
});
|
|
38
|
-
client.emit('init', {
|
|
39
|
-
msg: '这是初始化信息'
|
|
40
|
-
});
|
|
41
|
-
client.on('init', function (data) {
|
|
42
|
-
console.log('init response', data);
|
|
43
|
-
});
|
|
44
77
|
}
|
|
45
|
-
function onError() {
|
|
78
|
+
function onError(err) {
|
|
46
79
|
notification.error({
|
|
47
|
-
message: '连接失败'
|
|
80
|
+
message: '连接失败',
|
|
81
|
+
description: err.message
|
|
48
82
|
});
|
|
49
83
|
}
|
|
50
|
-
return /*#__PURE__*/React.createElement(
|
|
84
|
+
return /*#__PURE__*/React.createElement(Card, {
|
|
85
|
+
title: name
|
|
86
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
87
|
+
className: styles.history,
|
|
88
|
+
ref: historyRef
|
|
89
|
+
}, history.map(function (item, i) {
|
|
90
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
className: styles[item.type],
|
|
92
|
+
key: i
|
|
93
|
+
}, item.type, ": ", item.message);
|
|
94
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
className: styles.footer
|
|
96
|
+
}, /*#__PURE__*/React.createElement(Form, {
|
|
97
|
+
ref: formRef,
|
|
98
|
+
autoComplete: "off",
|
|
99
|
+
onFinish: function onFinish(_ref2) {
|
|
100
|
+
var _formRef$current;
|
|
101
|
+
var message = _ref2.message;
|
|
102
|
+
client.emit('message', message);
|
|
103
|
+
setHistory(function (list) {
|
|
104
|
+
return [].concat(_toConsumableArray(list), [{
|
|
105
|
+
type: 'me',
|
|
106
|
+
message: message
|
|
107
|
+
}]);
|
|
108
|
+
});
|
|
109
|
+
(_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.resetFields();
|
|
110
|
+
}
|
|
111
|
+
}, /*#__PURE__*/React.createElement(Form.Item, {
|
|
112
|
+
name: "message"
|
|
113
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
114
|
+
placeholder: "\u56DE\u8F66\u53D1\u9001\u4FE1\u606F",
|
|
115
|
+
autoFocus: true
|
|
116
|
+
})), /*#__PURE__*/React.createElement(Form.Item, null, /*#__PURE__*/React.createElement(Button, {
|
|
117
|
+
onClick: function onClick() {
|
|
118
|
+
if (online) {
|
|
119
|
+
client.close();
|
|
120
|
+
} else {
|
|
121
|
+
client.open();
|
|
122
|
+
}
|
|
123
|
+
setOnline(!online);
|
|
124
|
+
}
|
|
125
|
+
}, online ? '下线' : '上线')))));
|
|
126
|
+
};
|
|
127
|
+
export default (function () {
|
|
128
|
+
return /*#__PURE__*/React.createElement(DemoWrapper, null, /*#__PURE__*/React.createElement(BizGlobalDataContext.Consumer, null, function (_ref3) {
|
|
129
|
+
var currentApp = _ref3.currentApp;
|
|
130
|
+
console.log('当前应用', currentApp.id);
|
|
131
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
132
|
+
className: styles.container,
|
|
133
|
+
key: currentApp.id
|
|
134
|
+
}, /*#__PURE__*/React.createElement(ChatPanel, {
|
|
135
|
+
name: "\u5F20\u4E09",
|
|
136
|
+
param: {
|
|
137
|
+
appId: currentApp === null || currentApp === void 0 ? void 0 : currentApp.id,
|
|
138
|
+
origin: 3
|
|
139
|
+
}
|
|
140
|
+
}));
|
|
141
|
+
}));
|
|
51
142
|
});
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
@import '../../assets/styles/inner.less';
|
|
2
2
|
.container {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: row;
|
|
3
5
|
border: 1px solid red;
|
|
6
|
+
& > :global(.ant-card) {
|
|
7
|
+
flex: 1;
|
|
8
|
+
margin: @margin-md;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
.history {
|
|
12
|
+
height: 400px;
|
|
13
|
+
overflow: auto;
|
|
14
|
+
}
|
|
15
|
+
.he,
|
|
16
|
+
.me {
|
|
17
|
+
margin-bottom: @margin-sm;
|
|
18
|
+
padding: @padding-sm;
|
|
19
|
+
line-height: 24px;
|
|
20
|
+
background: @background-color-base;
|
|
21
|
+
}
|
|
22
|
+
.he {
|
|
23
|
+
text-align: left;
|
|
24
|
+
}
|
|
25
|
+
.me {
|
|
26
|
+
text-align: right;
|
|
4
27
|
}
|
package/es/socket/index.d.ts
CHANGED
|
@@ -5,9 +5,12 @@ declare class SocketClient {
|
|
|
5
5
|
private params?;
|
|
6
6
|
private listeners;
|
|
7
7
|
private catch;
|
|
8
|
-
|
|
8
|
+
private showLog;
|
|
9
|
+
private pingTimer?;
|
|
10
|
+
private appkey?;
|
|
11
|
+
constructor(url: string, appkey: string, params?: Record<string, any>);
|
|
9
12
|
emit(event: string, payload: SocketClientTypes.Message['data']['payload']): void;
|
|
10
|
-
on(type: string, handle: SocketClientTypes.Handler): void;
|
|
13
|
+
on(type: SocketClientTypes.EventType | string, handle: SocketClientTypes.Handler): void;
|
|
11
14
|
onConnected(handle: SocketClientTypes.Handler): void;
|
|
12
15
|
onDisconnected(handle: SocketClientTypes.Handler): void;
|
|
13
16
|
onError(handle: SocketClientTypes.Handler): void;
|
|
@@ -18,10 +21,11 @@ declare class SocketClient {
|
|
|
18
21
|
private ping;
|
|
19
22
|
removeAllListeners(): void;
|
|
20
23
|
removeListener(event: string, handle?: SocketClientTypes.Handler): void;
|
|
21
|
-
private
|
|
24
|
+
private getToken;
|
|
22
25
|
open(url?: string, params?: Record<string, any>): void;
|
|
23
26
|
close(): void;
|
|
24
27
|
destroy(): void;
|
|
25
28
|
private log;
|
|
29
|
+
openLog(open: boolean): void;
|
|
26
30
|
}
|
|
27
31
|
export default SocketClient;
|
package/es/socket/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
-
function
|
|
4
|
-
function
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
6
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -14,15 +14,22 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
|
|
|
14
14
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
15
15
|
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
16
|
import { notification } from 'antd';
|
|
17
|
+
import _ from 'lodash';
|
|
18
|
+
import request from 'umi-request';
|
|
19
|
+
import Apis from '../constants/apis';
|
|
17
20
|
import SocketClientTypes from './types';
|
|
18
21
|
var SocketClient = /*#__PURE__*/function () {
|
|
19
|
-
function SocketClient(url, params) {
|
|
22
|
+
function SocketClient(url, appkey, params) {
|
|
20
23
|
_classCallCheck(this, SocketClient);
|
|
21
24
|
this.client = void 0;
|
|
22
25
|
this.url = void 0;
|
|
23
26
|
this.params = void 0;
|
|
24
27
|
this.listeners = {};
|
|
25
28
|
this.catch = [];
|
|
29
|
+
this.showLog = false;
|
|
30
|
+
this.pingTimer = void 0;
|
|
31
|
+
this.appkey = void 0;
|
|
32
|
+
this.appkey = appkey;
|
|
26
33
|
this.url = url;
|
|
27
34
|
this.params = params;
|
|
28
35
|
this.open();
|
|
@@ -84,11 +91,11 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
84
91
|
}
|
|
85
92
|
}, {
|
|
86
93
|
key: "_onError",
|
|
87
|
-
value: function _onError(
|
|
94
|
+
value: function _onError(error) {
|
|
88
95
|
var _this$listeners$error;
|
|
89
|
-
this.log('error', 'socket连接异常');
|
|
96
|
+
this.log('error', 'socket连接异常', error);
|
|
90
97
|
(_this$listeners$error = this.listeners['error']) === null || _this$listeners$error === void 0 ? void 0 : _this$listeners$error.forEach(function (handle) {
|
|
91
|
-
handle.call(undefined);
|
|
98
|
+
handle.call(undefined, error);
|
|
92
99
|
});
|
|
93
100
|
}
|
|
94
101
|
}, {
|
|
@@ -99,6 +106,7 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
99
106
|
(_this$listeners$disco = this.listeners['disconnected']) === null || _this$listeners$disco === void 0 ? void 0 : _this$listeners$disco.forEach(function (handle) {
|
|
100
107
|
handle.call(undefined);
|
|
101
108
|
});
|
|
109
|
+
clearInterval(this.pingTimer);
|
|
102
110
|
}
|
|
103
111
|
}, {
|
|
104
112
|
key: "_onOpen",
|
|
@@ -106,7 +114,6 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
106
114
|
var _this$listeners$conne,
|
|
107
115
|
_this = this;
|
|
108
116
|
this.log('info', 'socket连接成功', event);
|
|
109
|
-
this.login();
|
|
110
117
|
(_this$listeners$conne = this.listeners['connected']) === null || _this$listeners$conne === void 0 ? void 0 : _this$listeners$conne.forEach(function (handle) {
|
|
111
118
|
handle.call(undefined);
|
|
112
119
|
});
|
|
@@ -122,26 +129,39 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
122
129
|
}, {
|
|
123
130
|
key: "onMessage",
|
|
124
131
|
value: function onMessage(event) {
|
|
132
|
+
var _this$listeners$Socke, _this$listeners$Socke2;
|
|
125
133
|
var res = JSON.parse(event.data);
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
if (res.code) {
|
|
135
|
+
switch (Number(res.code)) {
|
|
136
|
+
case SocketClientTypes.ResponseCode.offline:
|
|
137
|
+
(_this$listeners$Socke = this.listeners[SocketClientTypes.EventType.offline]) === null || _this$listeners$Socke === void 0 ? void 0 : _this$listeners$Socke.forEach(function (handle) {
|
|
138
|
+
handle.call(undefined, res);
|
|
139
|
+
});
|
|
140
|
+
break;
|
|
141
|
+
case SocketClientTypes.ResponseCode.exist:
|
|
142
|
+
(_this$listeners$Socke2 = this.listeners[SocketClientTypes.EventType.exist]) === null || _this$listeners$Socke2 === void 0 ? void 0 : _this$listeners$Socke2.forEach(function (handle) {
|
|
143
|
+
handle.call(undefined, res);
|
|
144
|
+
});
|
|
145
|
+
break;
|
|
146
|
+
case SocketClientTypes.ResponseCode.paramError:
|
|
147
|
+
this._onError(new Error('参数缺失或错误'));
|
|
148
|
+
}
|
|
149
|
+
} else if (res.type === SocketClientTypes.RequestType.pong) {
|
|
150
|
+
return;
|
|
151
|
+
} else {
|
|
152
|
+
var data = res.data;
|
|
153
|
+
if (this.listeners[data.event]) {
|
|
154
|
+
this.listeners[data.event].forEach(function (handle) {
|
|
155
|
+
handle.call(undefined, data.payload);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
138
158
|
}
|
|
139
159
|
}
|
|
140
160
|
}, {
|
|
141
161
|
key: "ping",
|
|
142
162
|
value: function ping() {
|
|
143
163
|
var _this2 = this;
|
|
144
|
-
setInterval(function () {
|
|
164
|
+
this.pingTimer = setInterval(function () {
|
|
145
165
|
var _this2$client;
|
|
146
166
|
(_this2$client = _this2.client) === null || _this2$client === void 0 ? void 0 : _this2$client.send(JSON.stringify({
|
|
147
167
|
type: SocketClientTypes.RequestType.ping
|
|
@@ -168,31 +188,67 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
168
188
|
}
|
|
169
189
|
}
|
|
170
190
|
}, {
|
|
171
|
-
key: "
|
|
172
|
-
value: function
|
|
173
|
-
var
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
191
|
+
key: "getToken",
|
|
192
|
+
value: function () {
|
|
193
|
+
var _getToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
194
|
+
var res;
|
|
195
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
196
|
+
while (1) switch (_context.prev = _context.next) {
|
|
197
|
+
case 0:
|
|
198
|
+
_context.next = 2;
|
|
199
|
+
return request(Apis.getSocketToken, {
|
|
200
|
+
method: 'get',
|
|
201
|
+
params: {
|
|
202
|
+
appKey: this.appkey
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
case 2:
|
|
206
|
+
res = _context.sent;
|
|
207
|
+
return _context.abrupt("return", res.data.socketToken);
|
|
208
|
+
case 4:
|
|
209
|
+
case "end":
|
|
210
|
+
return _context.stop();
|
|
211
|
+
}
|
|
212
|
+
}, _callee, this);
|
|
213
|
+
}));
|
|
214
|
+
function getToken() {
|
|
215
|
+
return _getToken.apply(this, arguments);
|
|
216
|
+
}
|
|
217
|
+
return getToken;
|
|
218
|
+
}()
|
|
179
219
|
}, {
|
|
180
220
|
key: "open",
|
|
181
221
|
value: function open(url, params) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
222
|
+
var _this4 = this;
|
|
223
|
+
this.getToken().then(function (token) {
|
|
224
|
+
_this4.params = params || _this4.params;
|
|
225
|
+
if (_this4.client) _this4.close();
|
|
226
|
+
var paramUrl = ["socketToken=".concat(token)];
|
|
227
|
+
if (_this4.params) {
|
|
228
|
+
Object.keys(_this4.params || {}).forEach(function (key) {
|
|
229
|
+
if (_.isObject(_this4.params[key]) || _.isArray(_this4.params[key])) {
|
|
230
|
+
paramUrl.push("".concat(key, "=").concat(JSON.stringify(_this4.params[key])));
|
|
231
|
+
} else {
|
|
232
|
+
paramUrl.push("".concat(key, "=").concat(_this4.params[key]));
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
var client = new WebSocket("".concat(url || _this4.url, "?").concat(paramUrl.join('&')));
|
|
237
|
+
_this4.client = client;
|
|
238
|
+
client.onmessage = _this4.onMessage.bind(_this4);
|
|
239
|
+
client.onerror = _this4._onError.bind(_this4);
|
|
240
|
+
client.onclose = _this4._onClose.bind(_this4);
|
|
241
|
+
client.onopen = _this4._onOpen.bind(_this4);
|
|
242
|
+
}).catch(function (err) {
|
|
243
|
+
_this4.log('error', 'socket获取token信息异常');
|
|
244
|
+
_this4._onError(err);
|
|
245
|
+
});
|
|
190
246
|
}
|
|
191
247
|
}, {
|
|
192
248
|
key: "close",
|
|
193
249
|
value: function close() {
|
|
194
|
-
var _this$
|
|
195
|
-
(_this$
|
|
250
|
+
var _this$client3;
|
|
251
|
+
(_this$client3 = this.client) === null || _this$client3 === void 0 ? void 0 : _this$client3.close();
|
|
196
252
|
this.log('info', '关闭socket连接');
|
|
197
253
|
}
|
|
198
254
|
}, {
|
|
@@ -209,7 +265,12 @@ var SocketClient = /*#__PURE__*/function () {
|
|
|
209
265
|
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
210
266
|
args[_key - 1] = arguments[_key];
|
|
211
267
|
}
|
|
212
|
-
(_console = console)
|
|
268
|
+
if (this.showLog) (_console = console).log.apply(_console, ["%c\u3010socketClient\u3011:".concat(type), "color: ".concat(type === 'error' ? 'red' : '#1890ff')].concat(args));
|
|
269
|
+
}
|
|
270
|
+
}, {
|
|
271
|
+
key: "openLog",
|
|
272
|
+
value: function openLog(open) {
|
|
273
|
+
this.showLog = open;
|
|
213
274
|
}
|
|
214
275
|
}]);
|
|
215
276
|
return SocketClient;
|
package/es/socket/types.d.ts
CHANGED
|
@@ -2,15 +2,22 @@ declare namespace SocketClientTypes {
|
|
|
2
2
|
enum EventType {
|
|
3
3
|
connected = "connected",
|
|
4
4
|
disconnected = "disconnected",
|
|
5
|
-
error = "error"
|
|
5
|
+
error = "error",
|
|
6
|
+
offline = "offline",
|
|
7
|
+
exist = "exist"
|
|
6
8
|
}
|
|
7
9
|
enum RequestType {
|
|
8
10
|
common = 0,
|
|
9
11
|
ping = 1,
|
|
10
|
-
|
|
12
|
+
pong = 2,
|
|
11
13
|
normal = 5,
|
|
12
14
|
img = 6
|
|
13
15
|
}
|
|
16
|
+
enum ResponseCode {
|
|
17
|
+
offline = 109001,
|
|
18
|
+
exist = 109002,
|
|
19
|
+
paramError = 109005
|
|
20
|
+
}
|
|
14
21
|
type Message = {
|
|
15
22
|
type: RequestType;
|
|
16
23
|
data: {
|
|
@@ -20,7 +27,10 @@ declare namespace SocketClientTypes {
|
|
|
20
27
|
};
|
|
21
28
|
interface ResponseData {
|
|
22
29
|
code: string;
|
|
23
|
-
data:
|
|
30
|
+
data: {
|
|
31
|
+
type: RequestType;
|
|
32
|
+
[prop: string]: any;
|
|
33
|
+
};
|
|
24
34
|
}
|
|
25
35
|
type Handler = (msg?: Message['data']['payload']) => void;
|
|
26
36
|
}
|
package/es/socket/types.js
CHANGED
|
@@ -5,14 +5,22 @@ var SocketClientTypes;
|
|
|
5
5
|
EventType["connected"] = "connected";
|
|
6
6
|
EventType["disconnected"] = "disconnected";
|
|
7
7
|
EventType["error"] = "error";
|
|
8
|
+
EventType["offline"] = "offline";
|
|
9
|
+
EventType["exist"] = "exist";
|
|
8
10
|
})(EventType = SocketClientTypes.EventType || (SocketClientTypes.EventType = {}));
|
|
9
11
|
var RequestType;
|
|
10
12
|
(function (RequestType) {
|
|
11
13
|
RequestType[RequestType["common"] = 0] = "common";
|
|
12
14
|
RequestType[RequestType["ping"] = 1] = "ping";
|
|
13
|
-
RequestType[RequestType["
|
|
15
|
+
RequestType[RequestType["pong"] = 2] = "pong";
|
|
14
16
|
RequestType[RequestType["normal"] = 5] = "normal";
|
|
15
17
|
RequestType[RequestType["img"] = 6] = "img";
|
|
16
18
|
})(RequestType = SocketClientTypes.RequestType || (SocketClientTypes.RequestType = {}));
|
|
19
|
+
var ResponseCode;
|
|
20
|
+
(function (ResponseCode) {
|
|
21
|
+
ResponseCode[ResponseCode["offline"] = 109001] = "offline";
|
|
22
|
+
ResponseCode[ResponseCode["exist"] = 109002] = "exist";
|
|
23
|
+
ResponseCode[ResponseCode["paramError"] = 109005] = "paramError";
|
|
24
|
+
})(ResponseCode = SocketClientTypes.ResponseCode || (SocketClientTypes.ResponseCode = {}));
|
|
17
25
|
})(SocketClientTypes || (SocketClientTypes = {}));
|
|
18
26
|
export default SocketClientTypes;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zgfe/business-lib",
|
|
3
|
-
"version": "1.1.29-visual.
|
|
3
|
+
"version": "1.1.29-visual.10",
|
|
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": "
|
|
62
|
+
"gitHead": "f352c2c2c369823c3bcf34002084c73321fb5a58"
|
|
63
63
|
}
|