huangxiaojing 4 年之前
父節點
當前提交
a0e34c9597
共有 1 個文件被更改,包括 46 次插入21 次删除
  1. 46 21
      screenAndroid/WXdraw.js

+ 46 - 21
screenAndroid/WXdraw.js

@@ -40,29 +40,54 @@ if (room == "A1") {
 }
 var cUrl = isWSS ? "wss" : "ws" + "://" + wsUrl + "/card?cardIp=" + form.ip;
 
-var wsss = new WebSocket(cUrl);
-wsss.binaryType = 'arraybuffer';
+var wsss;
 
-wsss.onopen = function () {
-	var pings = {
-		"event": "getScreenStatus"
-	}
-	wsss.send(JSON.stringify(pings));
-	var bitRate = {
-		"data": {
-			"bitRate": 2243000
-		},
-		"event": "bitRate"
-	}
-	wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
-};
+function doConnect() {
+	wsss = new WebSocket(cUrl);
+	wsss.binaryType = 'arraybuffer';
 
-wsss.onclose = function (event) {
-	console.log("onclose==============");
-};
-wsss.onerror = function (event) {
-	console.log("onerror==============");
-};
+	wsss.onopen = function () {
+		var pings = {
+			"event": "getScreenStatus"
+		}
+		wsss.send(JSON.stringify(pings));
+		var bitRate = {
+			"data": {
+				"bitRate": 2243000
+			},
+			"event": "bitRate"
+		}
+		wsss.send(ExexuteMove(JSON.stringify(bitRate), form.sn))
+	};
+	wsss.onclose = function () {
+		$.confirm({
+			title: '提示',
+			text: '连接断开,是否准备重连?',
+			onOK: function () {
+				doConnect();
+			},
+			onCancel: function () {
+				wx.miniProgram.switchTab({
+					url: '/pages/home/home'
+				})
+			}
+		});
+	};
+	wsss.onerror = function () {
+		$.confirm({
+			title: '提示',
+			text: '连接断开,是否准备重连?',
+			onOK: function () {
+				doConnect();
+			},
+			onCancel: function () {
+				wx.miniProgram.switchTab({
+					url: '/pages/home/home'
+				})
+			}
+		});
+	};
+}
 $('#box').on("click", function () {
 	draw_graph('pencil', this)
 })