zby-live-sdk 1.0.49-beta-talrtc0922 → 1.0.49-beta-talrtc1014

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.
Files changed (51) hide show
  1. package/.babelrc +5 -5
  2. package/.editorconfig +13 -13
  3. package/.eslintrc.js +29 -29
  4. package/CHANGELOG.md +381 -370
  5. package/README.md +276 -276
  6. package/dist/zby-live-sdk.cjs.js +4 -3
  7. package/dist/zby-live-sdk.esm.js +4 -3
  8. package/dist/zby-live-sdk.umd.js +4 -3
  9. package/package.json +1 -1
  10. package/src/channel/getSendMsgParams.js +66 -66
  11. package/src/channel/index.js +138 -138
  12. package/src/channel/pomelo/index.js +184 -184
  13. package/src/channel/pomelo/latestQueue.js +151 -151
  14. package/src/channel/pomelo/polemo.js +749 -749
  15. package/src/channel/pomelo/util.js +54 -54
  16. package/src/channel/sdk-cb.js +73 -73
  17. package/src/channel/stream-msg.js +97 -97
  18. package/src/channel/zby/index.js +74 -74
  19. package/src/channel/zby/interactWithChannel.js +4 -4
  20. package/src/channel/zby/interactWithChannelControl.js +1568 -1568
  21. package/src/channel/zby/interactWithChannelEntry.js +318 -318
  22. package/src/config/config.js +153 -153
  23. package/src/default/base.js +70 -70
  24. package/src/default/extend.js +36 -36
  25. package/src/default/index.js +9 -9
  26. package/src/live/base.js +42 -42
  27. package/src/live/call-method.js +9 -9
  28. package/src/live/extend.js +53 -53
  29. package/src/live/index.js +9 -9
  30. package/src/network/api.js +50 -50
  31. package/src/network/commonFetch.js +66 -66
  32. package/src/network/dataReport.js +429 -429
  33. package/src/notice.js +394 -394
  34. package/src/tool/base.js +74 -74
  35. package/src/tool/call-method.js +9 -9
  36. package/src/tool/extend.js +42 -42
  37. package/src/tool/index.js +9 -9
  38. package/src/util/bridge.js +87 -87
  39. package/src/util/bridge1.js +46 -46
  40. package/src/util/dict.js +51 -51
  41. package/src/util/sessionStorage.js +29 -29
  42. package/src/util/sha256.js +482 -482
  43. package/src/util/util.js +308 -308
  44. package/src/zby-av-sdk/agora-sdk.js +711 -711
  45. package/src/zby-av-sdk/device.js +145 -145
  46. package/src/zby-av-sdk/rtc-sdk.js +2839 -2839
  47. package/src/zby-av-sdk/talrtc-sdk.js +2392 -2348
  48. package/src/zby-av-sdk/trtc-sdk.js +1801 -1801
  49. package/src/zby-av-sdk/zby-av-sdk.js +1891 -1891
  50. package/src/zby-av-sdk/zego-sdk.js +2987 -2987
  51. package/src/zby-live-sdk.js +1561 -1557
@@ -1,184 +1,184 @@
1
- import pomeloClient from './polemo';
2
- import dealReceiveStreamMsg from '../stream-msg';
3
- import defaultApi from '../../default/extend';
4
- import util from '../../util/util';
5
- import polemoUtil from './util';
6
- import zbysdk from '../../zby-live-sdk';
7
- import dataReport from '../../network/dataReport';
8
- import {getApiCloudBaseUrl} from '../../config/config.js';
9
-
10
- let sendMsgCheckIntervalTimer = null;
11
- let sendMsgCheckIntervalTime = 3000;
12
-
13
- const pomeloObj = {
14
- isInRoom: false,
15
- sendMsgCacheList: {},
16
- sendMsgCheckList: {},
17
- sendMsgIndex: 0,
18
- initParams: null,
19
- async joinRoom(args, cb) {
20
- if (!args) {
21
- return;
22
- }
23
- this.log('channel_log : start joining pomelo ......');
24
- const { userId, roomId, chatUrl, userName, role, institutionId, guid} = args;
25
- const _args = { userId, roomId, host: chatUrl, userName, institutionId, guid, role: polemoUtil.translateRole(role) };
26
- this.log(`joinRoom: args: ${JSON.stringify(_args)}`);
27
- this.initParams = _args;
28
- // 定时检查发送消息列表
29
- // this.checkSendMsgList();
30
- const res = await pomeloClient.joinRoom({
31
- ..._args,
32
- roomId: util.getConfId(institutionId, roomId)
33
- }, dealCb);
34
- // 加入房间成功
35
- if (res.code === 200) {
36
- this.log('joinRoom success');
37
- this.isInRoom = true;
38
- await this.checkFailedAndCacheMSg();
39
- this.checkSendMsgList();
40
- } else {
41
- this.log('joinRoom failed');
42
- }
43
- try {
44
- dataReport.joinRoomResult({
45
- code: res.code === 200 ? '0' : '3',
46
- // cloud_api_response: JSON.stringify(window.zby_sdk_cloud_data),
47
- cloud_api_response: window.zby_sdk_cloud_data,
48
- cloud_api_url: `${getApiCloudBaseUrl()}/rtccloud/class/init`,
49
- chat_url: chatUrl
50
- });
51
- } catch (e) {};
52
- },
53
- // 离开房间重置所有变量
54
- leaveRoom() {
55
- this.log('leaveRoom');
56
- this.isInRoom = false;
57
- this.sendMsgCacheList = {};
58
- sendMsgCheckIntervalTimer = null;
59
- pomeloClient.disconnect();
60
- },
61
- async sendChannelMsg(data) {
62
- const currTime = new Date().getTime();
63
- // 记录缓存列表
64
- this.sendMsgIndex++;
65
- const { role, userId } = this.initParams;
66
- const params = {
67
- type: 'streamMessage',
68
- online_trace_id: `pc${util.firstUpperCase(role)}${util.uuid()}`,
69
- body: JSON.stringify({
70
- message: JSON.stringify(data),
71
- trace_id: `sdk_1.0_${(currTime).toString().padStart(16, '123456')}`,
72
- index: this.sendMsgIndex,
73
- save: '0',
74
- targetid: data.targetId,
75
- mtype: 'stream',
76
- uuid: `${userId}_2_${this.sendMsgIndex}_${currTime}`
77
- }),
78
- };
79
- if (this.isInRoom) {
80
- // 加入房间成功直接发送消息
81
- const res = await this.sendChannelMsgInner(params, data.target || '*');
82
- if (res.code !== 200) {
83
- this.sendMsgCheckList[params.online_trace_id] = params;
84
- }
85
- } else {
86
- // 为加入房间成功先缓存消息队列
87
- this.cacheSendChannelMsg(params, data.target);
88
- }
89
- },
90
- // 缓存消息队列
91
- cacheSendChannelMsg(data, target) {
92
- const len = Object.keys(this.sendMsgCacheList).length;
93
- // 大于100条不再缓存
94
- if (len > 100) {
95
- return;
96
- }
97
- this.sendMsgCacheList[data.online_trace_id] = {
98
- data,
99
- target
100
- };
101
- },
102
- // 发送消息
103
- sendChannelMsgInner(data, target = '*') {
104
- this.log(`sendChannelMsgInner: data: ${JSON.stringify(data)}, target: ${target}`);
105
- try {
106
- dataReport.pomeloSendMsg({api:data.body.api,data:{...data,body:JSON.parse(data.body)},target});
107
- } catch(e) {
108
- console.log('pomeloSendMsg_error',e);
109
- }
110
- return pomeloClient.sendChannelMessage(data, target);
111
- },
112
- // 遍历失败和缓存消息
113
- async checkFailedAndCacheMSg() {
114
- // 遍历失败消息
115
- const len = Object.keys(this.sendMsgCheckList).length;
116
- if (len > 0) {
117
- this.log(`checkSendMsgList-sendMsgCheckList :${JSON.stringify(this.sendMsgCheckList)}`);
118
- for(let index in this.sendMsgCheckList) {
119
- const msg = this.sendMsgCheckList[index];
120
- const res = await this.sendChannelMsgInner(msg.data, msg.target);
121
- if (res.code === 200) {
122
- delete this.sendMsgCheckList[index];
123
- }
124
- }
125
- }
126
- // 遍历缓存消息
127
- const len1 = Object.keys(this.sendMsgCacheList).length;
128
- if (len1 > 0) {
129
- this.log(`checkSendMsgList-sendMsgCacheList :${JSON.stringify(this.sendMsgCacheList)}`);
130
- for(let index in this.sendMsgCacheList) {
131
- const msg = this.sendMsgCacheList[index];
132
- const res = await this.sendChannelMsgInner(msg.data, msg.target);
133
- if (res.code === 200) {
134
- delete this.sendMsgCacheList[index];
135
- }
136
- }
137
- }
138
- },
139
-
140
- // 定时检查缓存队列
141
- async checkSendMsgList() {
142
- sendMsgCheckIntervalTimer = setInterval(async () => {
143
- if (!this.isInRoom) {
144
- return false;
145
- }
146
- this.checkFailedAndCacheMSg();
147
- }, sendMsgCheckIntervalTime);
148
- },
149
- log(msg) {
150
- defaultApi.writeLog(msg, 'channel-polemo');
151
- }
152
- };
153
-
154
- function dealCb(msg) {
155
- try {
156
- const body = JSON.parse(msg.body);
157
- // 收发消息
158
- if (msg.type === 'streamMessage') {
159
- const { roomId, userId, userName, institutionId, role } = pomeloObj.initParams;
160
- const baseInfo = { roomId, userId, userName, institutionId, role: polemoUtil.translateRole('', role), target: msg.from };
161
- const message = {...JSON.parse(body.message), ...body};
162
- dealReceiveStreamMsg(message, baseInfo);
163
- }
164
- // 切换sdk
165
- if (msg.type === 'streamsdk') {
166
- console.log(`%c接收到信道广播的切换SDK消息,切换到:${body.data}, 当前: ${window.current_sdk_type}`, 'color:blue');
167
- defaultApi.writeLog(`%c接收到信道广播的切换SDK消息,切换到:${body.data}, 当前: ${window.current_sdk_type}`);
168
- if (window.current_sdk_type !== body.data) {
169
- zbysdk.changeSDK();
170
- } else {
171
- console.log('%c接收到信道广播目标SDK和本地一致,不切换:' + body.data, 'color:blue');
172
- defaultApi.writeLog(`%c接收到信道广播目标SDK和本地一致,不切换到:${body.data}`);
173
- ENTRY.recordLogToFile('info', 'channel target sdk type is the same as the local sdk ,will not change sdk to :' + body.data);
174
- }
175
- }
176
- } catch (error) {
177
-
178
- }
179
- }
180
-
181
-
182
-
183
-
184
- export default pomeloObj;
1
+ import pomeloClient from './polemo';
2
+ import dealReceiveStreamMsg from '../stream-msg';
3
+ import defaultApi from '../../default/extend';
4
+ import util from '../../util/util';
5
+ import polemoUtil from './util';
6
+ import zbysdk from '../../zby-live-sdk';
7
+ import dataReport from '../../network/dataReport';
8
+ import {getApiCloudBaseUrl} from '../../config/config.js';
9
+
10
+ let sendMsgCheckIntervalTimer = null;
11
+ let sendMsgCheckIntervalTime = 3000;
12
+
13
+ const pomeloObj = {
14
+ isInRoom: false,
15
+ sendMsgCacheList: {},
16
+ sendMsgCheckList: {},
17
+ sendMsgIndex: 0,
18
+ initParams: null,
19
+ async joinRoom(args, cb) {
20
+ if (!args) {
21
+ return;
22
+ }
23
+ this.log('channel_log : start joining pomelo ......');
24
+ const { userId, roomId, chatUrl, userName, role, institutionId, guid} = args;
25
+ const _args = { userId, roomId, host: chatUrl, userName, institutionId, guid, role: polemoUtil.translateRole(role) };
26
+ this.log(`joinRoom: args: ${JSON.stringify(_args)}`);
27
+ this.initParams = _args;
28
+ // 定时检查发送消息列表
29
+ // this.checkSendMsgList();
30
+ const res = await pomeloClient.joinRoom({
31
+ ..._args,
32
+ roomId: util.getConfId(institutionId, roomId)
33
+ }, dealCb);
34
+ // 加入房间成功
35
+ if (res.code === 200) {
36
+ this.log('joinRoom success');
37
+ this.isInRoom = true;
38
+ await this.checkFailedAndCacheMSg();
39
+ this.checkSendMsgList();
40
+ } else {
41
+ this.log('joinRoom failed');
42
+ }
43
+ try {
44
+ dataReport.joinRoomResult({
45
+ code: res.code === 200 ? '0' : '3',
46
+ // cloud_api_response: JSON.stringify(window.zby_sdk_cloud_data),
47
+ cloud_api_response: window.zby_sdk_cloud_data,
48
+ cloud_api_url: `${getApiCloudBaseUrl()}/rtccloud/class/init`,
49
+ chat_url: chatUrl
50
+ });
51
+ } catch (e) {};
52
+ },
53
+ // 离开房间重置所有变量
54
+ leaveRoom() {
55
+ this.log('leaveRoom');
56
+ this.isInRoom = false;
57
+ this.sendMsgCacheList = {};
58
+ sendMsgCheckIntervalTimer = null;
59
+ pomeloClient.disconnect();
60
+ },
61
+ async sendChannelMsg(data) {
62
+ const currTime = new Date().getTime();
63
+ // 记录缓存列表
64
+ this.sendMsgIndex++;
65
+ const { role, userId } = this.initParams;
66
+ const params = {
67
+ type: 'streamMessage',
68
+ online_trace_id: `pc${util.firstUpperCase(role)}${util.uuid()}`,
69
+ body: JSON.stringify({
70
+ message: JSON.stringify(data),
71
+ trace_id: `sdk_1.0_${(currTime).toString().padStart(16, '123456')}`,
72
+ index: this.sendMsgIndex,
73
+ save: '0',
74
+ targetid: data.targetId,
75
+ mtype: 'stream',
76
+ uuid: `${userId}_2_${this.sendMsgIndex}_${currTime}`
77
+ }),
78
+ };
79
+ if (this.isInRoom) {
80
+ // 加入房间成功直接发送消息
81
+ const res = await this.sendChannelMsgInner(params, data.target || '*');
82
+ if (res.code !== 200) {
83
+ this.sendMsgCheckList[params.online_trace_id] = params;
84
+ }
85
+ } else {
86
+ // 为加入房间成功先缓存消息队列
87
+ this.cacheSendChannelMsg(params, data.target);
88
+ }
89
+ },
90
+ // 缓存消息队列
91
+ cacheSendChannelMsg(data, target) {
92
+ const len = Object.keys(this.sendMsgCacheList).length;
93
+ // 大于100条不再缓存
94
+ if (len > 100) {
95
+ return;
96
+ }
97
+ this.sendMsgCacheList[data.online_trace_id] = {
98
+ data,
99
+ target
100
+ };
101
+ },
102
+ // 发送消息
103
+ sendChannelMsgInner(data, target = '*') {
104
+ this.log(`sendChannelMsgInner: data: ${JSON.stringify(data)}, target: ${target}`);
105
+ try {
106
+ dataReport.pomeloSendMsg({api:data.body.api,data:{...data,body:JSON.parse(data.body)},target});
107
+ } catch(e) {
108
+ console.log('pomeloSendMsg_error',e);
109
+ }
110
+ return pomeloClient.sendChannelMessage(data, target);
111
+ },
112
+ // 遍历失败和缓存消息
113
+ async checkFailedAndCacheMSg() {
114
+ // 遍历失败消息
115
+ const len = Object.keys(this.sendMsgCheckList).length;
116
+ if (len > 0) {
117
+ this.log(`checkSendMsgList-sendMsgCheckList :${JSON.stringify(this.sendMsgCheckList)}`);
118
+ for(let index in this.sendMsgCheckList) {
119
+ const msg = this.sendMsgCheckList[index];
120
+ const res = await this.sendChannelMsgInner(msg.data, msg.target);
121
+ if (res.code === 200) {
122
+ delete this.sendMsgCheckList[index];
123
+ }
124
+ }
125
+ }
126
+ // 遍历缓存消息
127
+ const len1 = Object.keys(this.sendMsgCacheList).length;
128
+ if (len1 > 0) {
129
+ this.log(`checkSendMsgList-sendMsgCacheList :${JSON.stringify(this.sendMsgCacheList)}`);
130
+ for(let index in this.sendMsgCacheList) {
131
+ const msg = this.sendMsgCacheList[index];
132
+ const res = await this.sendChannelMsgInner(msg.data, msg.target);
133
+ if (res.code === 200) {
134
+ delete this.sendMsgCacheList[index];
135
+ }
136
+ }
137
+ }
138
+ },
139
+
140
+ // 定时检查缓存队列
141
+ async checkSendMsgList() {
142
+ sendMsgCheckIntervalTimer = setInterval(async () => {
143
+ if (!this.isInRoom) {
144
+ return false;
145
+ }
146
+ this.checkFailedAndCacheMSg();
147
+ }, sendMsgCheckIntervalTime);
148
+ },
149
+ log(msg) {
150
+ defaultApi.writeLog(msg, 'channel-polemo');
151
+ }
152
+ };
153
+
154
+ function dealCb(msg) {
155
+ try {
156
+ const body = JSON.parse(msg.body);
157
+ // 收发消息
158
+ if (msg.type === 'streamMessage') {
159
+ const { roomId, userId, userName, institutionId, role } = pomeloObj.initParams;
160
+ const baseInfo = { roomId, userId, userName, institutionId, role: polemoUtil.translateRole('', role), target: msg.from };
161
+ const message = {...JSON.parse(body.message), ...body};
162
+ dealReceiveStreamMsg(message, baseInfo);
163
+ }
164
+ // 切换sdk
165
+ if (msg.type === 'streamsdk') {
166
+ console.log(`%c接收到信道广播的切换SDK消息,切换到:${body.data}, 当前: ${window.current_sdk_type}`, 'color:blue');
167
+ defaultApi.writeLog(`%c接收到信道广播的切换SDK消息,切换到:${body.data}, 当前: ${window.current_sdk_type}`);
168
+ if (window.current_sdk_type !== body.data) {
169
+ zbysdk.changeSDK();
170
+ } else {
171
+ console.log('%c接收到信道广播目标SDK和本地一致,不切换:' + body.data, 'color:blue');
172
+ defaultApi.writeLog(`%c接收到信道广播目标SDK和本地一致,不切换到:${body.data}`);
173
+ ENTRY.recordLogToFile('info', 'channel target sdk type is the same as the local sdk ,will not change sdk to :' + body.data);
174
+ }
175
+ }
176
+ } catch (error) {
177
+
178
+ }
179
+ }
180
+
181
+
182
+
183
+
184
+ export default pomeloObj;
@@ -1,151 +1,151 @@
1
- function DoubleLinkList() {
2
- function DNode(data) {
3
- this.data = data;
4
- this.next = null;
5
- this.prev = null;
6
- }
7
-
8
- this.head = null;
9
- this.tail = null;
10
- this.length = 0;
11
-
12
- this.insert_head = function (data) {
13
- var temp_node = new DNode(data);
14
- if (this.head == null) {
15
- this.head = temp_node;
16
- this.tail = temp_node;
17
- } else {
18
- temp_node.next = this.head;
19
- this.head.prev = temp_node;
20
- this.head = temp_node;
21
- }
22
- this.length += 1;
23
-
24
- return temp_node;
25
- };
26
-
27
- this.insert_tail = function (data) {
28
- var node = new DNode(data);
29
- if (this.tail == null) {
30
- this.head = node;
31
- this.tail = node;
32
- } else {
33
- node.prev = this.tail;
34
- this.tail.next = node;
35
- this.tail = node;
36
- }
37
- this.length += 1;
38
-
39
- return node;
40
- };
41
-
42
- this.delete = function (node) {
43
- if (node.prev != null && node.next != null) {
44
- node.prev.next = node.next;
45
- node.next.prev = node.prev;
46
- } else if (node.prev != null) {
47
- this.tail = node.prev;
48
- this.tail.next = null;
49
-
50
- } else if (node.next != null) {
51
- this.head = node.next;
52
- this.head.prev = null;
53
- } else {
54
- this.head = null;
55
- this.tail = null;
56
- }
57
-
58
- this.length -= 1;
59
- };
60
-
61
- this.touch = function (node) {
62
- if (node.prev != null && node.next != null) {
63
- node.prev.next = node.next;
64
- node.next.prev = node.prev;
65
- } else if (node.prev != null) {
66
- this.tail = node.prev;
67
- this.tail.next = null;
68
- } else if (node.next != null) {
69
- this.head = node.next;
70
- this.head.prev = null;
71
- } else {
72
- this.head = null;
73
- this.tail = null;
74
- }
75
-
76
-
77
- node.prev = null;
78
- node.next = null;
79
- if (this.tail == null) {
80
- this.head = node;
81
- this.tail = node;
82
- } else {
83
- node.prev = this.tail;
84
- this.tail.next = node;
85
- this.tail = node;
86
- }
87
- };
88
-
89
- this.getLength = function () {
90
- return this.length;
91
- };
92
-
93
- this.getHead = function () {
94
- return this.head;
95
- };
96
-
97
- this.getTail = function () {
98
- return this.tail;
99
- };
100
- }
101
-
102
- export default function LatestQueue() {
103
- this.latestDList = new DoubleLinkList();
104
- this.latestDict = {};
105
-
106
- function LatestNode(msgId, timestamp) {
107
- this.msgId = msgId;
108
- this.timestamp = timestamp;
109
- }
110
-
111
- this.insert = function (msgId, timestamp) {
112
- if (this.latestDict[msgId]) {
113
- return;
114
- }
115
-
116
- const latestNode = new LatestNode(msgId, timestamp);
117
-
118
- this.latestDList.insert_tail(latestNode);
119
- this.latestDict[msgId] = latestNode;
120
- };
121
-
122
- this.isRepeat = function (msgId) {
123
- return !!this.latestDict[msgId];
124
- };
125
-
126
- this.delete = function (latestInterval, maxDeleteNum) {
127
- let tempDNode = this.latestDList.getHead();
128
- let currentDeleteNum = 0;
129
- let currentTimeStamp = Date.now();
130
- while (tempDNode != null) {
131
- if (currentTimeStamp - tempDNode.data.timestamp >= latestInterval) {
132
- delete this.latestDict[tempDNode.data.msgId];
133
- // console.log('我进来了,delete')
134
- this.latestDList.delete(tempDNode);
135
- currentDeleteNum += 1;
136
- }
137
-
138
- if (currentDeleteNum >= maxDeleteNum) {
139
- break;
140
- }
141
-
142
- tempDNode = tempDNode.next;
143
- }
144
-
145
- return currentDeleteNum;
146
- };
147
-
148
- this.getLength = function () {
149
- return this.latestDList.getLength();
150
- };
151
- }
1
+ function DoubleLinkList() {
2
+ function DNode(data) {
3
+ this.data = data;
4
+ this.next = null;
5
+ this.prev = null;
6
+ }
7
+
8
+ this.head = null;
9
+ this.tail = null;
10
+ this.length = 0;
11
+
12
+ this.insert_head = function (data) {
13
+ var temp_node = new DNode(data);
14
+ if (this.head == null) {
15
+ this.head = temp_node;
16
+ this.tail = temp_node;
17
+ } else {
18
+ temp_node.next = this.head;
19
+ this.head.prev = temp_node;
20
+ this.head = temp_node;
21
+ }
22
+ this.length += 1;
23
+
24
+ return temp_node;
25
+ };
26
+
27
+ this.insert_tail = function (data) {
28
+ var node = new DNode(data);
29
+ if (this.tail == null) {
30
+ this.head = node;
31
+ this.tail = node;
32
+ } else {
33
+ node.prev = this.tail;
34
+ this.tail.next = node;
35
+ this.tail = node;
36
+ }
37
+ this.length += 1;
38
+
39
+ return node;
40
+ };
41
+
42
+ this.delete = function (node) {
43
+ if (node.prev != null && node.next != null) {
44
+ node.prev.next = node.next;
45
+ node.next.prev = node.prev;
46
+ } else if (node.prev != null) {
47
+ this.tail = node.prev;
48
+ this.tail.next = null;
49
+
50
+ } else if (node.next != null) {
51
+ this.head = node.next;
52
+ this.head.prev = null;
53
+ } else {
54
+ this.head = null;
55
+ this.tail = null;
56
+ }
57
+
58
+ this.length -= 1;
59
+ };
60
+
61
+ this.touch = function (node) {
62
+ if (node.prev != null && node.next != null) {
63
+ node.prev.next = node.next;
64
+ node.next.prev = node.prev;
65
+ } else if (node.prev != null) {
66
+ this.tail = node.prev;
67
+ this.tail.next = null;
68
+ } else if (node.next != null) {
69
+ this.head = node.next;
70
+ this.head.prev = null;
71
+ } else {
72
+ this.head = null;
73
+ this.tail = null;
74
+ }
75
+
76
+
77
+ node.prev = null;
78
+ node.next = null;
79
+ if (this.tail == null) {
80
+ this.head = node;
81
+ this.tail = node;
82
+ } else {
83
+ node.prev = this.tail;
84
+ this.tail.next = node;
85
+ this.tail = node;
86
+ }
87
+ };
88
+
89
+ this.getLength = function () {
90
+ return this.length;
91
+ };
92
+
93
+ this.getHead = function () {
94
+ return this.head;
95
+ };
96
+
97
+ this.getTail = function () {
98
+ return this.tail;
99
+ };
100
+ }
101
+
102
+ export default function LatestQueue() {
103
+ this.latestDList = new DoubleLinkList();
104
+ this.latestDict = {};
105
+
106
+ function LatestNode(msgId, timestamp) {
107
+ this.msgId = msgId;
108
+ this.timestamp = timestamp;
109
+ }
110
+
111
+ this.insert = function (msgId, timestamp) {
112
+ if (this.latestDict[msgId]) {
113
+ return;
114
+ }
115
+
116
+ const latestNode = new LatestNode(msgId, timestamp);
117
+
118
+ this.latestDList.insert_tail(latestNode);
119
+ this.latestDict[msgId] = latestNode;
120
+ };
121
+
122
+ this.isRepeat = function (msgId) {
123
+ return !!this.latestDict[msgId];
124
+ };
125
+
126
+ this.delete = function (latestInterval, maxDeleteNum) {
127
+ let tempDNode = this.latestDList.getHead();
128
+ let currentDeleteNum = 0;
129
+ let currentTimeStamp = Date.now();
130
+ while (tempDNode != null) {
131
+ if (currentTimeStamp - tempDNode.data.timestamp >= latestInterval) {
132
+ delete this.latestDict[tempDNode.data.msgId];
133
+ // console.log('我进来了,delete')
134
+ this.latestDList.delete(tempDNode);
135
+ currentDeleteNum += 1;
136
+ }
137
+
138
+ if (currentDeleteNum >= maxDeleteNum) {
139
+ break;
140
+ }
141
+
142
+ tempDNode = tempDNode.next;
143
+ }
144
+
145
+ return currentDeleteNum;
146
+ };
147
+
148
+ this.getLength = function () {
149
+ return this.latestDList.getLength();
150
+ };
151
+ }