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.
- package/.babelrc +5 -5
- package/.editorconfig +13 -13
- package/.eslintrc.js +29 -29
- package/CHANGELOG.md +381 -370
- package/README.md +276 -276
- package/dist/zby-live-sdk.cjs.js +4 -3
- package/dist/zby-live-sdk.esm.js +4 -3
- package/dist/zby-live-sdk.umd.js +4 -3
- package/package.json +1 -1
- package/src/channel/getSendMsgParams.js +66 -66
- package/src/channel/index.js +138 -138
- package/src/channel/pomelo/index.js +184 -184
- package/src/channel/pomelo/latestQueue.js +151 -151
- package/src/channel/pomelo/polemo.js +749 -749
- package/src/channel/pomelo/util.js +54 -54
- package/src/channel/sdk-cb.js +73 -73
- package/src/channel/stream-msg.js +97 -97
- package/src/channel/zby/index.js +74 -74
- package/src/channel/zby/interactWithChannel.js +4 -4
- package/src/channel/zby/interactWithChannelControl.js +1568 -1568
- package/src/channel/zby/interactWithChannelEntry.js +318 -318
- package/src/config/config.js +153 -153
- package/src/default/base.js +70 -70
- package/src/default/extend.js +36 -36
- package/src/default/index.js +9 -9
- package/src/live/base.js +42 -42
- package/src/live/call-method.js +9 -9
- package/src/live/extend.js +53 -53
- package/src/live/index.js +9 -9
- package/src/network/api.js +50 -50
- package/src/network/commonFetch.js +66 -66
- package/src/network/dataReport.js +429 -429
- package/src/notice.js +394 -394
- package/src/tool/base.js +74 -74
- package/src/tool/call-method.js +9 -9
- package/src/tool/extend.js +42 -42
- package/src/tool/index.js +9 -9
- package/src/util/bridge.js +87 -87
- package/src/util/bridge1.js +46 -46
- package/src/util/dict.js +51 -51
- package/src/util/sessionStorage.js +29 -29
- package/src/util/sha256.js +482 -482
- package/src/util/util.js +308 -308
- package/src/zby-av-sdk/agora-sdk.js +711 -711
- package/src/zby-av-sdk/device.js +145 -145
- package/src/zby-av-sdk/rtc-sdk.js +2839 -2839
- package/src/zby-av-sdk/talrtc-sdk.js +2392 -2348
- package/src/zby-av-sdk/trtc-sdk.js +1801 -1801
- package/src/zby-av-sdk/zby-av-sdk.js +1891 -1891
- package/src/zby-av-sdk/zego-sdk.js +2987 -2987
- package/src/zby-live-sdk.js +1561 -1557
package/src/util/util.js
CHANGED
|
@@ -1,308 +1,308 @@
|
|
|
1
|
-
import MD5 from 'md5';
|
|
2
|
-
import sha256 from './sha256.js';
|
|
3
|
-
import { getNetworkTimestampApi } from '../network/api';
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
// timestamp : 0,
|
|
7
|
-
// diffTime : 0,
|
|
8
|
-
/**
|
|
9
|
-
* run the callback unitl checkFlag return true
|
|
10
|
-
* @param {function | boolean} checkFlag
|
|
11
|
-
* @param {function} callback
|
|
12
|
-
* @param {*} param
|
|
13
|
-
*/
|
|
14
|
-
waitFlagToRun(checkFlag, callback, param, options, count=1) {
|
|
15
|
-
/**
|
|
16
|
-
* options
|
|
17
|
-
* { repeatTimes : 重试次数限制
|
|
18
|
-
* interval : 间隔时间,默认 100ms
|
|
19
|
-
* }
|
|
20
|
-
* */
|
|
21
|
-
if(options && options.repeatTimes && (count > options.repeatTimes)) return;
|
|
22
|
-
if (checkFlag()) {
|
|
23
|
-
callback(param);
|
|
24
|
-
return;
|
|
25
|
-
} else {
|
|
26
|
-
const interval = options && options.timer ? options.timer : 100;
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
this.waitFlagToRun(checkFlag, callback, param, options, count+1);
|
|
29
|
-
}, interval);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* query字符串参数排序
|
|
35
|
-
* */
|
|
36
|
-
queryStringSort(param) {
|
|
37
|
-
return param.split('&').sort().join('&');
|
|
38
|
-
},
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 生成签名相关
|
|
42
|
-
*/
|
|
43
|
-
getVerifySign(param, saultKey='7qIdL2kdYQzecQJplq8QXfzpolOgUGOM') {
|
|
44
|
-
//按照api要求,进行混合saultKey二次MD5处理
|
|
45
|
-
if(typeof param == 'string') {
|
|
46
|
-
return MD5( MD5(this.queryStringSort(param) + saultKey));
|
|
47
|
-
} else if (typeof param == 'object') {
|
|
48
|
-
let arr = [];
|
|
49
|
-
for (var key in param) {
|
|
50
|
-
arr.push((key + '=' + param[key]));
|
|
51
|
-
}
|
|
52
|
-
let sortedQueryString = this.queryStringSort(arr.join('&'));
|
|
53
|
-
return MD5( MD5(sortedQueryString) + saultKey);
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
//根据值反查字典表中的键名
|
|
58
|
-
getMapKeyByValue(map, value) {
|
|
59
|
-
for (let item of map) {
|
|
60
|
-
if (map.get(item[0]) === value) {
|
|
61
|
-
return item[0];
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
uuid() {
|
|
66
|
-
var s = [];
|
|
67
|
-
var hexDigits = '0123456789abcdef';
|
|
68
|
-
for (var i = 0; i < 36; i++) {
|
|
69
|
-
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
70
|
-
}
|
|
71
|
-
s[14] = '4';
|
|
72
|
-
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
|
|
73
|
-
s[8] = s[13] = s[18] = s[23] = '-';
|
|
74
|
-
|
|
75
|
-
var uuid = s.join('');
|
|
76
|
-
return uuid;
|
|
77
|
-
},
|
|
78
|
-
getVerifySign1() {
|
|
79
|
-
const appId = '1002';
|
|
80
|
-
const key = 'OmAIqyYz0U1/guuFo4GH6nVGNVFeHAczwpsuXzMqKdw=';
|
|
81
|
-
const timestamp = new Date().getTime();
|
|
82
|
-
const RDM = this.uuid();
|
|
83
|
-
return {
|
|
84
|
-
appId,
|
|
85
|
-
RDM,
|
|
86
|
-
timestamp,
|
|
87
|
-
Authorization: sha256.hmacsha256(key, `${appId}&${timestamp}&${RDM}`)
|
|
88
|
-
};
|
|
89
|
-
},
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @param {String} idType id类型: userId, roomId, orgId
|
|
93
|
-
* @param {Strig} streamUrl 流地址id
|
|
94
|
-
*/
|
|
95
|
-
getDataFromStreamUrl(idType, streamUrl){
|
|
96
|
-
// streamUrl 格式
|
|
97
|
-
// '_orgId_roomId_userId_1'
|
|
98
|
-
//倒序
|
|
99
|
-
const obj = {
|
|
100
|
-
userId: 1,
|
|
101
|
-
roomId: 2,
|
|
102
|
-
orgId : 3,
|
|
103
|
-
};
|
|
104
|
-
if(!streamUrl){
|
|
105
|
-
return;
|
|
106
|
-
}else{
|
|
107
|
-
return streamUrl.split('_').reverse()[obj[idType]];
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
// getCurrentExtensionVersions(ext_id){
|
|
111
|
-
// if(EM){
|
|
112
|
-
// EM.GetExtensionVersions('zego_ext',
|
|
113
|
-
// function(ec, content) {
|
|
114
|
-
// console.log('GetExtensionVersions EC:' + ec + '\nContent:' + content);
|
|
115
|
-
// });
|
|
116
|
-
// }
|
|
117
|
-
// }
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//转换一下用户角色的定义 用户角色 '1=teacher'/'2=student'/'3=assistant'/'4=parent'
|
|
121
|
-
translateRole(roleString) {
|
|
122
|
-
if (typeof roleString == 'string') {
|
|
123
|
-
if (roleString == 'teacher') {
|
|
124
|
-
return '1';
|
|
125
|
-
} else if (roleString == 'student') {
|
|
126
|
-
return '2';
|
|
127
|
-
} else if (roleString == 'assistant') {
|
|
128
|
-
return '3';
|
|
129
|
-
} else if (roleString == 'parent') {
|
|
130
|
-
return '4';
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
return roleString;
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
//转换一下用户角色的定义 用户角色 '1=teacher'/'2=student'/'3=assistant'/'4=parent'
|
|
137
|
-
translateRoleBack: function (roleNumber) {
|
|
138
|
-
if (typeof roleNumber == 'string') {
|
|
139
|
-
if (roleNumber == '1') {
|
|
140
|
-
return 'teacher';
|
|
141
|
-
} else if (roleNumber == '2') {
|
|
142
|
-
return 'student';
|
|
143
|
-
} else if (roleNumber == '3') {
|
|
144
|
-
return 'assistant';
|
|
145
|
-
} else if (roleNumber == '4') {
|
|
146
|
-
return 'parent';
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return '';
|
|
150
|
-
},
|
|
151
|
-
throttle: function(fn, delay) {
|
|
152
|
-
var context = null,
|
|
153
|
-
timer = null,
|
|
154
|
-
args = null;
|
|
155
|
-
return function() {
|
|
156
|
-
context = this;
|
|
157
|
-
args = arguments;
|
|
158
|
-
if (timer) return;
|
|
159
|
-
timer = setTimeout(function() {
|
|
160
|
-
clearTimeout(timer);
|
|
161
|
-
timer = null;
|
|
162
|
-
fn.apply(context, args);
|
|
163
|
-
}, delay);
|
|
164
|
-
};
|
|
165
|
-
},
|
|
166
|
-
// 格式化当前时间
|
|
167
|
-
currentTimeString() {
|
|
168
|
-
const date = new Date();
|
|
169
|
-
let fmt = 'yyyy-MM-dd hh:mm:ss:S';
|
|
170
|
-
const o = {
|
|
171
|
-
'M+' : date.getMonth()+1, //月份
|
|
172
|
-
'd+' : date.getDate(), //日
|
|
173
|
-
'h+' : date.getHours(), //小时
|
|
174
|
-
'm+' : date.getMinutes(), //分
|
|
175
|
-
's+' : date.getSeconds(), //秒
|
|
176
|
-
'q+' : Math.floor((date.getMonth()+3)/3), //季度
|
|
177
|
-
'S' : date.getMilliseconds() //毫秒
|
|
178
|
-
};
|
|
179
|
-
if(/(y+)/.test(fmt));
|
|
180
|
-
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+'').substr(4 - RegExp.$1.length));
|
|
181
|
-
for(let k in o) {
|
|
182
|
-
if(new RegExp('('+ k +')').test(fmt));
|
|
183
|
-
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (('00'+ o[k]).substr((''+ o[k]).length)));
|
|
184
|
-
}
|
|
185
|
-
return fmt;
|
|
186
|
-
},
|
|
187
|
-
//notice返回端上想要的uid
|
|
188
|
-
getUidByStreamId(streamId) {
|
|
189
|
-
if (streamId.split('_').length == 5) {
|
|
190
|
-
return streamId;
|
|
191
|
-
};
|
|
192
|
-
if (streamId && streamId.indexOf('_') > 0) {
|
|
193
|
-
return streamId.split('_')[2];
|
|
194
|
-
} else {
|
|
195
|
-
return streamId;
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
//数据上报返回真正的uid
|
|
199
|
-
getUidByStreamIdDr(streamId) {
|
|
200
|
-
if (streamId && streamId.indexOf('_') > 0) {
|
|
201
|
-
return streamId.split('_')[2];
|
|
202
|
-
} else {
|
|
203
|
-
return streamId;
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
toFixed(num, bit = 2) {
|
|
207
|
-
let backNum;
|
|
208
|
-
try {
|
|
209
|
-
backNum = parseFloat(num).toFixed(bit);
|
|
210
|
-
} catch (error) {
|
|
211
|
-
backNum = num;
|
|
212
|
-
}
|
|
213
|
-
return backNum;
|
|
214
|
-
},
|
|
215
|
-
getStreamId(args) {
|
|
216
|
-
const {institutionId, roomId, userId, groupId} = args;
|
|
217
|
-
return `${institutionId}_${groupId || roomId}_${userId}_1`;
|
|
218
|
-
},
|
|
219
|
-
getConfId(institutionId, roomId) {
|
|
220
|
-
return `${roomId}_${institutionId}`;
|
|
221
|
-
},
|
|
222
|
-
/**
|
|
223
|
-
* 深拷贝
|
|
224
|
-
* @param {*} obj 拷贝对象(object or array)
|
|
225
|
-
* @param {*} cache 缓存数组
|
|
226
|
-
*/
|
|
227
|
-
deepCopy(obj, cache = []) {
|
|
228
|
-
// typeof [] => 'object'
|
|
229
|
-
// typeof {} => 'object'
|
|
230
|
-
if (obj === null || typeof obj !== 'object') {
|
|
231
|
-
return obj;
|
|
232
|
-
}
|
|
233
|
-
// 如果传入的对象与缓存的相等, 则递归结束, 这样防止循环
|
|
234
|
-
/**
|
|
235
|
-
* 类似下面这种
|
|
236
|
-
* var a = {b:1}
|
|
237
|
-
* a.c = a
|
|
238
|
-
* 资料: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
239
|
-
*/
|
|
240
|
-
const hit = cache.filter(c => c.original === obj)[0];
|
|
241
|
-
if (hit) {
|
|
242
|
-
return hit.copy;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const copy = Array.isArray(obj) ? [] : {};
|
|
246
|
-
// 将copy首先放入cache, 因为我们需要在递归deepCopy的时候引用它
|
|
247
|
-
cache.push({
|
|
248
|
-
original: obj,
|
|
249
|
-
copy
|
|
250
|
-
});
|
|
251
|
-
Object.keys(obj).forEach(key => {
|
|
252
|
-
copy[key] = deepCopy(obj[key], cache);
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
return copy;
|
|
256
|
-
},
|
|
257
|
-
firstUpperCase(key) {
|
|
258
|
-
if (!key) {
|
|
259
|
-
return key;
|
|
260
|
-
}
|
|
261
|
-
return key.charAt(0).toUpperCase() + key.slice(1);
|
|
262
|
-
},
|
|
263
|
-
getChromeVersion() {
|
|
264
|
-
let chromeVersion = navigator.userAgent;
|
|
265
|
-
console.log('chromeVersion',chromeVersion);
|
|
266
|
-
let res = chromeVersion.search(/Chrome\/68/);
|
|
267
|
-
// res == -1 ;//非68版本要升级
|
|
268
|
-
let isUpdateChromeVersion = res < 0 ? true : false;
|
|
269
|
-
return isUpdateChromeVersion;
|
|
270
|
-
},
|
|
271
|
-
// 获取网络时间戳
|
|
272
|
-
// async getNetworkTimeStamp() {
|
|
273
|
-
// let res;
|
|
274
|
-
// try {
|
|
275
|
-
// res = await getNetworkTimestampApi();
|
|
276
|
-
// } catch (e){
|
|
277
|
-
// console.log('getNetworkTimeStamp1',e);
|
|
278
|
-
// }
|
|
279
|
-
// const res1 = new Date().getTime();
|
|
280
|
-
// // let timestamp = 0;
|
|
281
|
-
// if (res && res.data.t) {
|
|
282
|
-
// this.timestamp = +res.data.t;
|
|
283
|
-
// this.diffTime = this.timestamp - res1;
|
|
284
|
-
// console.log('getNetworkTimeStamp10');
|
|
285
|
-
// } else {
|
|
286
|
-
// this.timestamp = new Date().getTime();
|
|
287
|
-
// this.diffTime = 0;
|
|
288
|
-
// console.log('getNetworkTimeStamp11');
|
|
289
|
-
// // const res1 = await getNetworkTimestampApi('suning');
|
|
290
|
-
// // if (res1.status === 200) {
|
|
291
|
-
// // timestamp = +res1.data.sysTime1 * 1000;
|
|
292
|
-
// // }
|
|
293
|
-
// }
|
|
294
|
-
// console.log('getNetworkTimeStamp2',this.timestamp,res1,this.diffTime);
|
|
295
|
-
// // await this.getDiffTime();
|
|
296
|
-
// // return this.timestamp;
|
|
297
|
-
// },
|
|
298
|
-
//防抖
|
|
299
|
-
// debounce(fn,wait){
|
|
300
|
-
// var timer = null;
|
|
301
|
-
// return function(){
|
|
302
|
-
// if(timer !== null){
|
|
303
|
-
// clearTimeout(timer);
|
|
304
|
-
// }
|
|
305
|
-
// timer = setTimeout(fn,wait);
|
|
306
|
-
// }
|
|
307
|
-
// }
|
|
308
|
-
};
|
|
1
|
+
import MD5 from 'md5';
|
|
2
|
+
import sha256 from './sha256.js';
|
|
3
|
+
import { getNetworkTimestampApi } from '../network/api';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
// timestamp : 0,
|
|
7
|
+
// diffTime : 0,
|
|
8
|
+
/**
|
|
9
|
+
* run the callback unitl checkFlag return true
|
|
10
|
+
* @param {function | boolean} checkFlag
|
|
11
|
+
* @param {function} callback
|
|
12
|
+
* @param {*} param
|
|
13
|
+
*/
|
|
14
|
+
waitFlagToRun(checkFlag, callback, param, options, count=1) {
|
|
15
|
+
/**
|
|
16
|
+
* options
|
|
17
|
+
* { repeatTimes : 重试次数限制
|
|
18
|
+
* interval : 间隔时间,默认 100ms
|
|
19
|
+
* }
|
|
20
|
+
* */
|
|
21
|
+
if(options && options.repeatTimes && (count > options.repeatTimes)) return;
|
|
22
|
+
if (checkFlag()) {
|
|
23
|
+
callback(param);
|
|
24
|
+
return;
|
|
25
|
+
} else {
|
|
26
|
+
const interval = options && options.timer ? options.timer : 100;
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
this.waitFlagToRun(checkFlag, callback, param, options, count+1);
|
|
29
|
+
}, interval);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* query字符串参数排序
|
|
35
|
+
* */
|
|
36
|
+
queryStringSort(param) {
|
|
37
|
+
return param.split('&').sort().join('&');
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 生成签名相关
|
|
42
|
+
*/
|
|
43
|
+
getVerifySign(param, saultKey='7qIdL2kdYQzecQJplq8QXfzpolOgUGOM') {
|
|
44
|
+
//按照api要求,进行混合saultKey二次MD5处理
|
|
45
|
+
if(typeof param == 'string') {
|
|
46
|
+
return MD5( MD5(this.queryStringSort(param) + saultKey));
|
|
47
|
+
} else if (typeof param == 'object') {
|
|
48
|
+
let arr = [];
|
|
49
|
+
for (var key in param) {
|
|
50
|
+
arr.push((key + '=' + param[key]));
|
|
51
|
+
}
|
|
52
|
+
let sortedQueryString = this.queryStringSort(arr.join('&'));
|
|
53
|
+
return MD5( MD5(sortedQueryString) + saultKey);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
//根据值反查字典表中的键名
|
|
58
|
+
getMapKeyByValue(map, value) {
|
|
59
|
+
for (let item of map) {
|
|
60
|
+
if (map.get(item[0]) === value) {
|
|
61
|
+
return item[0];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
uuid() {
|
|
66
|
+
var s = [];
|
|
67
|
+
var hexDigits = '0123456789abcdef';
|
|
68
|
+
for (var i = 0; i < 36; i++) {
|
|
69
|
+
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
|
|
70
|
+
}
|
|
71
|
+
s[14] = '4';
|
|
72
|
+
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
|
|
73
|
+
s[8] = s[13] = s[18] = s[23] = '-';
|
|
74
|
+
|
|
75
|
+
var uuid = s.join('');
|
|
76
|
+
return uuid;
|
|
77
|
+
},
|
|
78
|
+
getVerifySign1() {
|
|
79
|
+
const appId = '1002';
|
|
80
|
+
const key = 'OmAIqyYz0U1/guuFo4GH6nVGNVFeHAczwpsuXzMqKdw=';
|
|
81
|
+
const timestamp = new Date().getTime();
|
|
82
|
+
const RDM = this.uuid();
|
|
83
|
+
return {
|
|
84
|
+
appId,
|
|
85
|
+
RDM,
|
|
86
|
+
timestamp,
|
|
87
|
+
Authorization: sha256.hmacsha256(key, `${appId}&${timestamp}&${RDM}`)
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
/**
|
|
91
|
+
*
|
|
92
|
+
* @param {String} idType id类型: userId, roomId, orgId
|
|
93
|
+
* @param {Strig} streamUrl 流地址id
|
|
94
|
+
*/
|
|
95
|
+
getDataFromStreamUrl(idType, streamUrl){
|
|
96
|
+
// streamUrl 格式
|
|
97
|
+
// '_orgId_roomId_userId_1'
|
|
98
|
+
//倒序
|
|
99
|
+
const obj = {
|
|
100
|
+
userId: 1,
|
|
101
|
+
roomId: 2,
|
|
102
|
+
orgId : 3,
|
|
103
|
+
};
|
|
104
|
+
if(!streamUrl){
|
|
105
|
+
return;
|
|
106
|
+
}else{
|
|
107
|
+
return streamUrl.split('_').reverse()[obj[idType]];
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// getCurrentExtensionVersions(ext_id){
|
|
111
|
+
// if(EM){
|
|
112
|
+
// EM.GetExtensionVersions('zego_ext',
|
|
113
|
+
// function(ec, content) {
|
|
114
|
+
// console.log('GetExtensionVersions EC:' + ec + '\nContent:' + content);
|
|
115
|
+
// });
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
//转换一下用户角色的定义 用户角色 '1=teacher'/'2=student'/'3=assistant'/'4=parent'
|
|
121
|
+
translateRole(roleString) {
|
|
122
|
+
if (typeof roleString == 'string') {
|
|
123
|
+
if (roleString == 'teacher') {
|
|
124
|
+
return '1';
|
|
125
|
+
} else if (roleString == 'student') {
|
|
126
|
+
return '2';
|
|
127
|
+
} else if (roleString == 'assistant') {
|
|
128
|
+
return '3';
|
|
129
|
+
} else if (roleString == 'parent') {
|
|
130
|
+
return '4';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return roleString;
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
//转换一下用户角色的定义 用户角色 '1=teacher'/'2=student'/'3=assistant'/'4=parent'
|
|
137
|
+
translateRoleBack: function (roleNumber) {
|
|
138
|
+
if (typeof roleNumber == 'string') {
|
|
139
|
+
if (roleNumber == '1') {
|
|
140
|
+
return 'teacher';
|
|
141
|
+
} else if (roleNumber == '2') {
|
|
142
|
+
return 'student';
|
|
143
|
+
} else if (roleNumber == '3') {
|
|
144
|
+
return 'assistant';
|
|
145
|
+
} else if (roleNumber == '4') {
|
|
146
|
+
return 'parent';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return '';
|
|
150
|
+
},
|
|
151
|
+
throttle: function(fn, delay) {
|
|
152
|
+
var context = null,
|
|
153
|
+
timer = null,
|
|
154
|
+
args = null;
|
|
155
|
+
return function() {
|
|
156
|
+
context = this;
|
|
157
|
+
args = arguments;
|
|
158
|
+
if (timer) return;
|
|
159
|
+
timer = setTimeout(function() {
|
|
160
|
+
clearTimeout(timer);
|
|
161
|
+
timer = null;
|
|
162
|
+
fn.apply(context, args);
|
|
163
|
+
}, delay);
|
|
164
|
+
};
|
|
165
|
+
},
|
|
166
|
+
// 格式化当前时间
|
|
167
|
+
currentTimeString() {
|
|
168
|
+
const date = new Date();
|
|
169
|
+
let fmt = 'yyyy-MM-dd hh:mm:ss:S';
|
|
170
|
+
const o = {
|
|
171
|
+
'M+' : date.getMonth()+1, //月份
|
|
172
|
+
'd+' : date.getDate(), //日
|
|
173
|
+
'h+' : date.getHours(), //小时
|
|
174
|
+
'm+' : date.getMinutes(), //分
|
|
175
|
+
's+' : date.getSeconds(), //秒
|
|
176
|
+
'q+' : Math.floor((date.getMonth()+3)/3), //季度
|
|
177
|
+
'S' : date.getMilliseconds() //毫秒
|
|
178
|
+
};
|
|
179
|
+
if(/(y+)/.test(fmt));
|
|
180
|
+
fmt=fmt.replace(RegExp.$1, (date.getFullYear()+'').substr(4 - RegExp.$1.length));
|
|
181
|
+
for(let k in o) {
|
|
182
|
+
if(new RegExp('('+ k +')').test(fmt));
|
|
183
|
+
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (('00'+ o[k]).substr((''+ o[k]).length)));
|
|
184
|
+
}
|
|
185
|
+
return fmt;
|
|
186
|
+
},
|
|
187
|
+
//notice返回端上想要的uid
|
|
188
|
+
getUidByStreamId(streamId) {
|
|
189
|
+
if (streamId.split('_').length == 5) {
|
|
190
|
+
return streamId;
|
|
191
|
+
};
|
|
192
|
+
if (streamId && streamId.indexOf('_') > 0) {
|
|
193
|
+
return streamId.split('_')[2];
|
|
194
|
+
} else {
|
|
195
|
+
return streamId;
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
//数据上报返回真正的uid
|
|
199
|
+
getUidByStreamIdDr(streamId) {
|
|
200
|
+
if (streamId && streamId.indexOf('_') > 0) {
|
|
201
|
+
return streamId.split('_')[2];
|
|
202
|
+
} else {
|
|
203
|
+
return streamId;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
toFixed(num, bit = 2) {
|
|
207
|
+
let backNum;
|
|
208
|
+
try {
|
|
209
|
+
backNum = parseFloat(num).toFixed(bit);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
backNum = num;
|
|
212
|
+
}
|
|
213
|
+
return backNum;
|
|
214
|
+
},
|
|
215
|
+
getStreamId(args) {
|
|
216
|
+
const {institutionId, roomId, userId, groupId} = args;
|
|
217
|
+
return `${institutionId}_${groupId || roomId}_${userId}_1`;
|
|
218
|
+
},
|
|
219
|
+
getConfId(institutionId, roomId) {
|
|
220
|
+
return `${roomId}_${institutionId}`;
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* 深拷贝
|
|
224
|
+
* @param {*} obj 拷贝对象(object or array)
|
|
225
|
+
* @param {*} cache 缓存数组
|
|
226
|
+
*/
|
|
227
|
+
deepCopy(obj, cache = []) {
|
|
228
|
+
// typeof [] => 'object'
|
|
229
|
+
// typeof {} => 'object'
|
|
230
|
+
if (obj === null || typeof obj !== 'object') {
|
|
231
|
+
return obj;
|
|
232
|
+
}
|
|
233
|
+
// 如果传入的对象与缓存的相等, 则递归结束, 这样防止循环
|
|
234
|
+
/**
|
|
235
|
+
* 类似下面这种
|
|
236
|
+
* var a = {b:1}
|
|
237
|
+
* a.c = a
|
|
238
|
+
* 资料: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value
|
|
239
|
+
*/
|
|
240
|
+
const hit = cache.filter(c => c.original === obj)[0];
|
|
241
|
+
if (hit) {
|
|
242
|
+
return hit.copy;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const copy = Array.isArray(obj) ? [] : {};
|
|
246
|
+
// 将copy首先放入cache, 因为我们需要在递归deepCopy的时候引用它
|
|
247
|
+
cache.push({
|
|
248
|
+
original: obj,
|
|
249
|
+
copy
|
|
250
|
+
});
|
|
251
|
+
Object.keys(obj).forEach(key => {
|
|
252
|
+
copy[key] = deepCopy(obj[key], cache);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return copy;
|
|
256
|
+
},
|
|
257
|
+
firstUpperCase(key) {
|
|
258
|
+
if (!key) {
|
|
259
|
+
return key;
|
|
260
|
+
}
|
|
261
|
+
return key.charAt(0).toUpperCase() + key.slice(1);
|
|
262
|
+
},
|
|
263
|
+
getChromeVersion() {
|
|
264
|
+
let chromeVersion = navigator.userAgent;
|
|
265
|
+
console.log('chromeVersion',chromeVersion);
|
|
266
|
+
let res = chromeVersion.search(/Chrome\/68/);
|
|
267
|
+
// res == -1 ;//非68版本要升级
|
|
268
|
+
let isUpdateChromeVersion = res < 0 ? true : false;
|
|
269
|
+
return isUpdateChromeVersion;
|
|
270
|
+
},
|
|
271
|
+
// 获取网络时间戳
|
|
272
|
+
// async getNetworkTimeStamp() {
|
|
273
|
+
// let res;
|
|
274
|
+
// try {
|
|
275
|
+
// res = await getNetworkTimestampApi();
|
|
276
|
+
// } catch (e){
|
|
277
|
+
// console.log('getNetworkTimeStamp1',e);
|
|
278
|
+
// }
|
|
279
|
+
// const res1 = new Date().getTime();
|
|
280
|
+
// // let timestamp = 0;
|
|
281
|
+
// if (res && res.data.t) {
|
|
282
|
+
// this.timestamp = +res.data.t;
|
|
283
|
+
// this.diffTime = this.timestamp - res1;
|
|
284
|
+
// console.log('getNetworkTimeStamp10');
|
|
285
|
+
// } else {
|
|
286
|
+
// this.timestamp = new Date().getTime();
|
|
287
|
+
// this.diffTime = 0;
|
|
288
|
+
// console.log('getNetworkTimeStamp11');
|
|
289
|
+
// // const res1 = await getNetworkTimestampApi('suning');
|
|
290
|
+
// // if (res1.status === 200) {
|
|
291
|
+
// // timestamp = +res1.data.sysTime1 * 1000;
|
|
292
|
+
// // }
|
|
293
|
+
// }
|
|
294
|
+
// console.log('getNetworkTimeStamp2',this.timestamp,res1,this.diffTime);
|
|
295
|
+
// // await this.getDiffTime();
|
|
296
|
+
// // return this.timestamp;
|
|
297
|
+
// },
|
|
298
|
+
//防抖
|
|
299
|
+
// debounce(fn,wait){
|
|
300
|
+
// var timer = null;
|
|
301
|
+
// return function(){
|
|
302
|
+
// if(timer !== null){
|
|
303
|
+
// clearTimeout(timer);
|
|
304
|
+
// }
|
|
305
|
+
// timer = setTimeout(fn,wait);
|
|
306
|
+
// }
|
|
307
|
+
// }
|
|
308
|
+
};
|