fs-danaus
2022-07-06 6fe1e6dbec57bbd10ba1bbcf3347fa7f4492e553
提交 | 用户 | age
a6a76f 1 var timeron=null;
6fe1e6 2 function initWebsocket(hostUrl,userCode,dbId,sessionId,userType) {
a6a76f 3 //  初始化weosocket
6fe1e6 4     var userFromType=1;
F 5     if(userType!=undefined) userFromType=userType;
a6a76f 6     var localHostUrl =  hostUrl; 
F 7     var localUserCode = userCode ;
8     var localDbId = dbId;
9     var localSessionId = sessionId ;
6fe1e6 10     var info = '/ws/websocketMessage/'+localUserCode + '/'+ localDbId+'/' + localSessionId+'/'+userFromType ;
a6a76f 11     var url = localHostUrl + info ;
F 12     websocket = new WebSocket(url);
13     
14     websocket.onopen = function () {
15         //  连接建立之后执行
6fe1e6 16         //console.log('WebSocket连接成功');
a6a76f 17         // this.connectUser()
F 18         // this.$indicator.close()
19         clearTimeout(timeron);//by danaus 2020/3/20 20:42
20       }
21
22       websocket.onerror = function (e) {
23           //  连接建立失败3S重连
24           timeron=setTimeout(function () {
6fe1e6 25               initWebsocket(localHostUrl,localUserCode,localDbId,localSessionId,userType);
a6a76f 26           }, 3000);
6fe1e6 27           console.log('连接建立失败,3秒后重连', e);
a6a76f 28         };
F 29
30         websocket.onclose = function (e) {
31           //  连接建立失败3S重连
32           // setTimeout(function () {
33           // initWebsocket(localHostUrl,localUserCode,localDbId,localSessionId);
34           // }, 3000);
6fe1e6 35             if (webSocket != null){
F 36                 websocket.close();
37             }
a6a76f 38           console.log('断开连接', e);
F 39         };
40       
41
42       // 接收消息
43       websocket.onmessage = function (e) {
6fe1e6 44             var json= JSON.parse(e.data);
F 45             if(json.info.msgType==6014){
46                 //重定向到登录页面
47                 location="/login.jsp?m=6015&d="+json.info.dbId;
48             }else if(json.info.msgType==6015){
49                 //刷新当前页面
50                 location="/login.jsp";
51             }else if(json.info.msgType==6002){
52                 //右下角弹窗
53
54             }
55          // console.log('接收消息', json);
a6a76f 56       }
F 57 }