Repository navigation
Expand file tree
/
Copy pathutils.js
More file actions
110 lines (105 loc) · 3.44 KB
/
Copy pathutils.js
File metadata and controls
110 lines (105 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* 初始化订阅状态
* @param {String} userId
*/
function initialization(userId) {
if (aliWebrtc) {
aliWebrtc.configRemoteAudio(userId, false);
aliWebrtc.configRemoteCameraTrack(userId, false, false);
aliWebrtc.configRemoteScreenTrack(userId, false);
}
}
/**
* 分析远端用户信息
* @param {String} userId
*/
function getSubscribeInfo(userId) {
var userInfo = aliWebrtc.getUserInfo(userId);
var subscribeInfo = [], subscribeInfoArr = [], isSubAudio = false, isSubLarge = false, isSubSmall = false, isSubCamera = false, isSubScreen = false, isSubVideo = false;
if (userInfo) {
userInfo.streamConfigs.forEach(v => {
if (v.subscribed) {
subscribeInfo.push(v.label);
subscribeInfoArr.push(v);
v.type == "audio" ? isSubAudio = true : "";
v.type == "video" ? isSubVideo = true : "";
v.label == "sophon_video_camera_large" ? isSubLarge = true : "";
v.label == "sophon_video_camera_small" ? isSubSmall = true : "";
v.label == "sophon_video_screen_share" ? isSubScreen = true : "";
if (isSubLarge || isSubSmall) {
isSubCamera = true;
}
}
});
}
return { subscribeInfo: subscribeInfo, subscribeInfoArr: subscribeInfoArr, isSubLarge: isSubLarge, isSubSmall: isSubSmall, isSubCamera: isSubCamera, isSubAudio: isSubAudio, isSubScreen: isSubScreen, isSubVideo: isSubVideo };
}
/**
* 取消订阅设置
* @param {String} userId
* @param {String} type
* @param {String} label
*/
function setConfigRemote(userId, type, label){
return new Promise((resolve, reject) => {
if (type == "audio") {
aliWebrtc.configRemoteAudio(userId, false);
} else {
if (label === "sophon_video_camera_large") {
aliWebrtc.configRemoteCameraTrack(userId, false, false);
console.warn("取消相机流");
} else if (label === "sophon_video_screen_share") {
console.warn("取消共享流");
aliWebrtc.configRemoteScreenTrack(userId, false);
}
}
aliWebrtc.subscribe(userId).then(re => {
resolve();
}).catch(err => { console.log("重新订阅失败", err); alert(err.message); })
});
}
/**
* 显示提示信息,并打印
* @param {String} text 要显示的信息
* @param {String} type 信息类型(默认成功)
* @param {Number} delay 延迟时间(默认2.5s)
*/
function showAlert(text,type,delay) {
if(!text) return;
var _type = type ? "alert-" + type : "alert-success"
var _delay = delay || 2500
$(".alert").html(text).addClass(_type).show().delay(_delay).fadeOut("normal",() => {$(".alert").removeClass(_type)});
if(_type === "warning"){
console.warn(text)
}else if(_type === "danger"){
console.log(text)
}else {
console.log(text)
}
}
/**
* 根据属性值获取在数组中的index
*/
Array.prototype.getIndexByProprety = function (val, proprety) {
var arr = this;
var index = -1;
arr.forEach((v, i, a) => {
if (v[proprety] == val) {
index = i;
}
});
return index;
}
/**
* 根据属性值获取数组中的某项
*/
Array.prototype.getObjByProprety = function (val, proprety) {
var arr = this;
var obj = {};
arr.forEach((v, i, a) => {
if (v[proprety] === val) {
obj = v;
}
});
return obj;
}