From 4efeb31d5b4921d7e851c256009486ad86bc70e2 Mon Sep 17 00:00:00 2001
From: zengh <123456>
Date: Tue, 21 Jun 2022 09:14:57 +0800
Subject: [PATCH] 地址替换
---
store/mutations.js | 99 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 85 insertions(+), 14 deletions(-)
diff --git a/store/mutations.js b/store/mutations.js
index 664665e..8e3c6fb 100644
--- a/store/mutations.js
+++ b/store/mutations.js
@@ -46,43 +46,100 @@
state.puserID = data.userID;
state.avatar = data.avatar;
}
-
+ console.log('登入数据传输成功 开始进入连接')
+
+ var url = 'ws://61.131.136.25:2086/websocket';
+
uni.connectSocket({
- url: 'ws://192.168.0.111:9034/websocket'
+ url: url
+ // url: 'ws://192.168.0.111:2086/websocket'
});
+
var socketOpen = false;
+
+ var heartbeatInterval = null;
+ var reconnect = null;
+
+
+
uni.onSocketOpen(function(res) {
socketOpen = true;
console.log('持续连接成功')
+
+ if (reconnect && reconnect != null) {
+ clearInterval(reconnect)
+ }
+
sendSocketMessage();
+
+ // 5秒发送一次心跳
+ heartbeatInterval = setInterval(() => {
+
+ console.log('发送心跳中')
+
+ uni.sendSocketMessage({
+ data: 'ping'
+ });
+
+ }, 5000)
+
});
-
+
+
+ // 监听连接失败
+ uni.onSocketError(function(res) {
+ console.log('WebSocket连接打开失败,请检查!');
+ //停止发送心跳
+
+ if (heartbeatInterval && heartbeatInterval != null) {
+ clearInterval(heartbeatInterval)
+ }
+ //如果不是人为关闭的话,进行重连
+ // if (!_this.isSocketClose) {}
+ reconnect = setInterval(() => { // 断线重连
+
+ console.log(`断线重连中...123`)
+ // 连接
+ uni.connectSocket({
+ url: url,
+ });
+
+ }, 3000)
+ });
+
+
+
+
function sendSocketMessage() {
var data = {
- // type: state.puserName,
- id: state.puserID,
- type: 'login'
- }
+ // type: state.puserName,
+
+ id: state.puserID,
+ type: 'login'
+ }
+
if (socketOpen) {
uni.sendSocketMessage({
data: JSON.stringify(data)
});
}
}
-
+
uni.onSocketMessage(function(res) {
console.log(res.data);
- var data = JSON.parse(res.data)
- // if (data.type == 'video') {
+ var data = JSON.parse(res.data)
+ if (data.type == 'video') {
// this.receiveVideo('Receiver', );
- console.log('进入接受 跳转',data.type)
+ console.log('进入接受 跳转', data.type)
uni.navigateTo({
- url: '../videoCall/videoCall?state=Receiver&type=' + data.type +'&room=' + data.roomId
+ url: '../videoCall/videoCall?state=Receiver&type=' + data.type + '&room=' + data
+ .roomId + '&name=' + data.name + '&faqiid=' + data.faqiid
});
- // }
+ }
// console.log('收到服务器内容:' + res.data);
});
-
+
+
//储存用户
WxStorage.set("init", "true");
WxStorage.set("name", data.userName);
@@ -90,6 +147,20 @@
WxStorage.set("accounts", data.accounts);
WxStorage.set("pass", data.pass);
},
+ // useWebSocket(state){
+ // uni.onSocketMessage(function(res) {
+ // console.log(res.data);
+ // var data = JSON.parse(res.data)
+ // if (data.type == 'video') {
+ // // this.receiveVideo('Receiver', );
+ // console.log('进入接受 跳转',data.type)
+ // uni.navigateTo({
+ // url: '../videoCall/videoCall?state=Receiver&type=' + data.type +'&room=' + data.roomId + '&name=' + data.name + '&faqiid=' + data.faqiid
+ // });
+ // }
+ // // console.log('收到服务器内容:' + res.data);
+ // });
+ // }
loginReset(state) { //重置
state.loging = false;
state.message.useName = '过客 ';
--
Gitblit v1.9.3