Browse Source

Merge branch 'houfix/修复云机触控自动重连' of Software/android-cloud-H5 into develop

zengzhixiang 2 years ago
parent
commit
e67fa35acb
2 changed files with 30 additions and 16 deletions
  1. 16 8
      static/screenAndroid/WXdraw.js
  2. 14 8
      static/screenIos/WXdraw.js

+ 16 - 8
static/screenAndroid/WXdraw.js

@@ -36,10 +36,10 @@ function changIsControl(value) {
 
 function throttle(fn, delay) {
   var flag = true;
-  errorTime += delay;
   return () => {
     if (!flag) return;
     flag = false;
+    errorTime += delay;
     timer = setTimeout(() => {
       fn();
       flag = true;
@@ -47,6 +47,10 @@ function throttle(fn, delay) {
   };
 }
 
+const throttleDoConnectDirectives = throttle(() => {
+  doConnectDirectives();
+}, 100);
+
 function doConnectDirectives() {
   videoWidth = Number(resolvingPower) ? Number(resolvingPower) : 720;
   videoHeight = videoWidth === 720 ? 1280 : 1920;
@@ -54,6 +58,7 @@ function doConnectDirectives() {
   wsss.binaryType = 'arraybuffer';
 
   wsss.onopen = function () {
+    errorTime = 0;
     // 进入发起询问
     var pings2 = {
       type: 'forwardMsg',
@@ -63,6 +68,7 @@ function doConnectDirectives() {
       },
     };
     wsss.send(JSON.stringify(pings2));
+
     wsss.send(
       JSON.stringify({
         type: 'getPhoneSize',
@@ -70,20 +76,22 @@ function doConnectDirectives() {
     );
   };
   wsss.onerror = function (e) {
-    wsss.close();
-    throttle(doConnectDirectives, 100);
-    if (errorTime > 1000) {
-      quit();
-    }
+    // console.log('🚀 ~ file: WXdraw.js ~ line 82 ~ onerror ~ e', e);
+    wsss.close(1006);
+    // throttle(doConnectDirectives, 100);
+    // if (errorTime > 1000) {
+    //   quit();
+    // }
   };
   wsss.onclose = function (e) {
-    // console.log('🚀 ~ file: WXdraw.js ~ line 93 ~ onclose ~ e', e.code);
+    // console.log('🚀 ~ file: WXdraw.js ~ line 93 ~ onclose ~ e', e);
     // new WebSocket(e.)
     // doConnectDirectives();
     if (e.code === 1006) {
       // 异常关闭,重连
+      throttleDoConnectDirectives();
       // doConnectDirectives();
-      throttle(doConnectDirectives, 100);
+      // throttle(doConnectDirectives, 100);
       if (errorTime > 1000) {
         quit();
       }

+ 14 - 8
static/screenIos/WXdraw.js

@@ -34,10 +34,10 @@ function changIsControl(value) {
 
 function throttle(fn, delay) {
   var flag = true;
-  errorTime += delay;
   return () => {
     if (!flag) return;
     flag = false;
+    errorTime += delay;
     timer = setTimeout(() => {
       fn();
       flag = true;
@@ -45,6 +45,10 @@ function throttle(fn, delay) {
   };
 }
 
+const throttleDoConnectDirectives = throttle(() => {
+  doConnectDirectives();
+}, 100);
+
 function doConnectDirectives() {
   videoWidth = Number(resolvingPower) ? Number(resolvingPower) : 720;
   videoHeight = videoWidth === 720 ? 1280 : 1920;
@@ -53,6 +57,7 @@ function doConnectDirectives() {
 
   wsss.onopen = function () {
     // 获取虚拟场景状态
+    errorTime = 0;
     var pings = { type: 'getVsStatus' };
     wsss.send(JSON.stringify(pings));
     var bitRate = {
@@ -80,20 +85,21 @@ function doConnectDirectives() {
   };
   wsss.onerror = function (e) {
     // console.log('🚀 ~ file: WXdraw.js ~ line 82 ~ onerror ~ e', e);
-    wsss.close();
-    throttle(doConnectDirectives, 100);
-    if (errorTime > 1000) {
-      quit();
-    }
+    wsss.close(1006);
+    // throttle(doConnectDirectives, 100);
+    // if (errorTime > 1000) {
+    //   quit();
+    // }
   };
   wsss.onclose = function (e) {
-    // console.log('🚀 ~ file: WXdraw.js ~ line 93 ~ onclose ~ e', e.code);
+    // console.log('🚀 ~ file: WXdraw.js ~ line 93 ~ onclose ~ e', e);
     // new WebSocket(e.)
     // doConnectDirectives();
     if (e.code === 1006) {
       // 异常关闭,重连
+      throttleDoConnectDirectives();
       // doConnectDirectives();
-      throttle(doConnectDirectives, 100);
+      // throttle(doConnectDirectives, 100);
       if (errorTime > 1000) {
         quit();
       }