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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function (global, factory) {
|
2 |
+
|
3 |
+
"use strict";
|
4 |
+
|
5 |
+
if (typeof module === "object" && typeof module.exports === "object") {
|
6 |
+
module.exports = factory(global, true);
|
7 |
+
} else {
|
8 |
+
if (typeof define === 'function' && define.amd) {
|
9 |
+
define(factory);
|
10 |
+
} else {
|
11 |
+
factory(global);
|
12 |
+
}
|
13 |
+
}
|
14 |
+
|
15 |
+
})(typeof window !== "undefined" ? window : this, function (window, noGlobal) {
|
16 |
+
|
17 |
+
"use strict";
|
18 |
+
|
19 |
+
/**
|
20 |
+
* http状态码,对应的返回信息,由于websocket不存在状态码,暂时由前端对返回信息进行匹配
|
21 |
+
错误码:406 错误信息:Failed to send message to WPS
|
22 |
+
错误码:406 错误信息:Json parse failed
|
23 |
+
错误码:406 错误信息:Product not found
|
24 |
+
错误码:406 错误信息:Failed
|
25 |
+
错误码:403 错误信息:Forbidden
|
26 |
+
错误码:503 错误信息:Service Unavailable
|
27 |
+
错误码:417 错误信息:WPSInnerMessage_InvalidBusinessId
|
28 |
+
*/
|
29 |
+
var httpCodeErrorMessageList = [
|
30 |
+
'Failed to send message to WPS',
|
31 |
+
'Json parse failed',
|
32 |
+
'Product not found',
|
33 |
+
'Failed',
|
34 |
+
'Forbidden',
|
35 |
+
'Service Unavailable',
|
36 |
+
'WPSInnerMessage_InvalidBusinessId'
|
37 |
+
]
|
38 |
+
|
39 |
+
var bFinished = true;
|
40 |
+
|
41 |
+
var serverVersion = 'wait';
|
42 |
+
var wpsinvokeNetType='wait';
|
43 |
+
|
44 |
+
if(sessionStorage.getItem('wpsinvokeNetType')) {
|
45 |
+
wpsinvokeNetType = sessionStorage.getItem('wpsinvokeNetType');
|
46 |
+
};
|
47 |
+
|
48 |
+
if(sessionStorage.getItem('serverVersion')) {
|
49 |
+
serverVersion = sessionStorage.getItem('serverVersion');
|
50 |
+
};
|
51 |
+
|
52 |
+
function isReplaceWebSocket() {
|
53 |
+
if( wpsinvokeNetType === 'websocket' ) {
|
54 |
+
return true;
|
55 |
+
} else {
|
56 |
+
return false;
|
57 |
+
};
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* ws、http互相替换链接
|
62 |
+
* @param {*} url 请求链接
|
63 |
+
* @returns
|
64 |
+
*/
|
65 |
+
function transferWebsocketToHttp(url) {
|
66 |
+
return url.replace('ws://','http://').replace(':58892',':58890');
|
67 |
+
}
|
68 |
+
|
69 |
+
function transferHttpToWebsocket(url) {
|
70 |
+
return url.replace('http://','ws://').replace(':58890',':58892');
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* 获取网页路径前缀
|
75 |
+
* @returns url前缀
|
76 |
+
*/
|
77 |
+
function GetUrlBase() {
|
78 |
+
if(isReplaceWebSocket()){
|
79 |
+
if (location.protocol == "https:")
|
80 |
+
return 'wss://127.0.0.1:58893'
|
81 |
+
return 'ws://127.0.0.1:58892'
|
82 |
+
}
|
83 |
+
return getHttpUrl();
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* 获取http链接
|
88 |
+
*/
|
89 |
+
function getHttpUrl (){
|
90 |
+
if (location.protocol == "https:")
|
91 |
+
return "https://127.0.0.1:58891"
|
92 |
+
return "http://127.0.0.1:58890"
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* 兼容IE低版本Array没有indexOf方法的场景
|
97 |
+
*/
|
98 |
+
if (!Array.prototype.indexOf) {
|
99 |
+
Array.prototype.indexOf = function (elt /*, from*/) {
|
100 |
+
var len = this.length >>> 0;
|
101 |
+
|
102 |
+
var from = Number(arguments[1]) || 0;
|
103 |
+
from = (from < 0)
|
104 |
+
? Math.ceil(from)
|
105 |
+
: Math.floor(from);
|
106 |
+
if (from < 0)
|
107 |
+
from += len;
|
108 |
+
|
109 |
+
for (; from < len; from++) {
|
110 |
+
if (from in this &&
|
111 |
+
this[from] === elt)
|
112 |
+
return from;
|
113 |
+
}
|
114 |
+
return -1;
|
115 |
+
};
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* 判断是否函数
|
120 |
+
*/
|
121 |
+
function isFunction(func) {
|
122 |
+
return typeof func === 'function';
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* websocket对象
|
127 |
+
*/
|
128 |
+
function getWebsocketObj(){
|
129 |
+
this.onopen = null;
|
130 |
+
this.onmessage = null;
|
131 |
+
this.onclose = null;
|
132 |
+
this.onerror = null;
|
133 |
+
this.wsInstance = null;
|
134 |
+
}
|
135 |
+
|
136 |
+
getWebsocketObj.prototype.connect = function(url) {
|
137 |
+
var that = this;
|
138 |
+
var ws = that.wsInstance = new WebSocket(url);
|
139 |
+
ws.onopen = function(res) {
|
140 |
+
if(isFunction(that.onopen)) {
|
141 |
+
that.onopen(res);
|
142 |
+
}
|
143 |
+
}
|
144 |
+
|
145 |
+
ws.onmessage = function(res) {
|
146 |
+
if(isFunction(that.onmessage)) {
|
147 |
+
that.onmessage(res);
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
ws.onclose = function(res) {
|
152 |
+
if(isFunction(that.onclose)) {
|
153 |
+
that.onclose(res);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
ws.onerror = function(res) {
|
158 |
+
if(isFunction(that.onerror)) {
|
159 |
+
that.onerror(res);
|
160 |
+
}
|
161 |
+
}
|
162 |
+
}
|
163 |
+
|
164 |
+
getWebsocketObj.prototype.send = function(data) {
|
165 |
+
if(this.wsInstance) {
|
166 |
+
this.wsInstance.send(data)
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
getWebsocketObj.prototype.close = function() {
|
171 |
+
if(this.wsInstance) {
|
172 |
+
this.wsInstance.close()
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
|
177 |
+
/**
|
178 |
+
* 兼容IE低版本的创建httpobj对象的方法
|
179 |
+
* @returns httpobj,可用于进行数据传输的http的对象
|
180 |
+
*/
|
181 |
+
function getHttpObj() {
|
182 |
+
var httpobj = null;
|
183 |
+
if (IEVersion() < 10) {
|
184 |
+
try {
|
185 |
+
httpobj = new XDomainRequest();
|
186 |
+
} catch (e1) {
|
187 |
+
httpobj = new createXHR();
|
188 |
+
}
|
189 |
+
} else {
|
190 |
+
httpobj = new createXHR();
|
191 |
+
}
|
192 |
+
return httpobj;
|
193 |
+
}
|
194 |
+
//兼容IE低版本的创建xmlhttprequest对象的方法
|
195 |
+
/**
|
196 |
+
* 兼容IE低版本的创建xmlhttprequest对象的方法
|
197 |
+
* @returns xmlhttprequest对象,兼容低版本IE
|
198 |
+
*/
|
199 |
+
function createXHR() {
|
200 |
+
if (typeof XMLHttpRequest != 'undefined') { //兼容高版本浏览器
|
201 |
+
return new XMLHttpRequest();
|
202 |
+
} else if (typeof ActiveXObject != 'undefined') { //IE6 采用 ActiveXObject, 兼容IE6
|
203 |
+
var versions = [ //由于MSXML库有3个版本,因此都要考虑
|
204 |
+
'MSXML2.XMLHttp.6.0',
|
205 |
+
'MSXML2.XMLHttp.3.0',
|
206 |
+
'MSXML2.XMLHttp'
|
207 |
+
];
|
208 |
+
|
209 |
+
for (var i = 0; i < versions.length; i++) {
|
210 |
+
try {
|
211 |
+
return new ActiveXObject(versions[i]);
|
212 |
+
} catch (e) {
|
213 |
+
//跳过
|
214 |
+
}
|
215 |
+
}
|
216 |
+
} else {
|
217 |
+
throw new Error('您的浏览器不支持XHR对象');
|
218 |
+
}
|
219 |
+
}
|
220 |
+
|
221 |
+
/**
|
222 |
+
* 加载项本地服务返回的错误信息,统一为data : message的json格式
|
223 |
+
* 如果有新增错误信息,添加到下面
|
224 |
+
* 也可以通过请求状态码返回错误信息
|
225 |
+
*/
|
226 |
+
var errorMsg = [
|
227 |
+
"{\"data\": \"Failed to send message to WPS.\"}",
|
228 |
+
"{\"data\": \"Json parse failed.\"}",
|
229 |
+
"{\"error\": \"Json parse failed.\"}"
|
230 |
+
]
|
231 |
+
/**
|
232 |
+
* 通过该接口给服务器发请求
|
233 |
+
* @param {*} options 参数对象,具体包含的参数如下:
|
234 |
+
* @param {*} url 网页路径,传输地址
|
235 |
+
* @param {*} type 传输类型,POST / GET / PUT
|
236 |
+
* @param {*} sendData 传输的数据
|
237 |
+
* @param {*} callBack 回调函数
|
238 |
+
* @param {*} tryCount 请求失败后的尝试次数
|
239 |
+
* @param {*} bPop 是否弹出浏览器提示对话框
|
240 |
+
* @param {*} timeout 请求等待响应的时间,超过时间请求实效
|
241 |
+
* @param {*} concurrent 请求是否同步发送
|
242 |
+
* @param {*} wpsclient wpsclient对象
|
243 |
+
* @returns NULL
|
244 |
+
*/
|
245 |
+
function startWps(options) {
|
246 |
+
if (!bFinished && !options.concurrent) {
|
247 |
+
if (options.callBack)
|
248 |
+
options.callBack({
|
249 |
+
status: 1,
|
250 |
+
message: "上一次请求没有完成"
|
251 |
+
});
|
252 |
+
return;
|
253 |
+
}
|
254 |
+
if (!options.concurrent)
|
255 |
+
bFinished = false;
|
256 |
+
else
|
257 |
+
options.bFinished = false;
|
258 |
+
|
259 |
+
function startWpsInnder(tryCount) {
|
260 |
+
if (tryCount <= 0) {
|
261 |
+
// http失败重试时,会唤醒云服务,当重试次数清0时,向云服务发起一次ws请求确认是否是浏览器安全问题
|
262 |
+
if(serverVersion === 'wait' && wpsinvokeNetType === 'wait') {
|
263 |
+
options.url = transferHttpToWebsocket(options.url);
|
264 |
+
startWpsInnderWebsocket(1);
|
265 |
+
return
|
266 |
+
};
|
267 |
+
if (!options.concurrent) {
|
268 |
+
if (bFinished)
|
269 |
+
return;
|
270 |
+
bFinished = true;
|
271 |
+
} else {
|
272 |
+
if (options.bFinished) {
|
273 |
+
return;
|
274 |
+
}
|
275 |
+
options.bFinished = true;
|
276 |
+
}
|
277 |
+
if (options.callBack)
|
278 |
+
options.callBack({
|
279 |
+
status: 2,
|
280 |
+
message: "请允许浏览器打开WPS Office"
|
281 |
+
});
|
282 |
+
return;
|
283 |
+
}
|
284 |
+
var xmlReq = getHttpObj();
|
285 |
+
//WPS客户端提供的接收参数的本地服务,HTTP服务端口为58890,HTTPS服务端口为58891
|
286 |
+
//这俩配置,取一即可,不可同时启用
|
287 |
+
xmlReq.open('POST', options.url);
|
288 |
+
xmlReq.onload = function (res) {
|
289 |
+
wpsinvokeNetType="http"
|
290 |
+
sessionStorage.setItem("wpsinvokeNetType",wpsinvokeNetType);
|
291 |
+
var responseStr = IEVersion() < 10 ? xmlReq.responseText : res.target.response;
|
292 |
+
var respStatus = IEVersion() < 10 ? xmlReq.status : res.target.status;
|
293 |
+
if (!options.concurrent)
|
294 |
+
bFinished = true;
|
295 |
+
else
|
296 |
+
options.bFinished = true;
|
297 |
+
if (options.callBack) {
|
298 |
+
if ((respStatus != undefined && respStatus != 200) || errorMsg.indexOf(responseStr) != -1) {
|
299 |
+
var errorMessage = JSON.parse(responseStr)
|
300 |
+
options.callBack({
|
301 |
+
status: 1,
|
302 |
+
message: errorMessage.data
|
303 |
+
});
|
304 |
+
if (errorMessage.data == "Subserver not available." && tryCount == options.tryCount && options.bPop) {
|
305 |
+
InitWpsCloudSvr();
|
306 |
+
setTimeout(function () {
|
307 |
+
startWpsInnder(tryCount - 1)
|
308 |
+
}, 3000);
|
309 |
+
}
|
310 |
+
}
|
311 |
+
else {
|
312 |
+
options.callBack({
|
313 |
+
status: 0,
|
314 |
+
response: responseStr
|
315 |
+
});
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
xmlReq.ontimeout = xmlReq.onerror = function (res) {
|
320 |
+
xmlReq.bTimeout = true;
|
321 |
+
if (tryCount == options.tryCount && options.bPop&&wpsinvokeNetType=="wait") { //打开wps并传参
|
322 |
+
InitWpsCloudSvr();
|
323 |
+
}
|
324 |
+
setTimeout(function () {
|
325 |
+
startWpsInnder(tryCount - 1)
|
326 |
+
}, 1000);
|
327 |
+
}
|
328 |
+
if (IEVersion() < 10) {
|
329 |
+
xmlReq.onreadystatechange = function () {
|
330 |
+
if (xmlReq.readyState != 4)
|
331 |
+
return;
|
332 |
+
if (xmlReq.bTimeout) {
|
333 |
+
return;
|
334 |
+
}
|
335 |
+
if (xmlReq.status === 200)
|
336 |
+
xmlReq.onload();
|
337 |
+
else
|
338 |
+
xmlReq.onerror();
|
339 |
+
}
|
340 |
+
}
|
341 |
+
xmlReq.timeout = options.timeout;
|
342 |
+
xmlReq.send(options.sendData)
|
343 |
+
}
|
344 |
+
|
345 |
+
function startWpsInnderWebsocket(tryCount){
|
346 |
+
// 重试次数结束时,标记请求已完成
|
347 |
+
if (tryCount <= 0) {
|
348 |
+
if (!options.concurrent) {
|
349 |
+
if (bFinished)
|
350 |
+
return;
|
351 |
+
bFinished = true;
|
352 |
+
} else {
|
353 |
+
if (options.bFinished) {
|
354 |
+
return;
|
355 |
+
}
|
356 |
+
options.bFinished = true;
|
357 |
+
}
|
358 |
+
if (options.callBack)
|
359 |
+
options.callBack({
|
360 |
+
status: 2,
|
361 |
+
message: "请允许浏览器打开WPS Office"
|
362 |
+
});
|
363 |
+
return;
|
364 |
+
}
|
365 |
+
var ws = new getWebsocketObj({ timeout:options.timeout });
|
366 |
+
ws.connect(options.url);
|
367 |
+
ws.onmessage = function(res) {
|
368 |
+
wpsinvokeNetType="websocket"
|
369 |
+
sessionStorage.setItem("wpsinvokeNetType",wpsinvokeNetType);
|
370 |
+
var responseStr = res.data;
|
371 |
+
if (!options.concurrent)
|
372 |
+
bFinished = true;
|
373 |
+
else
|
374 |
+
options.bFinished = true;
|
375 |
+
if (options.callBack) {
|
376 |
+
if (errorMsg.indexOf(responseStr) != -1 || httpCodeErrorMessageList.indexOf(responseStr) != -1 ) {
|
377 |
+
var errorMessage = JSON.parse(responseStr);
|
378 |
+
options.callBack({
|
379 |
+
status: 1,
|
380 |
+
message: errorMessage.data
|
381 |
+
});
|
382 |
+
if (errorMessage.data == "Subserver not available." && tryCount == options.tryCount && options.bPop) {
|
383 |
+
InitWpsCloudSvr();
|
384 |
+
setTimeout(function () {
|
385 |
+
startWpsInnderWebsocket(tryCount - 1)
|
386 |
+
}, 3000);
|
387 |
+
}
|
388 |
+
}
|
389 |
+
else {
|
390 |
+
options.callBack({
|
391 |
+
status: 0,
|
392 |
+
response: res.data
|
393 |
+
});
|
394 |
+
}
|
395 |
+
}
|
396 |
+
ws.close();
|
397 |
+
}
|
398 |
+
ws.onerror = function(res){
|
399 |
+
|
400 |
+
if (tryCount == options.tryCount && options.bPop&&wpsinvokeNetType=="wait") { //打开wps并传参
|
401 |
+
InitWpsCloudSvr();
|
402 |
+
}
|
403 |
+
setTimeout(function () {
|
404 |
+
startWpsInnderWebsocket(tryCount - 1)
|
405 |
+
}, 1000);
|
406 |
+
}
|
407 |
+
ws.onopen = function(res){
|
408 |
+
ws.send(options.sendData);
|
409 |
+
}
|
410 |
+
}
|
411 |
+
if(isReplaceWebSocket()){
|
412 |
+
startWpsInnderWebsocket(options.tryCount);
|
413 |
+
} else {
|
414 |
+
startWpsInnder(options.tryCount);
|
415 |
+
}
|
416 |
+
return;
|
417 |
+
}
|
418 |
+
|
419 |
+
var fromCharCode = String.fromCharCode;
|
420 |
+
// encoder stuff
|
421 |
+
var cb_utob = function (c) {
|
422 |
+
if (c.length < 2) {
|
423 |
+
var cc = c.charCodeAt(0);
|
424 |
+
return cc < 0x80 ? c :
|
425 |
+
cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6)) +
|
426 |
+
fromCharCode(0x80 | (cc & 0x3f))) :
|
427 |
+
(fromCharCode(0xe0 | ((cc >>> 12) & 0x0f)) +
|
428 |
+
fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
|
429 |
+
fromCharCode(0x80 | (cc & 0x3f)));
|
430 |
+
} else {
|
431 |
+
var cc = 0x10000 +
|
432 |
+
(c.charCodeAt(0) - 0xD800) * 0x400 +
|
433 |
+
(c.charCodeAt(1) - 0xDC00);
|
434 |
+
return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07)) +
|
435 |
+
fromCharCode(0x80 | ((cc >>> 12) & 0x3f)) +
|
436 |
+
fromCharCode(0x80 | ((cc >>> 6) & 0x3f)) +
|
437 |
+
fromCharCode(0x80 | (cc & 0x3f)));
|
438 |
+
}
|
439 |
+
};
|
440 |
+
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
441 |
+
var utob = function (u) {
|
442 |
+
return u.replace(re_utob, cb_utob);
|
443 |
+
};
|
444 |
+
var _encode = function (u) {
|
445 |
+
var isUint8Array = Object.prototype.toString.call(u) === '[object Uint8Array]';
|
446 |
+
if (isUint8Array)
|
447 |
+
return u.toString('base64')
|
448 |
+
else
|
449 |
+
return btoa(utob(String(u)));
|
450 |
+
}
|
451 |
+
|
452 |
+
if (typeof window.btoa !== 'function') window.btoa = func_btoa;
|
453 |
+
|
454 |
+
function func_btoa(input) {
|
455 |
+
var str = String(input);
|
456 |
+
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
457 |
+
for (
|
458 |
+
// initialize result and counter
|
459 |
+
var block, charCode, idx = 0, map = chars, output = '';
|
460 |
+
// if the next str index does not exist:
|
461 |
+
// change the mapping table to "="
|
462 |
+
// check if d has no fractional digits
|
463 |
+
str.charAt(idx | 0) || (map = '=', idx % 1);
|
464 |
+
// "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8
|
465 |
+
output += map.charAt(63 & block >> 8 - idx % 1 * 8)
|
466 |
+
) {
|
467 |
+
charCode = str.charCodeAt(idx += 3 / 4);
|
468 |
+
if (charCode > 0xFF) {
|
469 |
+
throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");
|
470 |
+
}
|
471 |
+
block = block << 8 | charCode;
|
472 |
+
}
|
473 |
+
return output;
|
474 |
+
}
|
475 |
+
|
476 |
+
if (typeof window.atob !== 'function') window.atob = func_atob;
|
477 |
+
|
478 |
+
function func_atob(input) {
|
479 |
+
var output = input.replace(/[\s\S]{1,4}/g, cb_decode);
|
480 |
+
return output
|
481 |
+
}
|
482 |
+
|
483 |
+
function cb_decode(cccc) {
|
484 |
+
var len = cccc.length
|
485 |
+
, padlen = len % 4
|
486 |
+
, n = (len > 0 ?
|
487 |
+
b64tab[cccc.charAt(0)] << 18 : 0) |
|
488 |
+
(len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
489 |
+
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
490 |
+
| (len > 3 ? b64tab[cccc.charAt(3)] : 0)
|
491 |
+
, chars = [
|
492 |
+
fromCharCode(n >>> 16),
|
493 |
+
fromCharCode((n >>> 8) & 0xff),
|
494 |
+
fromCharCode(n & 0xff)
|
495 |
+
]
|
496 |
+
;
|
497 |
+
chars.length -= [0, 0, 2, 1][padlen];
|
498 |
+
return chars.join('');
|
499 |
+
};
|
500 |
+
|
501 |
+
function btou(b) {
|
502 |
+
return b.replace(re_btou, cb_btou);
|
503 |
+
};
|
504 |
+
|
505 |
+
// decoder stuff
|
506 |
+
var re_btou = new RegExp([
|
507 |
+
'[\xC0-\xDF][\x80-\xBF]',
|
508 |
+
'[\xE0-\xEF][\x80-\xBF]{2}',
|
509 |
+
'[\xF0-\xF7][\x80-\xBF]{3}'
|
510 |
+
].join('|'), 'g');
|
511 |
+
|
512 |
+
function cb_btou(cccc) {
|
513 |
+
switch (cccc.length) {
|
514 |
+
case 4:
|
515 |
+
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
516 |
+
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
517 |
+
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
518 |
+
| (0x3f & cccc.charCodeAt(3)),
|
519 |
+
offset = cp - 0x10000;
|
520 |
+
return (fromCharCode((offset >>> 10) + 0xD800)
|
521 |
+
+ fromCharCode((offset & 0x3FF) + 0xDC00));
|
522 |
+
case 3:
|
523 |
+
return fromCharCode(
|
524 |
+
((0x0f & cccc.charCodeAt(0)) << 12)
|
525 |
+
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
526 |
+
| (0x3f & cccc.charCodeAt(2))
|
527 |
+
);
|
528 |
+
default:
|
529 |
+
return fromCharCode(
|
530 |
+
((0x1f & cccc.charCodeAt(0)) << 6)
|
531 |
+
| (0x3f & cccc.charCodeAt(1))
|
532 |
+
);
|
533 |
+
}
|
534 |
+
};
|
535 |
+
|
536 |
+
/**
|
537 |
+
* 将字符串进行Base64编码
|
538 |
+
* @param {*} u 需要编码的数据
|
539 |
+
* @param {*} urisafe 返回值,编码后的数据
|
540 |
+
* @returns urisafe
|
541 |
+
*/
|
542 |
+
var encode = function (u, urisafe) {
|
543 |
+
return !urisafe ?
|
544 |
+
_encode(u) :
|
545 |
+
_encode(String(u)).replace(/[+\/]/g, function (m0) {
|
546 |
+
return m0 == '+' ? '-' : '_';
|
547 |
+
}).replace(/=/g, '');
|
548 |
+
};
|
549 |
+
|
550 |
+
var decode = function (u) {
|
551 |
+
return btou(atob(String(u)));
|
552 |
+
}
|
553 |
+
/**
|
554 |
+
* 获取IE浏览器版本
|
555 |
+
* @returns IE浏览器版本
|
556 |
+
*/
|
557 |
+
function IEVersion() {
|
558 |
+
var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串
|
559 |
+
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器
|
560 |
+
var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器
|
561 |
+
var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
|
562 |
+
if (isIE) {
|
563 |
+
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
|
564 |
+
reIE.test(userAgent);
|
565 |
+
var fIEVersion = parseFloat(RegExp["$1"]);
|
566 |
+
if (fIEVersion == 7) {
|
567 |
+
return 7;
|
568 |
+
} else if (fIEVersion == 8) {
|
569 |
+
return 8;
|
570 |
+
} else if (fIEVersion == 9) {
|
571 |
+
return 9;
|
572 |
+
} else if (fIEVersion == 10) {
|
573 |
+
return 10;
|
574 |
+
} else {
|
575 |
+
return 6; //IE版本<=7
|
576 |
+
}
|
577 |
+
} else if (isEdge) {
|
578 |
+
return 20; //edge
|
579 |
+
} else if (isIE11) {
|
580 |
+
return 11; //IE11
|
581 |
+
} else {
|
582 |
+
return 30; //不是ie浏览器
|
583 |
+
}
|
584 |
+
}
|
585 |
+
|
586 |
+
/**
|
587 |
+
* 启动wps客户端,加载项执行操作,无返回值
|
588 |
+
* @param {*} options 参数对象,详情见下:
|
589 |
+
* @param {*} clientType 加载项类型, wps / wpp / et
|
590 |
+
* @param {*} name 加载项名称
|
591 |
+
* @param {*} func 客户端加载项要执行的方法
|
592 |
+
* @param {*} param 客户端家乡执行方法的参数
|
593 |
+
* @param {*} urlBase 网页路径前缀
|
594 |
+
* @param {*} callBack 回调函数
|
595 |
+
* @param {*} tryCount 请求失败后的尝试次数
|
596 |
+
* @param {*} bPop 是否弹出浏览器提示对话框
|
597 |
+
* @param {*} wpsclient wpsclient对象
|
598 |
+
*/
|
599 |
+
function WpsStart(options) {
|
600 |
+
var startInfo = {
|
601 |
+
"name": options.name,
|
602 |
+
"function": options.func,
|
603 |
+
"info": options.param.param,
|
604 |
+
"jsPluginsXml": options.param.jsPluginsXml
|
605 |
+
};
|
606 |
+
var strData = JSON.stringify(startInfo);
|
607 |
+
if (IEVersion() < 10) {
|
608 |
+
try {
|
609 |
+
eval("strData = '" + JSON.stringify(startInfo) + "';");
|
610 |
+
} catch (err) {
|
611 |
+
|
612 |
+
}
|
613 |
+
}
|
614 |
+
|
615 |
+
var baseData = encode(strData);
|
616 |
+
var url = options.urlBase + "/" + options.clientType + "/runParams";
|
617 |
+
var data = "ksowebstartup" + options.clientType + "://" + baseData;
|
618 |
+
startWps({
|
619 |
+
url: url,
|
620 |
+
sendData: data,
|
621 |
+
callBack: options.callBack,
|
622 |
+
tryCount: options.tryCount,
|
623 |
+
bPop: options.bPop,
|
624 |
+
timeout: 5000,
|
625 |
+
concurrent: false,
|
626 |
+
wpsclient: options.wpsclient
|
627 |
+
});
|
628 |
+
}
|
629 |
+
|
630 |
+
/**
|
631 |
+
* 服务端版本为空时,通过该接口启动wps
|
632 |
+
* @param {*} options 参数对象,详情见下:
|
633 |
+
* @param {*} clientType 加载项类型, wps / wpp / et
|
634 |
+
* @param {*} name 加载项名称
|
635 |
+
* @param {*} func 客户端加载项要执行的方法
|
636 |
+
* @param {*} param 客户端家乡执行方法的参数
|
637 |
+
* @param {*} urlBase 网页路径前缀
|
638 |
+
* @param {*} callBack 回调函数
|
639 |
+
* @param {*} wpsclient wpsclient对象
|
640 |
+
* @param {*} concurrent 请求是否同步发送
|
641 |
+
*/
|
642 |
+
function WpsStartWrap(options) {
|
643 |
+
WpsStart({
|
644 |
+
clientType: options.clientType,
|
645 |
+
name: options.name,
|
646 |
+
func: options.func,
|
647 |
+
param: options.param,
|
648 |
+
urlBase: options.urlBase,
|
649 |
+
callBack: options.callBack,
|
650 |
+
tryCount: 4,
|
651 |
+
bPop: true,
|
652 |
+
wpsclient: options.wpsclient,
|
653 |
+
})
|
654 |
+
}
|
655 |
+
|
656 |
+
/**
|
657 |
+
* 支持浏览器触发,WPS有返回值的启动
|
658 |
+
*
|
659 |
+
* @param {*} clientType 组件类型
|
660 |
+
* @param {*} name WPS加载项名称
|
661 |
+
* @param {*} func WPS加载项入口方法
|
662 |
+
* @param {*} param 参数:包括WPS加载项内部定义的方法,参数等
|
663 |
+
* @param {*} callBack 回调函数
|
664 |
+
* @param {*} tryCount 重试次数
|
665 |
+
* @param {*} bPop 是否弹出浏览器提示对话框
|
666 |
+
*/
|
667 |
+
function WpsStartWrapExInner(options) {
|
668 |
+
var infocontent = options.param.param;
|
669 |
+
var cmdId = guid();
|
670 |
+
if (!options.wpsclient || options.wpsclient.single) {
|
671 |
+
infocontent = JSON.stringify(options.param.param);
|
672 |
+
var rspUrl = getHttpUrl() + "/transferEcho/runParams";
|
673 |
+
var funcEx = "var res = " + options.func;
|
674 |
+
var cbCode = "var xhr = new XMLHttpRequest();xhr.open('POST', '" + rspUrl + "');xhr.send(JSON.stringify({id: '" + cmdId + "', response: res}));" //res 为func执行返回值
|
675 |
+
var infoEx = infocontent + ");" + cbCode + "void(0";
|
676 |
+
options.func = funcEx;
|
677 |
+
infocontent = infoEx;
|
678 |
+
}
|
679 |
+
var startInfo = {
|
680 |
+
"name": options.name,
|
681 |
+
"function": options.func,
|
682 |
+
"info": infocontent,
|
683 |
+
"showToFront": options.param.showToFront,
|
684 |
+
"jsPluginsXml": options.param.jsPluginsXml,
|
685 |
+
};
|
686 |
+
|
687 |
+
var strData = JSON.stringify(startInfo);
|
688 |
+
if (IEVersion() < 10) {
|
689 |
+
try {
|
690 |
+
eval("strData = '" + JSON.stringify(startInfo) + "';");
|
691 |
+
} catch (err) {
|
692 |
+
|
693 |
+
}
|
694 |
+
}
|
695 |
+
|
696 |
+
var baseData = encode(strData);
|
697 |
+
var wrapper;
|
698 |
+
|
699 |
+
if (!options.wpsclient || options.wpsclient.single) {
|
700 |
+
var url = options.urlBase + "/transfer/runParams";
|
701 |
+
var data = "ksowebstartup" + options.clientType + "://" + baseData;
|
702 |
+
wrapper = {
|
703 |
+
id: cmdId,
|
704 |
+
app: options.clientType,
|
705 |
+
data: data,
|
706 |
+
serverId: serverId,
|
707 |
+
mode: options.silentMode ? true : false,
|
708 |
+
timeout: options.timeout,
|
709 |
+
startparam: options.startparam,
|
710 |
+
};
|
711 |
+
}
|
712 |
+
else {
|
713 |
+
var url = options.urlBase + "/transferEx/runParams";
|
714 |
+
wrapper = {
|
715 |
+
id: options.wpsclient.clientId,
|
716 |
+
app: options.clientType,
|
717 |
+
data: baseData,
|
718 |
+
mode: options.wpsclient.silentMode ? "true" : "false",
|
719 |
+
serverId: serverId,
|
720 |
+
timeout: options.timeout,
|
721 |
+
startparam: options.startparam,
|
722 |
+
};
|
723 |
+
}
|
724 |
+
wrapper = JSON.stringify(wrapper);
|
725 |
+
startWps({
|
726 |
+
url: url,
|
727 |
+
sendData: wrapper,
|
728 |
+
callBack: options.callBack,
|
729 |
+
tryCount: options.tryCount,
|
730 |
+
bPop: options.bPop,
|
731 |
+
timeout: 0,
|
732 |
+
concurrent: options.concurrent,
|
733 |
+
wpsclient: options.wpsclient
|
734 |
+
});
|
735 |
+
}
|
736 |
+
|
737 |
+
/**
|
738 |
+
* 获取服务端版本号的接口
|
739 |
+
* @param {*} options 参数对象,详情见下:
|
740 |
+
* @param {*} clientType 加载项类型, wps / wpp / et
|
741 |
+
* @param {*} name 加载项名称
|
742 |
+
* @param {*} func 客户端加载项要执行的方法
|
743 |
+
* @param {*} param 客户端家乡执行方法的参数
|
744 |
+
* @param {*} urlBase 网页路径前缀
|
745 |
+
* @param {*} callBack 回调函数
|
746 |
+
* @param {*} wpsclient wpsclient对象
|
747 |
+
* @param {*} concurrent 请求是否同步发送
|
748 |
+
*/
|
749 |
+
function WpsStartWrapVersionInner(options) {
|
750 |
+
if (serverVersion == "wait") {
|
751 |
+
if (g_isSdkInited == true) {
|
752 |
+
InitWpsCloudSvr();
|
753 |
+
}
|
754 |
+
startWps({
|
755 |
+
url: options.urlBase + '/version',
|
756 |
+
sendData: JSON.stringify({ serverId: serverId }),
|
757 |
+
callBack: function (res) {
|
758 |
+
if (res.status !== 0) {
|
759 |
+
options.callBack(res)
|
760 |
+
return;
|
761 |
+
}
|
762 |
+
serverVersion = res.response;
|
763 |
+
sessionStorage.setItem('serverVersion', serverVersion);
|
764 |
+
// 确定版本不能使用ws后,需要把未启动时定义好的协议调整回来
|
765 |
+
if(wpsinvokeNetType === 'websocket') {
|
766 |
+
options.urlBase = transferWebsocketToHttp(options.urlBase)
|
767 |
+
}
|
768 |
+
if (options.isPublish != true) {
|
769 |
+
options.tryCount = 1
|
770 |
+
options.bPop = false
|
771 |
+
if (serverVersion === "") {
|
772 |
+
WpsStart(options)
|
773 |
+
} else if (serverVersion < "1.0.1" && options.wpsclient) {
|
774 |
+
options.wpsclient.single = true;
|
775 |
+
WpsStartWrapExInner(options);
|
776 |
+
} else {
|
777 |
+
WpsStartWrapExInner(options);
|
778 |
+
}
|
779 |
+
}
|
780 |
+
else {
|
781 |
+
if (serverVersion === "") {
|
782 |
+
callBack({
|
783 |
+
status: 4,
|
784 |
+
message: "当前客户端不支持,请升级客户端"
|
785 |
+
})
|
786 |
+
} else {
|
787 |
+
WpsAddonGetAllConfigInner(options.callBack)
|
788 |
+
}
|
789 |
+
}
|
790 |
+
},
|
791 |
+
tryCount: 4,
|
792 |
+
bPop: !g_isSdkInited,
|
793 |
+
timeout: 5000,
|
794 |
+
concurrent: options.concurrent
|
795 |
+
});
|
796 |
+
} else {
|
797 |
+
if (options.isPublish != true) {
|
798 |
+
options.tryCount = 4
|
799 |
+
options.bPop = true
|
800 |
+
if (serverVersion === "") {
|
801 |
+
WpsStartWrap(options)
|
802 |
+
} else if (serverVersion < "1.0.1" && options.wpsclient) {
|
803 |
+
options.wpsclient.single = true;
|
804 |
+
WpsStartWrapExInner(options);
|
805 |
+
} else {
|
806 |
+
WpsStartWrapExInner(options);
|
807 |
+
}
|
808 |
+
}
|
809 |
+
else {
|
810 |
+
if (serverVersion === "") {
|
811 |
+
callBack({
|
812 |
+
status: 4,
|
813 |
+
message: "当前客户端不支持,请升级客户端"
|
814 |
+
})
|
815 |
+
} else {
|
816 |
+
WpsAddonGetAllConfigInner(options.callBack)
|
817 |
+
}
|
818 |
+
}
|
819 |
+
}
|
820 |
+
}
|
821 |
+
|
822 |
+
var HeartBeatCode =
|
823 |
+
"function getHttpObj() {\n"
|
824 |
+
+ " var httpobj = null;\n"
|
825 |
+
+ " if (IEVersion() < 10) {\n"
|
826 |
+
+ " try {\n"
|
827 |
+
+ " httpobj = new XDomainRequest();\n"
|
828 |
+
+ " } catch (e1) {\n"
|
829 |
+
+ " httpobj = new createXHR();\n"
|
830 |
+
+ " }\n"
|
831 |
+
+ " } else {\n"
|
832 |
+
+ " httpobj = new createXHR();\n"
|
833 |
+
+ " }\n"
|
834 |
+
+ " return httpobj;\n"
|
835 |
+
+ " }\n"
|
836 |
+
+ " \n"
|
837 |
+
+ " function createXHR() {\n"
|
838 |
+
+ " if (typeof XMLHttpRequest != 'undefined') {\n"
|
839 |
+
+ " return new XMLHttpRequest();\n"
|
840 |
+
+ " } else if (typeof ActiveXObject != 'undefined') {\n"
|
841 |
+
+ " var versions = [\n"
|
842 |
+
+ " 'MSXML2.XMLHttp.6.0',\n"
|
843 |
+
+ " 'MSXML2.XMLHttp.3.0',\n"
|
844 |
+
+ " 'MSXML2.XMLHttp'\n"
|
845 |
+
+ " ];\n"
|
846 |
+
+ " \n"
|
847 |
+
+ " for (var i = 0; i < versions.length; i++) {\n"
|
848 |
+
+ " try {\n"
|
849 |
+
+ " return new ActiveXObject(versions[i]);\n"
|
850 |
+
+ " } catch (e) {\n"
|
851 |
+
+ " \n"
|
852 |
+
+ " }\n"
|
853 |
+
+ " }\n"
|
854 |
+
+ " } else {\n"
|
855 |
+
+ " throw new Error('您的浏览器不支持XHR对象');\n"
|
856 |
+
+ " }\n"
|
857 |
+
+ " }\n"
|
858 |
+
+ " \n"
|
859 |
+
+ " function IEVersion() {\n"
|
860 |
+
+ " var userAgent = navigator.userAgent; \n"
|
861 |
+
+ " var isIE = userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1;\n"
|
862 |
+
+ " var isEdge = userAgent.indexOf('Edge') > -1 && !isIE; \n"
|
863 |
+
+ " var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf('rv:11.0') > -1;\n"
|
864 |
+
+ " if (isIE) {\n"
|
865 |
+
+ " var reIE = new RegExp('MSIE (\\d+\\.\\d+);');\n"
|
866 |
+
+ " reIE.test(userAgent);\n"
|
867 |
+
+ " var fIEVersion = parseFloat(RegExp['$1']);\n"
|
868 |
+
+ " if (fIEVersion == 7) {\n"
|
869 |
+
+ " return 7;\n"
|
870 |
+
+ " } else if (fIEVersion == 8) {\n"
|
871 |
+
+ " return 8;\n"
|
872 |
+
+ " } else if (fIEVersion == 9) {\n"
|
873 |
+
+ " return 9;\n"
|
874 |
+
+ " } else if (fIEVersion == 10) {\n"
|
875 |
+
+ " return 10;\n"
|
876 |
+
+ " } else {\n"
|
877 |
+
+ " return 6; \n"
|
878 |
+
+ " }\n"
|
879 |
+
+ " } else if (isEdge) {\n"
|
880 |
+
+ " return 20; \n"
|
881 |
+
+ " } else if (isIE11) {\n"
|
882 |
+
+ " return 11; \n"
|
883 |
+
+ " } else {\n"
|
884 |
+
+ " return 30; \n"
|
885 |
+
+ " }\n"
|
886 |
+
+ " }\n"
|
887 |
+
+ " var heartBeatStart = false;\n"
|
888 |
+
+ " function checkLastRegTime() {\n"
|
889 |
+
+ " var now = new Date().valueOf();\n"
|
890 |
+
+ " var TimeGap = now - LastRegTime;\n"
|
891 |
+
+ " if (TimeGap > 5000 && !heartBeatStart) {\n"
|
892 |
+
+ " HeartBeat();\n"
|
893 |
+
+ " heartBeatStart = true;\n"
|
894 |
+
+ " }\n"
|
895 |
+
+ " }\n"
|
896 |
+
+ " \n"
|
897 |
+
+ " function HeartBeat() {\n"
|
898 |
+
+ " var heartBeatItem = function () {\n"
|
899 |
+
+ " var xhr = getHttpObj();\n"
|
900 |
+
+ " xhr.onload = function (e) {\n"
|
901 |
+
+ " self.setTimeout(heartBeatItem, 5000);\n"
|
902 |
+
+ " }\n"
|
903 |
+
+ " xhr.onerror = function (e) {\n"
|
904 |
+
+ " self.setTimeout(heartBeatItem, 5000);\n"
|
905 |
+
+ " }\n"
|
906 |
+
+ " xhr.ontimeout = function (e) {\n"
|
907 |
+
+ " self.setTimeout(heartBeatItem, 5000);\n"
|
908 |
+
+ " }\n"
|
909 |
+
+ " xhr.open('POST', 'http://127.0.0.1:58890/askwebnotify', true);\n"
|
910 |
+
+ " xhr.timeout = 2000;\n"
|
911 |
+
+ " xhr.send(JSON.stringify(paramStr));\n"
|
912 |
+
+ " }\n"
|
913 |
+
+ " heartBeatItem();\n"
|
914 |
+
+ " }\n"
|
915 |
+
+ " \n"
|
916 |
+
+ " var paramStr;\n"
|
917 |
+
+ " var startCheck = false;\n"
|
918 |
+
+ " self.addEventListener('message', function (event) {\n"
|
919 |
+
+ " var data = event.data;\n"
|
920 |
+
+ " paramStr = data.param\n"
|
921 |
+
+ " paramStr.heartBeat = true\n"
|
922 |
+
+ " LastRegTime = data.LastRegTime;\n"
|
923 |
+
+ " if (!startCheck) {\n"
|
924 |
+
+ " startCheck = true;\n"
|
925 |
+
+ " self.setInterval(checkLastRegTime, 5000)\n"
|
926 |
+
+ " }\n"
|
927 |
+
+ " }, false);\n"
|
928 |
+
|
929 |
+
var HeartBeatCodeWebSocket =
|
930 |
+
" // 判断是否函数 \n"
|
931 |
+
+ " function isFunction(func) { \n"
|
932 |
+
+ " return typeof func === 'function'; \n"
|
933 |
+
+ " } \n"
|
934 |
+
+ " // websocket对象 \n"
|
935 |
+
+ " function getWebsocketObj() { \n"
|
936 |
+
+ " this.onopen = null; \n"
|
937 |
+
+ " this.onmessage = null; \n"
|
938 |
+
+ " this.onclose = null; \n"
|
939 |
+
+ " this.onerror = null; \n"
|
940 |
+
+ " this.wsInstance = null; \n"
|
941 |
+
+ " } \n"
|
942 |
+
+ " getWebsocketObj.prototype.connect = function (url) { \n"
|
943 |
+
+ " var that = this; \n"
|
944 |
+
+ " var ws = (that.wsInstance = new WebSocket(url)); \n"
|
945 |
+
+ " ws.onopen = function (res) { \n"
|
946 |
+
+ " if (isFunction(that.onopen)) { \n"
|
947 |
+
+ " that.onopen(res); \n"
|
948 |
+
+ " } \n"
|
949 |
+
+ " }; \n"
|
950 |
+
+ " ws.onmessage = function (res) { \n"
|
951 |
+
+ " if (isFunction(that.onmessage)) { \n"
|
952 |
+
+ " that.onmessage(res); \n"
|
953 |
+
+ " } \n"
|
954 |
+
+ " }; \n"
|
955 |
+
+ " ws.onclose = function (res) { \n"
|
956 |
+
+ " if (isFunction(that.onclose)) { \n"
|
957 |
+
+ " that.onclose(res); \n"
|
958 |
+
+ " } \n"
|
959 |
+
+ " }; \n"
|
960 |
+
+ " ws.onerror = function (res) { \n"
|
961 |
+
+ " if (isFunction(that.onerror)) { \n"
|
962 |
+
+ " that.onerror(res); \n"
|
963 |
+
+ " } \n"
|
964 |
+
+ " }; \n"
|
965 |
+
+ " }; \n"
|
966 |
+
+ " getWebsocketObj.prototype.send = function (data) { \n"
|
967 |
+
+ " if (this.wsInstance) { \n"
|
968 |
+
+ " this.wsInstance.send(data); \n"
|
969 |
+
+ " } \n"
|
970 |
+
+ " }; \n"
|
971 |
+
+ " getWebsocketObj.prototype.close = function () { \n"
|
972 |
+
+ " if (this.wsInstance) { \n"
|
973 |
+
+ " this.wsInstance.close(); \n"
|
974 |
+
+ " } \n"
|
975 |
+
+ " }; \n"
|
976 |
+
+ " var heartBeatStart = false; \n"
|
977 |
+
+ " function checkLastRegTime() { \n"
|
978 |
+
+ " var now = new Date().valueOf(); \n"
|
979 |
+
+ " var TimeGap = now - LastRegTime; \n"
|
980 |
+
+ " if (TimeGap > 5000 && !heartBeatStart) { \n"
|
981 |
+
+ " HeartBeat(); \n"
|
982 |
+
+ " heartBeatStart = true; \n"
|
983 |
+
+ " } \n"
|
984 |
+
+ " } \n"
|
985 |
+
+ " var ws = null \n"
|
986 |
+
+ " function HeartBeat() { \n"
|
987 |
+
+ " var heartBeatItem = function () { \n"
|
988 |
+
+ " if(ws !== null) { \n"
|
989 |
+
+ " ws.send(JSON.stringify(paramStr)); \n"
|
990 |
+
+ " return; \n"
|
991 |
+
+ " } \n"
|
992 |
+
+ " ws = new getWebsocketObj(); \n"
|
993 |
+
+ " ws.onmessage = function () { \n"
|
994 |
+
+ " self.setTimeout(function() { \n"
|
995 |
+
+ " ws.send(JSON.stringify(paramStr)) \n"
|
996 |
+
+ " }, 5000); \n"
|
997 |
+
+ " }; \n"
|
998 |
+
+ " ws.onclose = function () { \n"
|
999 |
+
+ " ws = null; \n"
|
1000 |
+
+ " self.setTimeout(heartBeatItem, 5000); \n"
|
1001 |
+
+ " }; \n"
|
1002 |
+
+ " ws.connect('ws://127.0.0.1:58892/askwebnotify'); \n"
|
1003 |
+
+ " ws.onopen = function () { \n"
|
1004 |
+
+ " ws.send(JSON.stringify(paramStr)); \n"
|
1005 |
+
+ " }; \n"
|
1006 |
+
+ " }; \n"
|
1007 |
+
+ " heartBeatItem(); \n"
|
1008 |
+
+ " }; \n"
|
1009 |
+
+ " var paramStr; \n"
|
1010 |
+
+ " var startCheck = false; \n"
|
1011 |
+
+ " self.addEventListener( \n"
|
1012 |
+
+ " 'message', \n"
|
1013 |
+
+ " function (event) { \n"
|
1014 |
+
+ " var data = event.data; \n"
|
1015 |
+
+ " paramStr = data.param; \n"
|
1016 |
+
+ " paramStr.heartBeat = true; \n"
|
1017 |
+
+ " LastRegTime = data.LastRegTime; \n"
|
1018 |
+
+ " if (!startCheck) { \n"
|
1019 |
+
+ " startCheck = true; \n"
|
1020 |
+
+ " self.setInterval(checkLastRegTime, 5000); \n"
|
1021 |
+
+ " } \n"
|
1022 |
+
+ " }, \n"
|
1023 |
+
+ " false \n"
|
1024 |
+
+ " ); \n"
|
1025 |
+
|
1026 |
+
/**
|
1027 |
+
* 生成guid的接口
|
1028 |
+
* @returns guid
|
1029 |
+
*/
|
1030 |
+
function guid() {
|
1031 |
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
1032 |
+
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
1033 |
+
return v.toString(16);
|
1034 |
+
});
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
/**
|
1038 |
+
* 开启多用户的接口
|
1039 |
+
*/
|
1040 |
+
var serverId = undefined
|
1041 |
+
function EnableMultiUser() {
|
1042 |
+
serverId = getServerId();
|
1043 |
+
InitSdk(true)
|
1044 |
+
}
|
1045 |
+
|
1046 |
+
/**
|
1047 |
+
* 自定义协议启动服务端
|
1048 |
+
* 默认不带参数serverId,linux未升级之前不要使用多用户
|
1049 |
+
*/
|
1050 |
+
function InitWpsCloudSvr() {
|
1051 |
+
if (serverId == undefined)
|
1052 |
+
window.location.href = "ksoWPSCloudSvr://start=RelayHttpServer"//是否启动wps弹框
|
1053 |
+
else
|
1054 |
+
window.location.href = "ksoWPSCloudSvr://start=RelayHttpServer" + "&serverId=" + serverId //是否启动wps弹框
|
1055 |
+
}
|
1056 |
+
|
1057 |
+
/**
|
1058 |
+
* 获取serverId的接口
|
1059 |
+
* @returns serverId
|
1060 |
+
*/
|
1061 |
+
function getServerId() {
|
1062 |
+
if (window.localStorage) {
|
1063 |
+
if (localStorage.getItem("serverId")) {
|
1064 |
+
//
|
1065 |
+
}
|
1066 |
+
else {
|
1067 |
+
localStorage.setItem("serverId", guid());
|
1068 |
+
}
|
1069 |
+
return localStorage.getItem("serverId");
|
1070 |
+
}
|
1071 |
+
else {
|
1072 |
+
return guid();
|
1073 |
+
}
|
1074 |
+
}
|
1075 |
+
|
1076 |
+
/**
|
1077 |
+
* 将字符串转成二进制���这里用来将字符串化后的js代码转成二进制文件
|
1078 |
+
* @param {*} code
|
1079 |
+
* @returns js文件对象的url
|
1080 |
+
*/
|
1081 |
+
function codeToBlob(code) {
|
1082 |
+
var blob = new Blob([code], { type: 'text/javascript' }); // 生成js文件对象
|
1083 |
+
var objectURL = window.URL.createObjectURL(blob); // 生成js文件的url
|
1084 |
+
return objectURL;
|
1085 |
+
}
|
1086 |
+
|
1087 |
+
var RegWebNotifyMap = { wps: {}, wpp: {}, et: {}, pdf: {} }
|
1088 |
+
var bWebNotifyUseTimeout = true
|
1089 |
+
function WebNotifyUseTimeout(value) {
|
1090 |
+
bWebNotifyUseTimeout = value ? true : false
|
1091 |
+
}
|
1092 |
+
var g_businessId = Number(Math.random().toString().substr(3, 5) + Date.parse(new Date())).toString(36);
|
1093 |
+
var HeartBeatWorker
|
1094 |
+
var checkVersionInterval
|
1095 |
+
if (window.Worker) {
|
1096 |
+
try {
|
1097 |
+
var code = '';
|
1098 |
+
HeartBeatWorkerCallBack()
|
1099 |
+
checkVersionInterval = setInterval(HeartBeatWorkerCallBack,1000)
|
1100 |
+
|
1101 |
+
} catch (error) {
|
1102 |
+
//
|
1103 |
+
}
|
1104 |
+
}
|
1105 |
+
function HeartBeatWorkerCallBack(){
|
1106 |
+
if(serverVersion === 'wait'){
|
1107 |
+
return;
|
1108 |
+
}
|
1109 |
+
if(isReplaceWebSocket()) {
|
1110 |
+
code = HeartBeatCodeWebSocket;
|
1111 |
+
} else {
|
1112 |
+
code = HeartBeatCode
|
1113 |
+
};
|
1114 |
+
HeartBeatWorker = new Worker(codeToBlob(code));
|
1115 |
+
if(checkVersionInterval) {
|
1116 |
+
clearInterval(checkVersionInterval);
|
1117 |
+
}
|
1118 |
+
return;
|
1119 |
+
}
|
1120 |
+
var g_LastRegTime;
|
1121 |
+
/**
|
1122 |
+
* 注册一个前端页面接收WPS传来消息的方法
|
1123 |
+
* @param {*} clientType wps | et | wpp
|
1124 |
+
* @param {*} name WPS加载项的名称
|
1125 |
+
* @param {*} callBack 回调函数
|
1126 |
+
* @param {*} wpsclient wpsclient对象
|
1127 |
+
*/
|
1128 |
+
function RegWebNotify(clientType, name, callBack, wpsclient) {
|
1129 |
+
if (clientType != "wps" && clientType != "wpp" && clientType != "et" && clientType != "pdf")
|
1130 |
+
return;
|
1131 |
+
var paramStr = {}
|
1132 |
+
if (wpsclient) {
|
1133 |
+
if (wpsclient.notifyRegsitered == true) {
|
1134 |
+
return
|
1135 |
+
}
|
1136 |
+
wpsclient.notifyRegsitered = true;
|
1137 |
+
paramStr = {
|
1138 |
+
clientId: wpsclient.clientId,
|
1139 |
+
name: name,
|
1140 |
+
type: clientType,
|
1141 |
+
serverId: serverId
|
1142 |
+
}
|
1143 |
+
|
1144 |
+
}
|
1145 |
+
else {
|
1146 |
+
if (typeof callBack != 'function')
|
1147 |
+
return
|
1148 |
+
if (RegWebNotifyMap[clientType][name]) {
|
1149 |
+
RegWebNotifyMap[clientType][name] = callBack;
|
1150 |
+
return
|
1151 |
+
}
|
1152 |
+
var RegWebNotifyID = new Date().valueOf() + ''
|
1153 |
+
paramStr = {
|
1154 |
+
id: RegWebNotifyID,
|
1155 |
+
name: name,
|
1156 |
+
type: clientType,
|
1157 |
+
serverId: serverId
|
1158 |
+
}
|
1159 |
+
RegWebNotifyMap[clientType][name] = callBack
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
var askItem = function () {
|
1163 |
+
var xhr = getHttpObj()
|
1164 |
+
xhr.onload = function (e) {
|
1165 |
+
if(!WpsInvoke.RegWebNotifyEnable){
|
1166 |
+
RegWebNotifyMap[clientType][name]=null;
|
1167 |
+
return ;
|
1168 |
+
}
|
1169 |
+
if (xhr.responseText == "WPSInnerMessage_quit" || (xhr.status != undefined && xhr.status != 200)||!WpsInvoke.RegWebNotifyEnable) {
|
1170 |
+
if ((!wpsclient || wpsclient.single)) {
|
1171 |
+
window.setTimeout(askItem, 2000);
|
1172 |
+
}
|
1173 |
+
return;
|
1174 |
+
}
|
1175 |
+
window.setTimeout(askItem, 300)
|
1176 |
+
// fix 新版本客户端使用旧版sdk的时候,会出现版本号判断问题
|
1177 |
+
if (serverVersion!== "" && serverVersion !== "wait") {
|
1178 |
+
try {
|
1179 |
+
if (!HeartBeatWorker)
|
1180 |
+
throw new Error();
|
1181 |
+
var resText = JSON.parse(xhr.responseText);
|
1182 |
+
paramStr.messageId = resText.msgId;
|
1183 |
+
if (wpsclient) {
|
1184 |
+
if (resText.data != undefined && paramStr.messageId != undefined) // 如果发的数据是字符串化后的json对象,这里的resText.data就是一个json对象,可以输出自己想要的json数据
|
1185 |
+
if (typeof resText.data == 'object')
|
1186 |
+
wpsclient.OnRegWebNotify(JSON.stringify(resText.data))
|
1187 |
+
else
|
1188 |
+
wpsclient.OnRegWebNotify(resText.data)
|
1189 |
+
else
|
1190 |
+
wpsclient.OnRegWebNotify(xhr.responseText)
|
1191 |
+
} else {
|
1192 |
+
var func = RegWebNotifyMap[clientType][name]
|
1193 |
+
if (resText.data != undefined && paramStr.messageId != undefined) // 如果发的数据是字符串化后的json对象,这里的resText.data就是一个json对象,可以输出自己想要的json数据
|
1194 |
+
if (typeof resText.data == 'object')
|
1195 |
+
func(JSON.stringify(resText.data))
|
1196 |
+
else
|
1197 |
+
func(resText.data)
|
1198 |
+
else
|
1199 |
+
func(xhr.responseText)
|
1200 |
+
}
|
1201 |
+
}
|
1202 |
+
catch (e) {
|
1203 |
+
// 这里做一个容错,即使json解析失败,也要把msgId提取出来,发回给服务端,避免消息清不掉一直重复发送
|
1204 |
+
// 同时把data也取出来,但是格式无法保证
|
1205 |
+
var data
|
1206 |
+
var str = xhr.responseText
|
1207 |
+
var idx1 = str.indexOf("\"msgId\"")
|
1208 |
+
var idx2
|
1209 |
+
var idx3
|
1210 |
+
var idx4
|
1211 |
+
var data
|
1212 |
+
if (idx1 != -1) {
|
1213 |
+
idx1 = idx1 + 8
|
1214 |
+
idx2 = str.indexOf("\"data\"") - 2
|
1215 |
+
paramStr.messageId = parseInt(str.substring(idx1, idx2))
|
1216 |
+
idx3 = str.indexOf("\"data\"") + 8
|
1217 |
+
idx4 = str.length - 2
|
1218 |
+
data = str.substring(idx3, idx4)
|
1219 |
+
}
|
1220 |
+
if (wpsclient) {
|
1221 |
+
if (paramStr.messageId !== undefined && data != undefined)
|
1222 |
+
wpsclient.OnRegWebNotify(data)
|
1223 |
+
else
|
1224 |
+
wpsclient.OnRegWebNotify(xhr.responseText)
|
1225 |
+
} else {
|
1226 |
+
var func = RegWebNotifyMap[clientType][name]
|
1227 |
+
if (paramStr.messageId !== undefined && data != undefined)
|
1228 |
+
func(data)
|
1229 |
+
else
|
1230 |
+
func(xhr.responseText)
|
1231 |
+
}
|
1232 |
+
}
|
1233 |
+
}
|
1234 |
+
else {
|
1235 |
+
var resText = JSON.parse(xhr.responseText);
|
1236 |
+
paramStr.messageId = resText.msgId;
|
1237 |
+
var resData = decode(resText.data);
|
1238 |
+
if (wpsclient) {
|
1239 |
+
wpsclient.OnRegWebNotify(resData)
|
1240 |
+
}
|
1241 |
+
else {
|
1242 |
+
var func = RegWebNotifyMap[clientType][name]
|
1243 |
+
func(resData)
|
1244 |
+
}
|
1245 |
+
}
|
1246 |
+
}
|
1247 |
+
xhr.onerror = function (e) {
|
1248 |
+
if (bWebNotifyUseTimeout)
|
1249 |
+
window.setTimeout(askItem, 1000)
|
1250 |
+
else
|
1251 |
+
window.setTimeout(askItem, 10000)
|
1252 |
+
}
|
1253 |
+
xhr.ontimeout = function (e) {
|
1254 |
+
if (bWebNotifyUseTimeout)
|
1255 |
+
window.setTimeout(askItem, 300)
|
1256 |
+
else
|
1257 |
+
window.setTimeout(askItem, 10000)
|
1258 |
+
}
|
1259 |
+
if (IEVersion() < 10) {
|
1260 |
+
xhr.onreadystatechange = function () {
|
1261 |
+
if (xhr.readyState != 4)
|
1262 |
+
return;
|
1263 |
+
if (xhr.bTimeout) {
|
1264 |
+
return;
|
1265 |
+
}
|
1266 |
+
if (xhr.status === 200)
|
1267 |
+
xhr.onload();
|
1268 |
+
else
|
1269 |
+
xhr.onerror();
|
1270 |
+
}
|
1271 |
+
}
|
1272 |
+
xhr.open('POST', GetUrlBase() + '/askwebnotify', true)
|
1273 |
+
if (bWebNotifyUseTimeout)
|
1274 |
+
xhr.timeout = 2000;
|
1275 |
+
if (HeartBeatWorker) {
|
1276 |
+
g_LastRegTime = new Date().valueOf();
|
1277 |
+
var param = {
|
1278 |
+
param: {
|
1279 |
+
name: name,
|
1280 |
+
type: clientType,
|
1281 |
+
businessId: g_businessId,
|
1282 |
+
serverId: serverId
|
1283 |
+
},
|
1284 |
+
LastRegTime: g_LastRegTime
|
1285 |
+
}
|
1286 |
+
HeartBeatWorker.postMessage(param)
|
1287 |
+
}
|
1288 |
+
if (HeartBeatWorker) {
|
1289 |
+
paramStr.businessId = g_businessId
|
1290 |
+
}
|
1291 |
+
xhr.send(JSON.stringify(paramStr));
|
1292 |
+
}
|
1293 |
+
|
1294 |
+
// 用途ws发送消失后,客户端一段时间没有回复,自动关闭链接操作
|
1295 |
+
var askItemWebsocketTimer = null;
|
1296 |
+
// 客户端有消息推送标记
|
1297 |
+
var hasResponse = false;
|
1298 |
+
// 客户端无消息推送标记
|
1299 |
+
var isTimeout = false;
|
1300 |
+
var askItemWebsocket = function() {
|
1301 |
+
if(!isReplaceWebSocket()) {
|
1302 |
+
askItem();
|
1303 |
+
return
|
1304 |
+
}
|
1305 |
+
var ws = new getWebsocketObj();
|
1306 |
+
ws.connect(GetUrlBase() + '/askwebnotify');
|
1307 |
+
ws.onmessage = function(res){
|
1308 |
+
hasResponse = true;
|
1309 |
+
ws.close();
|
1310 |
+
if(askItemWebsocketTimer !== null){
|
1311 |
+
clearTimeout(askItemWebsocketTimer);
|
1312 |
+
askItemWebsocketTimer = null;
|
1313 |
+
}
|
1314 |
+
if(!WpsInvoke.RegWebNotifyEnable){
|
1315 |
+
RegWebNotifyMap[clientType][name]=null;
|
1316 |
+
return ;
|
1317 |
+
}
|
1318 |
+
if (res.data == "WPSInnerMessage_quit" || httpCodeErrorMessageList.indexOf(res.data) != -1 ||!WpsInvoke.RegWebNotifyEnable ) {
|
1319 |
+
if ((!wpsclient || wpsclient.single)) {
|
1320 |
+
window.setTimeout(function() {
|
1321 |
+
askItemWebsocket();
|
1322 |
+
}, 2000);
|
1323 |
+
}
|
1324 |
+
return;
|
1325 |
+
};
|
1326 |
+
window.setTimeout(function() {
|
1327 |
+
askItemWebsocket();
|
1328 |
+
}, 300);
|
1329 |
+
// fix 新版本客户端使用旧版sdk的时候,会出现版本号判断问题
|
1330 |
+
if (serverVersion!== "" && serverVersion !== "wait") {
|
1331 |
+
try {
|
1332 |
+
if (!HeartBeatWorker)
|
1333 |
+
throw new Error();
|
1334 |
+
var resText = JSON.parse(res.data);
|
1335 |
+
paramStr.messageId = resText.msgId;
|
1336 |
+
if (wpsclient) {
|
1337 |
+
if (resText.data != undefined && paramStr.messageId != undefined) // 如果发的数据是字符串化后的json对象,这里的resText.data就是一个json对象,可以输出自己想要的json数据
|
1338 |
+
if (typeof resText.data == 'object')
|
1339 |
+
wpsclient.OnRegWebNotify(JSON.stringify(resText.data))
|
1340 |
+
else
|
1341 |
+
wpsclient.OnRegWebNotify(resText.data)
|
1342 |
+
else
|
1343 |
+
wpsclient.OnRegWebNotify(res.data)
|
1344 |
+
} else {
|
1345 |
+
var func = RegWebNotifyMap[clientType][name]
|
1346 |
+
if (resText.data != undefined && paramStr.messageId != undefined) // 如果发的数据是字符串化后的json对象,这里的resText.data就是一个json对象,可以输出自己想要的json数据
|
1347 |
+
if (typeof resText.data == 'object')
|
1348 |
+
func(JSON.stringify(resText.data))
|
1349 |
+
else
|
1350 |
+
func(resText.data)
|
1351 |
+
else
|
1352 |
+
func(res.data)
|
1353 |
+
}
|
1354 |
+
}
|
1355 |
+
catch (e) {
|
1356 |
+
// 这里做一个容错,即使json解析失败,也要把msgId提取出来,发回给服务端,避免消息清不掉一直重复发送
|
1357 |
+
// 同时把data也取出来,但是格式无法保证
|
1358 |
+
var data
|
1359 |
+
var str = res.data
|
1360 |
+
var idx1 = str.indexOf("\"msgId\"")
|
1361 |
+
var idx2
|
1362 |
+
var idx3
|
1363 |
+
var idx4
|
1364 |
+
var data
|
1365 |
+
if (idx1 != -1) {
|
1366 |
+
idx1 = idx1 + 8
|
1367 |
+
idx2 = str.indexOf("\"data\"") - 2
|
1368 |
+
paramStr.messageId = parseInt(str.substring(idx1, idx2))
|
1369 |
+
idx3 = str.indexOf("\"data\"") + 8
|
1370 |
+
idx4 = str.length - 2
|
1371 |
+
data = str.substring(idx3, idx4)
|
1372 |
+
}
|
1373 |
+
if (wpsclient) {
|
1374 |
+
if (paramStr.messageId !== undefined && data != undefined)
|
1375 |
+
wpsclient.OnRegWebNotify(data)
|
1376 |
+
else
|
1377 |
+
wpsclient.OnRegWebNotify(res.data)
|
1378 |
+
} else {
|
1379 |
+
var func = RegWebNotifyMap[clientType][name]
|
1380 |
+
if (paramStr.messageId !== undefined && data != undefined)
|
1381 |
+
func(data)
|
1382 |
+
else
|
1383 |
+
func(res.data)
|
1384 |
+
}
|
1385 |
+
}
|
1386 |
+
}
|
1387 |
+
else {
|
1388 |
+
var resText = res.data;
|
1389 |
+
paramStr.messageId = resText.msgId;
|
1390 |
+
var resData = decode(resText.data);
|
1391 |
+
if (wpsclient) {
|
1392 |
+
wpsclient.OnRegWebNotify(resData)
|
1393 |
+
}
|
1394 |
+
else {
|
1395 |
+
var func = RegWebNotifyMap[clientType][name]
|
1396 |
+
func(resData)
|
1397 |
+
}
|
1398 |
+
}
|
1399 |
+
};
|
1400 |
+
|
1401 |
+
ws.onclose = function (e) {
|
1402 |
+
// 正常有请求响应,不做处理由onmessage进行递归
|
1403 |
+
if(hasResponse === true){
|
1404 |
+
hasResponse = false;
|
1405 |
+
return
|
1406 |
+
};
|
1407 |
+
// 超时处理
|
1408 |
+
if(isTimeout === true) {
|
1409 |
+
isTimeout = false;
|
1410 |
+
if (bWebNotifyUseTimeout)
|
1411 |
+
window.setTimeout(askItemWebsocket, 300);
|
1412 |
+
else
|
1413 |
+
window.setTimeout(askItemWebsocket, 10000);
|
1414 |
+
return
|
1415 |
+
};
|
1416 |
+
// 异常处理
|
1417 |
+
if (bWebNotifyUseTimeout)
|
1418 |
+
window.setTimeout(askItemWebsocket, 1000);
|
1419 |
+
else
|
1420 |
+
window.setTimeout(askItemWebsocket, 10000);
|
1421 |
+
}
|
1422 |
+
|
1423 |
+
ws.onopen = function(){
|
1424 |
+
if (HeartBeatWorker) {
|
1425 |
+
paramStr.businessId = g_businessId
|
1426 |
+
}
|
1427 |
+
ws.send(JSON.stringify(paramStr));
|
1428 |
+
askItemWebsocketTimer = window.setTimeout(function() {
|
1429 |
+
isTimeout = true;
|
1430 |
+
ws.close();
|
1431 |
+
askItemWebsocketTimer = null;
|
1432 |
+
}, 2000);
|
1433 |
+
};
|
1434 |
+
|
1435 |
+
if (HeartBeatWorker) {
|
1436 |
+
g_LastRegTime = new Date().valueOf();
|
1437 |
+
var param = {
|
1438 |
+
param: {
|
1439 |
+
name: name,
|
1440 |
+
type: clientType,
|
1441 |
+
businessId: g_businessId,
|
1442 |
+
serverId: serverId
|
1443 |
+
},
|
1444 |
+
LastRegTime: g_LastRegTime
|
1445 |
+
}
|
1446 |
+
HeartBeatWorker.postMessage(param)
|
1447 |
+
}
|
1448 |
+
};
|
1449 |
+
if(isReplaceWebSocket()) {
|
1450 |
+
askItemWebsocket();
|
1451 |
+
} else {
|
1452 |
+
askItem();
|
1453 |
+
}
|
1454 |
+
}
|
1455 |
+
|
1456 |
+
/**
|
1457 |
+
* 获取服务端版本号的接口,这里主要是初始化一些参数
|
1458 |
+
* @param {*} clientType 加载项类型, wps / wpp / et
|
1459 |
+
* @param {*} name 加载项名称
|
1460 |
+
* @param {*} func 客户端加载项要执行的方法
|
1461 |
+
* @param {*} param 客户端加载项执行方法的参数
|
1462 |
+
* @param {*} callBack 回调函数
|
1463 |
+
* @param {*} showToFront 设置客户端是否显示到前面
|
1464 |
+
* @param {*} jsPluginsXml 设置加载项路径
|
1465 |
+
* @param {*} silentMode 是否是静默启动
|
1466 |
+
* @param {*} timeout 设置客户端启动超时时间(透传客户端内部执行),单位为ms
|
1467 |
+
* @param {*} startparam 传递给wps客户端的启动参数
|
1468 |
+
*/
|
1469 |
+
function WpsStartWrapVersion(clientType, name, func, param, callBack, showToFront, jsPluginsXml, silentMode, timeout, startparam) {
|
1470 |
+
var paramEx = {
|
1471 |
+
jsPluginsXml: jsPluginsXml ? jsPluginsXml : "",
|
1472 |
+
showToFront: typeof (showToFront) == 'boolean' ? showToFront : true,
|
1473 |
+
param: (typeof (param) == 'object' ? param : JSON.parse(param))
|
1474 |
+
}
|
1475 |
+
var options = {
|
1476 |
+
clientType: clientType,
|
1477 |
+
name: name,
|
1478 |
+
func: func,
|
1479 |
+
param: paramEx,
|
1480 |
+
urlBase: GetUrlBase(),
|
1481 |
+
callBack: callBack,
|
1482 |
+
wpsclient: undefined,
|
1483 |
+
concurrent: true,
|
1484 |
+
silentMode: silentMode,
|
1485 |
+
timeout: timeout,
|
1486 |
+
startparam: startparam,
|
1487 |
+
}
|
1488 |
+
WpsStartWrapVersionInner(options);
|
1489 |
+
}
|
1490 |
+
|
1491 |
+
//从外部浏览器远程调用 WPS 加载项中的方法
|
1492 |
+
var WpsInvoke = {
|
1493 |
+
InvokeAsHttp: WpsStartWrapVersion,
|
1494 |
+
InvokeAsHttps: WpsStartWrapVersion,
|
1495 |
+
RegWebNotify: RegWebNotify,
|
1496 |
+
ClientType: {
|
1497 |
+
wps: "wps",
|
1498 |
+
et: "et",
|
1499 |
+
wpp: "wpp",
|
1500 |
+
pdf: "pdf"
|
1501 |
+
},
|
1502 |
+
CreateXHR: getHttpObj,
|
1503 |
+
IsClientRunning: IsClientRunning,
|
1504 |
+
GetVersion: GetVersion,
|
1505 |
+
RegWebNotifyEnable:true
|
1506 |
+
}
|
1507 |
+
|
1508 |
+
/**
|
1509 |
+
* @constructor WpsClient wps客户端
|
1510 |
+
* @param {string} clientType 必传参数,加载项类型,有效值为"wps","wpp","et";分别表示文字,演示,电子表格
|
1511 |
+
*/
|
1512 |
+
function WpsClient(clientType) {
|
1513 |
+
/**
|
1514 |
+
* 设置RegWebNotify的回调函数,加载项给业务端发消息通过该函数
|
1515 |
+
* @memberof WpsClient
|
1516 |
+
* @member onMessage
|
1517 |
+
*/
|
1518 |
+
this.onMessage;
|
1519 |
+
|
1520 |
+
/**
|
1521 |
+
* 设置加载项路径
|
1522 |
+
* @memberof WpsClient
|
1523 |
+
* @member jsPluginsXml
|
1524 |
+
*/
|
1525 |
+
this.jsPluginsXml;
|
1526 |
+
|
1527 |
+
/**
|
1528 |
+
* 内部成员,外部无需调用
|
1529 |
+
*/
|
1530 |
+
this.notifyRegsitered = false;
|
1531 |
+
this.clientId = "";
|
1532 |
+
this.concurrent = true;
|
1533 |
+
this.clientType = clientType;
|
1534 |
+
|
1535 |
+
/**
|
1536 |
+
* 内部函数,外部无需调用
|
1537 |
+
* @param {*} options
|
1538 |
+
*/
|
1539 |
+
this.initWpsClient = function (options) {
|
1540 |
+
options.clientType = this.clientType
|
1541 |
+
options.wpsclient = this
|
1542 |
+
options.concurrent = this.concurrent
|
1543 |
+
WpsStartWrapVersionInner(options)
|
1544 |
+
}
|
1545 |
+
|
1546 |
+
/**
|
1547 |
+
* 以http启动
|
1548 |
+
* @param {string} name 加载项名称
|
1549 |
+
* @param {string} func 要调用的加载项中的函数行
|
1550 |
+
* @param {string} param 在加载项中执行函数func要传递的数据
|
1551 |
+
* @param {function({int, string})} callBack 回调函数,status = 0 表示成功,失败请查看message信息
|
1552 |
+
* @param {bool} showToFront 设置wps是否���示到前面来
|
1553 |
+
* @param {*} timeout 设置客户端启动超时时间(透传客户端内部执行),单位为ms
|
1554 |
+
* @param {*} startparam 传递给wps客户端的启动参数
|
1555 |
+
* @return {string} "Failed to send message to WPS." 发送消息失败,客户端已关闭;
|
1556 |
+
* "WPS Addon is not response." 加载项阻塞,函数执行失败
|
1557 |
+
*/
|
1558 |
+
this.InvokeAsHttp = function (name, func, param, callBack, showToFront, timeout, startparam) {
|
1559 |
+
function clientCallback(res) {
|
1560 |
+
//this不是WpsClient,是options对象
|
1561 |
+
if (res.status !== 0 || serverVersion < "1.0.1" || this.wpsclient.single == true) {
|
1562 |
+
if (callBack)
|
1563 |
+
callBack(res);
|
1564 |
+
if (serverVersion < "1.0.1" || this.wpsclient.single == true)
|
1565 |
+
RegWebNotify(clientType, name, this.wpsclient.onMessage)
|
1566 |
+
return;
|
1567 |
+
}
|
1568 |
+
// fix 新版本客户端使用旧版sdk的时候,会出现版本号判断问题
|
1569 |
+
if (serverVersion!== "" && serverVersion !== "wait") {
|
1570 |
+
try {
|
1571 |
+
var resObject = JSON.parse(res.response);
|
1572 |
+
if (this.wpsclient.clientId == "") {
|
1573 |
+
this.wpsclient.clientId = resObject.clientId;
|
1574 |
+
}
|
1575 |
+
if (typeof resObject.data == "object")
|
1576 |
+
res.response = JSON.stringify(resObject.data);
|
1577 |
+
else
|
1578 |
+
res.response = resObject.data;
|
1579 |
+
}
|
1580 |
+
catch (e) {
|
1581 |
+
var str = res.response
|
1582 |
+
var idx1 = str.indexOf("\"clientId\":\"{")
|
1583 |
+
var idx2
|
1584 |
+
var idx3
|
1585 |
+
var idx4
|
1586 |
+
if (idx1 != -1) {
|
1587 |
+
idx1 = idx1 + ("\"clientId\":\"{").length - 1
|
1588 |
+
idx2 = str.indexOf("\"data\":") - 3
|
1589 |
+
if (this.wpsclient.clientId == "") {
|
1590 |
+
this.wpsclient.clientId = str.substring(idx1, idx2);
|
1591 |
+
}
|
1592 |
+
idx3 = str.indexOf("\"data\":") + ("\"data\":").length
|
1593 |
+
idx4 = str.length - 1
|
1594 |
+
if (idx3 < idx4)
|
1595 |
+
res.response = str.substring(idx3, idx4)
|
1596 |
+
else
|
1597 |
+
res.response = "";
|
1598 |
+
}
|
1599 |
+
}
|
1600 |
+
}
|
1601 |
+
else {
|
1602 |
+
var resObject = JSON.parse(res.response);
|
1603 |
+
if (this.wpsclient.clientId == "") {
|
1604 |
+
this.wpsclient.clientId = resObject.clientId;
|
1605 |
+
}
|
1606 |
+
res.response = decode(resObject.data);
|
1607 |
+
}
|
1608 |
+
if (IEVersion() < 10)
|
1609 |
+
eval(" res.response = '" + res.response + "';");
|
1610 |
+
if (callBack)
|
1611 |
+
callBack(res);
|
1612 |
+
this.wpsclient.RegWebNotify(name);
|
1613 |
+
}
|
1614 |
+
var paramEx = {
|
1615 |
+
jsPluginsXml: this.jsPluginsXml ? this.jsPluginsXml : "",
|
1616 |
+
showToFront: typeof (showToFront) == 'boolean' ? showToFront : true,
|
1617 |
+
param: (typeof (param) == 'object' ? param : JSON.parse(param))
|
1618 |
+
}
|
1619 |
+
this.initWpsClient({
|
1620 |
+
name: name,
|
1621 |
+
func: func,
|
1622 |
+
param: paramEx,
|
1623 |
+
urlBase: GetUrlBase(),
|
1624 |
+
callBack: clientCallback,
|
1625 |
+
timeout: timeout,
|
1626 |
+
startparam: startparam,
|
1627 |
+
})
|
1628 |
+
}
|
1629 |
+
|
1630 |
+
/**
|
1631 |
+
* 以https启动
|
1632 |
+
* @param {string} name 加载项名称
|
1633 |
+
* @param {string} func 要调用的加载项中的函数行
|
1634 |
+
* @param {string} param 在加载项中执行函数func要传递的数据
|
1635 |
+
* @param {function({int, string})} callBack 回调函数,status = 0 表示成功,失败请查看message信息
|
1636 |
+
* @param {*} timeout 设置客户端启动超时时间(透传客户端内部执行),单位为ms
|
1637 |
+
* @param {*} startparam 传递给wps客户端的启动参数
|
1638 |
+
* @param {bool} showToFront 设置wps是否显示到前面来
|
1639 |
+
*/
|
1640 |
+
this.InvokeAsHttps = function (name, func, param, callBack, showToFront, timeout, startparam) {
|
1641 |
+
var paramEx = {
|
1642 |
+
jsPluginsXml: this.jsPluginsXml ? this.jsPluginsXml : "",
|
1643 |
+
showToFront: typeof (showToFront) == 'boolean' ? showToFront : true,
|
1644 |
+
param: (typeof (param) == 'object' ? param : JSON.parse(param))
|
1645 |
+
}
|
1646 |
+
this.initWpsClient({
|
1647 |
+
name: name,
|
1648 |
+
func: func,
|
1649 |
+
param: paramEx,
|
1650 |
+
urlBase: GetUrlBase(),
|
1651 |
+
callBack: callBack,
|
1652 |
+
timeout: timeout,
|
1653 |
+
startparam: startparam,
|
1654 |
+
})
|
1655 |
+
}
|
1656 |
+
|
1657 |
+
/**
|
1658 |
+
* 内部函数,外部无需调用
|
1659 |
+
* @param {*} name
|
1660 |
+
*/
|
1661 |
+
this.RegWebNotify = function (name) {
|
1662 |
+
RegWebNotify(this.clientType, name, null, this);
|
1663 |
+
}
|
1664 |
+
|
1665 |
+
/**
|
1666 |
+
* 消息注册函数的回调函数
|
1667 |
+
* @param {*} message 客户端发来的消息
|
1668 |
+
*/
|
1669 |
+
this.OnRegWebNotify = function (message) {
|
1670 |
+
if (this.onMessage)
|
1671 |
+
this.onMessage(message)
|
1672 |
+
}
|
1673 |
+
|
1674 |
+
/**
|
1675 |
+
* 以静默模式启动客户端
|
1676 |
+
* @param {string} name 必传参数,加载项名称
|
1677 |
+
* @param {*} timeout 设置客户端启动超时时间(透传客户端内部执行),单位为ms
|
1678 |
+
* @param {*} startparam 传递给wps客户端的启动参数
|
1679 |
+
* @param {function({int, string})} [callBack] 回调函数,status = 0 表示成功,失败请查看message信息
|
1680 |
+
*/
|
1681 |
+
this.StartWpsInSilentMode = function (name, callBack, timeout, startparam) {
|
1682 |
+
function initCallback(res) {
|
1683 |
+
//this不是WpsClient,是options对象
|
1684 |
+
if (res.status !== 0 || serverVersion < "1.0.1" || this.wpsclient.single == true) {
|
1685 |
+
if (callBack)
|
1686 |
+
callBack(res);
|
1687 |
+
if (serverVersion < "1.0.1" || this.wpsclient.single == true)
|
1688 |
+
RegWebNotify(clientType, name, this.wpsclient.onMessage)
|
1689 |
+
return;
|
1690 |
+
}
|
1691 |
+
var jsonObj = JSON.parse(res.response);
|
1692 |
+
if (this.wpsclient.clientId == "") {
|
1693 |
+
this.wpsclient.clientId = jsonObj.clientId;
|
1694 |
+
}
|
1695 |
+
// fix 新版本客户端使用旧版sdk的时候,会出现版本号判断问题
|
1696 |
+
if (serverVersion!== "" && serverVersion !== "wait") {
|
1697 |
+
res.response = JSON.stringify(jsonObj.data);
|
1698 |
+
}
|
1699 |
+
else {
|
1700 |
+
res.response = decode(jsonObj.data);
|
1701 |
+
}
|
1702 |
+
if (callBack) {
|
1703 |
+
callBack(res);
|
1704 |
+
}
|
1705 |
+
this.wpsclient.RegWebNotify(name);
|
1706 |
+
}
|
1707 |
+
var paramEx = {
|
1708 |
+
jsPluginsXml: this.jsPluginsXml,
|
1709 |
+
showToFront: false,
|
1710 |
+
param: { status: "InitInSilentMode" }
|
1711 |
+
}
|
1712 |
+
this.silentMode = true;
|
1713 |
+
this.initWpsClient({
|
1714 |
+
name: name,
|
1715 |
+
func: "",
|
1716 |
+
param: paramEx,
|
1717 |
+
urlBase: GetUrlBase(),
|
1718 |
+
callBack: initCallback,
|
1719 |
+
timeout: timeout,
|
1720 |
+
startparam: startparam,
|
1721 |
+
})
|
1722 |
+
}
|
1723 |
+
|
1724 |
+
/**
|
1725 |
+
* 显示客户端到最前面
|
1726 |
+
* @param {string} name 必传参数,加载项名称
|
1727 |
+
* @param {function({int, string})} [callBack] 回调函数
|
1728 |
+
*/
|
1729 |
+
this.ShowToFront = function (name, callBack) {
|
1730 |
+
if (serverVersion < "1.0.1") {
|
1731 |
+
if (callBack) {
|
1732 |
+
callBack({
|
1733 |
+
status: 4,
|
1734 |
+
message: "当前客户端不支持,请升级客户端"
|
1735 |
+
});
|
1736 |
+
return;
|
1737 |
+
}
|
1738 |
+
return;
|
1739 |
+
}
|
1740 |
+
if (this.clientId == "") {
|
1741 |
+
if (callBack) callBack({
|
1742 |
+
status: 3,
|
1743 |
+
message: "没有静默启动客户端"
|
1744 |
+
});
|
1745 |
+
return;
|
1746 |
+
}
|
1747 |
+
var paramEx = {
|
1748 |
+
jsPluginsXml: "",
|
1749 |
+
showToFront: true,
|
1750 |
+
param: { status: "ShowToFront" }
|
1751 |
+
}
|
1752 |
+
this.initWpsClient({
|
1753 |
+
name: name,
|
1754 |
+
func: "",
|
1755 |
+
param: paramEx,
|
1756 |
+
urlBase: GetUrlBase(),
|
1757 |
+
callBack: callBack
|
1758 |
+
})
|
1759 |
+
}
|
1760 |
+
|
1761 |
+
/**
|
1762 |
+
* 关闭未显示出来的静默启动客户端
|
1763 |
+
* @param {string} name 必传参数,加载项名称
|
1764 |
+
* @param {function({int, string})} [callBack] 回调函数
|
1765 |
+
*/
|
1766 |
+
this.CloseSilentClient = function (name, callBack) {
|
1767 |
+
if (serverVersion < "1.0.1") {
|
1768 |
+
if (callBack) {
|
1769 |
+
callBack({
|
1770 |
+
status: 4,
|
1771 |
+
message: "当前客户端不支持,请升级客户端"
|
1772 |
+
});
|
1773 |
+
return;
|
1774 |
+
}
|
1775 |
+
return;
|
1776 |
+
}
|
1777 |
+
if (this.clientId == "") {
|
1778 |
+
if (callBack) callBack({
|
1779 |
+
status: 3,
|
1780 |
+
message: "没有静默启动客户端"
|
1781 |
+
});
|
1782 |
+
return;
|
1783 |
+
}
|
1784 |
+
var paramEx = {
|
1785 |
+
jsPluginsXml: "",
|
1786 |
+
showToFront: false,
|
1787 |
+
param: undefined
|
1788 |
+
}
|
1789 |
+
var func;
|
1790 |
+
if (this.clientType == "wps")
|
1791 |
+
func = "wps.WpsApplication().Quit"
|
1792 |
+
else if (this.clientType == "et")
|
1793 |
+
func = "wps.EtApplication().Quit"
|
1794 |
+
else if (this.clientType == "wpp")
|
1795 |
+
func = "wps.WppApplication().Quit"
|
1796 |
+
|
1797 |
+
function closeSilentClient(res) {
|
1798 |
+
if (res.status == 0)
|
1799 |
+
this.wpsclient.clientId = ""
|
1800 |
+
if (callBack) callBack(res);
|
1801 |
+
return;
|
1802 |
+
}
|
1803 |
+
this.initWpsClient({
|
1804 |
+
name: name,
|
1805 |
+
func: func,
|
1806 |
+
param: paramEx,
|
1807 |
+
urlBase: GetUrlBase(),
|
1808 |
+
callBack: closeSilentClient
|
1809 |
+
})
|
1810 |
+
}
|
1811 |
+
|
1812 |
+
/**
|
1813 |
+
* 当前客户端是否在运行,使用WpsClient.IsClientRunning()进行调用
|
1814 |
+
* @param {function({int, string})} [callBack] 回调函数,"Client is running." 客户端正在运行
|
1815 |
+
* "Client is not running." 客户端没有运行
|
1816 |
+
*/
|
1817 |
+
this.IsClientRunning = function (callBack) {
|
1818 |
+
if (serverVersion < "1.0.1") {
|
1819 |
+
if (callBack) {
|
1820 |
+
callBack({
|
1821 |
+
status: 4,
|
1822 |
+
message: "当前客户端不支持,请升级客户端"
|
1823 |
+
});
|
1824 |
+
return;
|
1825 |
+
}
|
1826 |
+
return;
|
1827 |
+
}
|
1828 |
+
IsClientRunning(this.clientType, callBack, this)
|
1829 |
+
}
|
1830 |
+
}
|
1831 |
+
|
1832 |
+
/**
|
1833 |
+
* 初始化sdk,用来减少在服务进程启动时自定义协议弹框出现的次数
|
1834 |
+
*/
|
1835 |
+
var g_isSdkInited = false;
|
1836 |
+
function InitSdk(bMultiUser) {
|
1837 |
+
g_isSdkInited = false;
|
1838 |
+
var url = GetUrlBase() + "/version";
|
1839 |
+
startWps({
|
1840 |
+
url: url,
|
1841 |
+
sendData: JSON.stringify({ serverId: serverId }),
|
1842 |
+
callBack: function (res) {
|
1843 |
+
if ((!serverId && !bMultiUser) || bMultiUser)
|
1844 |
+
g_isSdkInited = true;
|
1845 |
+
if (res.status !== 0 && res.message !== "Subserver not available.") {
|
1846 |
+
serverVersion = "wait"
|
1847 |
+
return;
|
1848 |
+
}
|
1849 |
+
if (res.response && serverVersion == "wait"){
|
1850 |
+
serverVersion = res.response;
|
1851 |
+
sessionStorage.setItem('serverVersion', serverVersion);
|
1852 |
+
}
|
1853 |
+
|
1854 |
+
},
|
1855 |
+
tryCount: 1,
|
1856 |
+
bPop: false,
|
1857 |
+
concurrent: true,
|
1858 |
+
timeout: 1000
|
1859 |
+
});
|
1860 |
+
}
|
1861 |
+
InitSdk(false);
|
1862 |
+
|
1863 |
+
function GetVersion(callBack) {
|
1864 |
+
var url = GetUrlBase() + "/version";
|
1865 |
+
startWps({
|
1866 |
+
url: url,
|
1867 |
+
data: "",
|
1868 |
+
callBack: function (res) {
|
1869 |
+
callBack && callBack(res);
|
1870 |
+
if (res.status !== 0 && res.message !== "Subserver not available.") {
|
1871 |
+
serverVersion = "wait"
|
1872 |
+
return;
|
1873 |
+
}
|
1874 |
+
if (res.response && serverVersion == "wait"){
|
1875 |
+
serverVersion = res.response;
|
1876 |
+
sessionStorage.setItem('serverVersion', serverVersion);
|
1877 |
+
}
|
1878 |
+
},
|
1879 |
+
tryCount: 4,
|
1880 |
+
bPop: true,
|
1881 |
+
timeout: 5000
|
1882 |
+
});
|
1883 |
+
}
|
1884 |
+
if (typeof noGlobal === "undefined") {
|
1885 |
+
window.WpsInvoke = WpsInvoke;
|
1886 |
+
window.WpsClient = WpsClient;
|
1887 |
+
window.WebNotifyUseTimeout = WebNotifyUseTimeout;
|
1888 |
+
window.EnableMultiUser = EnableMultiUser;
|
1889 |
+
}
|
1890 |
+
|
1891 |
+
/**
|
1892 |
+
* 当前客户端是否在运行,使用WpsInvoke.IsClientRunning()进行调用
|
1893 |
+
* @param {string} clientType 加载项类型
|
1894 |
+
* @param {function} [callBack] 回调函数,"Client is running." 客户端正在运行
|
1895 |
+
* "Client is not running." 客户端没有运行
|
1896 |
+
*/
|
1897 |
+
function IsClientRunning(clientType, callBack, wpsclient) {
|
1898 |
+
var url = GetUrlBase() + "/isRunning";
|
1899 |
+
var wrapper = {
|
1900 |
+
id: wpsclient == undefined ? undefined : wpsclient.clientId,
|
1901 |
+
app: clientType,
|
1902 |
+
serverId: serverId
|
1903 |
+
}
|
1904 |
+
wrapper = JSON.stringify(wrapper);
|
1905 |
+
startWps({
|
1906 |
+
url: url,
|
1907 |
+
sendData: wrapper,
|
1908 |
+
callBack: callBack,
|
1909 |
+
tryCount: 1,
|
1910 |
+
bPop: false,
|
1911 |
+
timeout: 2000,
|
1912 |
+
concurrent: true,
|
1913 |
+
wpsclient: wpsclient
|
1914 |
+
});
|
1915 |
+
}
|
1916 |
+
|
1917 |
+
/**
|
1918 |
+
* 获取publish.xml的内容
|
1919 |
+
* @param {*} callBack 回调函数
|
1920 |
+
*/
|
1921 |
+
function WpsAddonGetAllConfigInner(callBack) {
|
1922 |
+
var options = {
|
1923 |
+
url: GetUrlBase() + "/publishlist",
|
1924 |
+
type: "POST",
|
1925 |
+
sendData: JSON.stringify({ serverId: serverId }),
|
1926 |
+
callBack: callBack,
|
1927 |
+
tryCount: 3,
|
1928 |
+
bPop: true,
|
1929 |
+
timeout: 5000,
|
1930 |
+
concurrent: true,
|
1931 |
+
}
|
1932 |
+
startWps(options);
|
1933 |
+
}
|
1934 |
+
|
1935 |
+
/**
|
1936 |
+
* 先获取一下版本号
|
1937 |
+
* @param {*} callBack 回调函数
|
1938 |
+
*/
|
1939 |
+
function WpsAddonGetAllConfig(callBack) {
|
1940 |
+
var options = {
|
1941 |
+
callBack: callBack,
|
1942 |
+
isPublish: true,
|
1943 |
+
urlBase: GetUrlBase()
|
1944 |
+
}
|
1945 |
+
WpsStartWrapVersionInner(options);
|
1946 |
+
}
|
1947 |
+
|
1948 |
+
/**
|
1949 |
+
* 检查ribbon.xml文件是否有效
|
1950 |
+
* @param {*} element 参数对象
|
1951 |
+
* @param {*} callBack 回调函数
|
1952 |
+
*/
|
1953 |
+
function WpsAddonVerifyStatus(element, callBack) {
|
1954 |
+
var xmlReq = getHttpObj();
|
1955 |
+
var offline = element.online === "false";
|
1956 |
+
var url = offline ? element.url : element.url + "ribbon.xml";
|
1957 |
+
xmlReq.open("POST", GetUrlBase() + "/redirect/runParams");
|
1958 |
+
xmlReq.onload = function (res) {
|
1959 |
+
if (offline && !res.target.response.startsWith("7z")) {
|
1960 |
+
callBack({ status: 1, msg: "不是有效的7z格式" + url });
|
1961 |
+
} else if (!offline && !res.target.response.startsWith("<customUI")) {
|
1962 |
+
callBack({ status: 1, msg: "不是有效的ribbon.xml, " + url })
|
1963 |
+
} else {
|
1964 |
+
callBack({ status: 0, msg: "OK" })
|
1965 |
+
}
|
1966 |
+
}
|
1967 |
+
xmlReq.onerror = function (res) {
|
1968 |
+
xmlReq.bTimeout = true;
|
1969 |
+
callBack({ status: 2, msg: "网页路径不可访问,如果是跨域问题,不影响使用" + url })
|
1970 |
+
}
|
1971 |
+
xmlReq.ontimeout = function (res) {
|
1972 |
+
xmlReq.bTimeout = true;
|
1973 |
+
callBack({ status: 3, msg: "访问超时" + url })
|
1974 |
+
}
|
1975 |
+
if (IEVersion() < 10) {
|
1976 |
+
xmlReq.onreadystatechange = function () {
|
1977 |
+
if (xmlReq.readyState != 4)
|
1978 |
+
return;
|
1979 |
+
if (xmlReq.bTimeout) {
|
1980 |
+
return;
|
1981 |
+
}
|
1982 |
+
if (xmlReq.status === 200)
|
1983 |
+
xmlReq.onload();
|
1984 |
+
else
|
1985 |
+
xmlReq.onerror();
|
1986 |
+
}
|
1987 |
+
}
|
1988 |
+
xmlReq.timeout = 5000;
|
1989 |
+
var data = {
|
1990 |
+
method: "get",
|
1991 |
+
url: url,
|
1992 |
+
data: ""
|
1993 |
+
}
|
1994 |
+
var sendData = FormatSendData(data)
|
1995 |
+
xmlReq.send(sendData);
|
1996 |
+
}
|
1997 |
+
|
1998 |
+
function WpsAddonVerifyStatusWebSocket(element, callBack){
|
1999 |
+
var timer = null
|
2000 |
+
var ws = getWebsocketObj();
|
2001 |
+
var offline = element.online === "false";
|
2002 |
+
var url = offline ? element.url : element.url + "ribbon.xml";
|
2003 |
+
ws.connect(GetUrlBase() + "/redirect/runParams");
|
2004 |
+
ws.onmessage = function (res) {
|
2005 |
+
if(timer !== null) {
|
2006 |
+
clearTimeout(timer);
|
2007 |
+
timer = null;
|
2008 |
+
};
|
2009 |
+
if (offline && !res.data.startsWith("7z")) {
|
2010 |
+
callBack({ status: 1, msg: "不是有效的7z格式" + url });
|
2011 |
+
} else if (!offline && !res.data.startsWith("<customUI")) {
|
2012 |
+
callBack({ status: 1, msg: "不是有效的ribbon.xml, " + url })
|
2013 |
+
} else {
|
2014 |
+
callBack({ status: 0, msg: "OK" })
|
2015 |
+
}
|
2016 |
+
ws.close();
|
2017 |
+
}
|
2018 |
+
ws.onerror = function () {
|
2019 |
+
ws.bTimeout = true;
|
2020 |
+
callBack({ status: 2, msg: "网页路径不可访问,如果是跨域问题,不影响使用" + url })
|
2021 |
+
}
|
2022 |
+
var data = {
|
2023 |
+
method: "get",
|
2024 |
+
url: url,
|
2025 |
+
data: ""
|
2026 |
+
}
|
2027 |
+
var sendData = FormatSendData(data)
|
2028 |
+
ws.onopen = function() {
|
2029 |
+
ws.send(sendData);
|
2030 |
+
}
|
2031 |
+
timer = setTimeout(function() {
|
2032 |
+
callBack({ status: 3, msg: "访问超时" + url });
|
2033 |
+
timer = null;
|
2034 |
+
ws.close();
|
2035 |
+
}, 5000)
|
2036 |
+
}
|
2037 |
+
|
2038 |
+
/**
|
2039 |
+
* 部署加载项,包括启动enable / disable禁用 / disableall禁用所有
|
2040 |
+
* @param {*} element 参数对象
|
2041 |
+
* @param {*} cmd 具体操作,enable / disable / disableall
|
2042 |
+
* @param {*} callBack 回调函数
|
2043 |
+
*/
|
2044 |
+
function WpsAddonHandleEx(element, cmd, callBack) {
|
2045 |
+
var data = FormatData(element, cmd);
|
2046 |
+
startWps({
|
2047 |
+
url: GetUrlBase() + "/deployaddons/runParams",
|
2048 |
+
type: "POST",
|
2049 |
+
sendData: data,
|
2050 |
+
callBack: callBack,
|
2051 |
+
tryCount: 3,
|
2052 |
+
bPop: true,
|
2053 |
+
timeout: 0,
|
2054 |
+
concurrent: true
|
2055 |
+
});
|
2056 |
+
}
|
2057 |
+
|
2058 |
+
/**
|
2059 |
+
* 启用加载项
|
2060 |
+
* @param {*} element 参数对象
|
2061 |
+
* @param {*} callBack 回调函数
|
2062 |
+
*/
|
2063 |
+
function WpsAddonEnable(element, callBack) {
|
2064 |
+
WpsAddonHandleEx(element, "enable", callBack)
|
2065 |
+
}
|
2066 |
+
|
2067 |
+
/**
|
2068 |
+
* 禁用加载项
|
2069 |
+
* @param {*} element 参数对象
|
2070 |
+
* @param {*} callBack 回调函数
|
2071 |
+
*/
|
2072 |
+
function WpsAddonDisable(element, callBack) {
|
2073 |
+
WpsAddonHandleEx(element, "disable", callBack)
|
2074 |
+
}
|
2075 |
+
|
2076 |
+
/**
|
2077 |
+
* 禁用所有加载项
|
2078 |
+
* @param {*} element
|
2079 |
+
* @param {*} callBack
|
2080 |
+
*/
|
2081 |
+
function WpsAddonDisableAll(element, callBack) {
|
2082 |
+
WpsAddonHandleEx(element, "disableall", callBack)
|
2083 |
+
}
|
2084 |
+
|
2085 |
+
/**
|
2086 |
+
* 生成json格式的数据
|
2087 |
+
* @param {*} element 参数对象
|
2088 |
+
* @param {*} cmd 具体操作,enable / disable / disableall
|
2089 |
+
* @returns base64编码后的数据
|
2090 |
+
*/
|
2091 |
+
function FormatData(element, cmd) {
|
2092 |
+
var data = {
|
2093 |
+
"cmd": cmd, //"enable", 启用, "disable", 禁用, "disableall", 禁用所有
|
2094 |
+
"name": element.name,
|
2095 |
+
"url": element.url,
|
2096 |
+
"addonType": element.addonType,
|
2097 |
+
"online": element.online,
|
2098 |
+
"version": element.version,
|
2099 |
+
"time": new Date().getTime()
|
2100 |
+
}
|
2101 |
+
return FormatSendData(data);
|
2102 |
+
}
|
2103 |
+
|
2104 |
+
/**
|
2105 |
+
* 将json格式的数据字符串化,并进行base64编码
|
2106 |
+
* @param {*} data 数据
|
2107 |
+
* @returns base64编码后的数据
|
2108 |
+
*/
|
2109 |
+
function FormatSendData(data) {
|
2110 |
+
var strData = JSON.stringify(data);
|
2111 |
+
if (IEVersion() < 10)
|
2112 |
+
eval("strData = '" + JSON.stringify(strData) + "';");
|
2113 |
+
|
2114 |
+
if (serverVersion >= "1.0.2" && serverId != undefined) {
|
2115 |
+
var base64Data = encode(strData);
|
2116 |
+
return JSON.stringify({
|
2117 |
+
serverId: serverId,
|
2118 |
+
data: base64Data
|
2119 |
+
})
|
2120 |
+
}
|
2121 |
+
else {
|
2122 |
+
return encode(strData);
|
2123 |
+
}
|
2124 |
+
}
|
2125 |
+
|
2126 |
+
var verifyStatus = function(){};
|
2127 |
+
if(isReplaceWebSocket()) {
|
2128 |
+
verifyStatus = WpsAddonVerifyStatusWebSocket
|
2129 |
+
} else {
|
2130 |
+
verifyStatus = WpsAddonVerifyStatus
|
2131 |
+
}
|
2132 |
+
|
2133 |
+
//管理 WPS 加载项
|
2134 |
+
var WpsAddonMgr = {
|
2135 |
+
getAllConfig: WpsAddonGetAllConfig,
|
2136 |
+
verifyStatus: verifyStatus,
|
2137 |
+
enable: WpsAddonEnable,
|
2138 |
+
disable: WpsAddonDisable,
|
2139 |
+
disableall: WpsAddonDisableAll
|
2140 |
+
}
|
2141 |
+
|
2142 |
+
if (typeof noGlobal === "undefined") {
|
2143 |
+
window.WpsAddonMgr = WpsAddonMgr;
|
2144 |
+
}
|
2145 |
+
return { WpsInvoke: WpsInvoke, WpsClient: WpsClient, WebNotifyUseTimeout: WebNotifyUseTimeout, EnableMultiUser: EnableMultiUser, WpsAddonMgr: WpsAddonMgr, version: "1.0.33" };
|
2146 |
+
});
|
2147 |
+
|
2148 |
+
/**
|
2149 |
+
* 改动时间:2022-11-28 19:06
|
2150 |
+
* 改动说明:1、调整心跳触发时机,确认云服务版本号后才触发
|
2151 |
+
* 2、轮询客户端消息赋予businessId调整至请求发送前。避免心跳没创建的异常情况
|
2152 |
+
* 改动影响:http&ws下,心跳触发是否正常
|
2153 |
+
*/
|