funs.js
4.41 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* 根据item id 编写对应的前端检测方法
*/
(function(global) {
function testWebSocket(ip,port,cb){
//ws://192.168.7.201:7070/ws/ 如果是https下 wss wss://192.168.7.201:7070/ws/
var url = '';
var hostname ="";
if(port=='7443'){
hostname = "wss";
}else{
hostname = "ws";
}
url = hostname+'://'+ip+':'+port+'/ws/';
var ws = new WebSocket(url,'xmpp');
ws.onerror = function () {
cb(false);
};
ws.onopen = function () {
cb(true);
};
}
function IEVersion() {
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
if(isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
reIE.test(userAgent);
var fIEVersion = parseFloat(RegExp["$1"]);
if(fIEVersion == 7) {
return 7;
} else if(fIEVersion == 8) {
return 8;
} else if(fIEVersion == 9) {
return 9;
} else if(fIEVersion == 10) {
return 10;
} else {
return 6;//IE版本<=7
}
} else if(isEdge) {
return 'edge';//edge
} else if(isIE11) {
return 11; //IE11
}else{
return -1;//不是ie浏览器
}
}
function execCallback(fun, result, resolution) {
if(result === "" && resolution === "") {
result === i18n.t("detect_pass");
}
if (typeof fun === 'function') {
fun(result, resolution);
}
}
function parseURL(url, proto) {
if (url.indexOf('://') === -1) {
url = proto + '://' + url;
}
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
query: a.search,
params: (function(){
var ret = {},
seg = a.search.replace(/^\?/,'').split('&'),
len = seg.length, i = 0, s; //len = 2
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^\/])/,'/$1'),
relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
segments: a.pathname.replace(/^\//,'').split('/')
};
}
function getMappingHost() {
var hostInfo = {
host: "",
port: ""
}
if (!sysinfo.ipConfig) {
return hostInfo;
}
for (var key in sysinfo.ipConfig) {
if(key.indexOf(window.location.hostname) >= 0) {
hostInfo.host = sysinfo.ipConfig[key]
break;
}
}
var parsed = parseURL(hostInfo.host, 'ws');
hostInfo.host = parsed.host;
hostInfo.port = parsed.port;
return hostInfo;
}
var ClientFuns = {
// pc连接消息服务的端口检测
1: function (row, callback) {
var targetHost, targetPort;
var hostInfo = getMappingHost();
targetHost = hostInfo.host || sysinfo.openfireEmessageClientUrl;
targetPort = hostInfo.port || sysinfo.openfireHttpbindPort;
testWebSocket(targetHost, targetPort, function(pass) {
var result = "", resolution = "";
if(pass) {
result = i18n.t("detect_pass");
}else {
result = i18n.t("pcConnectServerError");
resolution = i18n.t("pcConnectServerError_detail0") + targetHost+ i18n.t("pcConnectServerError_detail1") +targetPort+ i18n.t("pcConnectServerError_detail2") +"<a href='https://yq.weaver.com.cn/eb/qa/view/#/question/71401bb39e2f4ae8b5cff979abe263c3' target='_blank'>"+ i18n.t("pcConnectServerError_detail3") +"</a>"
}
execCallback(callback, result, resolution);
});
},
// web端加载检测
8: function(row, callback) {
var versionNO = IEVersion();
var result = "", resolution = "";
if(versionNO > 0 && versionNO < 10){
result = i18n.t("currentBrowserNotSupport");
resolution = i18n.t("iegt9");
}
execCallback(callback, result, resolution);
}
}
global.ClientFuns = ClientFuns
global.ApiUrl = "/social/detect/interface/detect.jsp?m="
global.testWebSocket = testWebSocket
})(window)