|
|
@@ -5,7 +5,6 @@
|
|
|
|
|
|
// 文本消息
|
|
|
socketTask: null,
|
|
|
- // urlData: "ws://114.115.147.140:12345/api/api_gateway?method=control_center.real_time.im_message",
|
|
|
urlData: "wss://www.toreskj.com/api/api_gateway?method=control_center.real_time.im_message",
|
|
|
// urlData: "ws://192.168.1.17:12345/api/api_gateway?method=control_center.real_time.im_message",
|
|
|
is_open_socket: false, // 确保websocket是打开状态
|
|
|
@@ -24,7 +23,9 @@
|
|
|
reconnectTimeOutObj: null, // 重连之后多久再次重连
|
|
|
// 测试
|
|
|
app: [],
|
|
|
- hdskdh: null
|
|
|
+
|
|
|
+ // 消息发送加载
|
|
|
+ msgSetTime: null,
|
|
|
},
|
|
|
onLoad() {},
|
|
|
onLaunch: function() {
|
|
|
@@ -32,32 +33,46 @@
|
|
|
// App启动
|
|
|
|
|
|
var that = this
|
|
|
+ // uni.getStorage({
|
|
|
+ // key: 'session_key',
|
|
|
+ // success: function(res) {
|
|
|
+ // that.globalData.token = res.data
|
|
|
+ // // console.log('登录成功了')
|
|
|
+ // that.msgInit(); // 文本初始化
|
|
|
+ // },
|
|
|
+ // fail: function(err) {
|
|
|
+ // console.log(err)
|
|
|
+ // console.log('没有登录成功')
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ },
|
|
|
+ onShow: function() {
|
|
|
+ var that = this
|
|
|
+ // App展示在前台
|
|
|
+ console.log('+++++++++++++++++++App Show-------------------------------------')
|
|
|
+ // this.msgInit(); // 再进行请求
|
|
|
uni.getStorage({
|
|
|
key: 'session_key',
|
|
|
success: function(res) {
|
|
|
- // console.log(res)
|
|
|
that.globalData.token = res.data
|
|
|
// console.log('登录成功了')
|
|
|
+ console.log(res)
|
|
|
that.msgInit(); // 文本初始化
|
|
|
},
|
|
|
fail: function(err) {
|
|
|
- // console.log(err)
|
|
|
- // console.log('没有登录成功')
|
|
|
+ console.log(err)
|
|
|
+ console.log('没有登录成功')
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
- onShow: function() {
|
|
|
- // App展示在前台
|
|
|
- console.log('+++++++++++++++++++App Show-------------------------------------')
|
|
|
- this.msgInit(); // 再进行请求
|
|
|
- },
|
|
|
onHide: function() {
|
|
|
// App不再再展示在前台
|
|
|
- // this.close(); // 关闭
|
|
|
+ this.close(); // 关闭
|
|
|
},
|
|
|
methods: {
|
|
|
// 实时通信 - 初始化
|
|
|
msgInit() {
|
|
|
+ console.log('进入了实时通信初始化=--------------------------', this.globalData.token)
|
|
|
var that = this
|
|
|
// 连接webscoket
|
|
|
that.globalData.socketTask = uni.connectSocket({
|
|
|
@@ -83,6 +98,7 @@
|
|
|
async success(res) {
|
|
|
that.globalData.is_open_socket = true
|
|
|
console.log("消息发送成功");
|
|
|
+ uni.hideLoading(); // 关闭通信异常弹框
|
|
|
|
|
|
},
|
|
|
});
|
|
|
@@ -96,6 +112,7 @@
|
|
|
var val = JSON.parse(res.data)
|
|
|
console.log('这是返回的内容---------', val)
|
|
|
if (val.action == 'list') {
|
|
|
+ clearTimeout(that.globalData.msgSetTime); // 消息发送成功,清除发送失败定时器
|
|
|
console.log('这是发送人的ID', that.globalData.userId)
|
|
|
var obj1 = {
|
|
|
'action': 'list', // 动作标识,必填
|
|
|
@@ -112,7 +129,7 @@
|
|
|
});
|
|
|
that.globalData.userId = null
|
|
|
} else if (val.action == 'none') {
|
|
|
- console.log('进入了none')
|
|
|
+ console.log('进入了none', val)
|
|
|
that.globalData.list = val.data
|
|
|
this.$store.state.list = val.data
|
|
|
} else if (val.action == 'recv_video') {
|
|
|
@@ -144,6 +161,9 @@
|
|
|
// 连接失败
|
|
|
that.globalData.socketTask.onError((res) => {
|
|
|
// console.log(res, '连接错误');
|
|
|
+ uni.showLoading({
|
|
|
+ title: "通信异常,连接中..."
|
|
|
+ })
|
|
|
clearTimeout(this.globalData.timeoutObj);
|
|
|
setTimeout(() => {
|
|
|
that.reconnect();
|
|
|
@@ -159,6 +179,7 @@
|
|
|
//onmessage拿到返回的心跳就说明连接正常
|
|
|
var obj = {
|
|
|
'action': 'keepalive', // 动作标识,必填
|
|
|
+ 'type': 'App',
|
|
|
'recv_user_id': '', // 接收人用户id, 非必填
|
|
|
'data': {
|
|
|
msg_status: false,
|
|
|
@@ -172,7 +193,11 @@
|
|
|
// console.log('消息发送成功1111')
|
|
|
}
|
|
|
});
|
|
|
- console.log('进入心跳机制了')
|
|
|
+ console.log('进入心跳机制了', that.globalData.socketTask)
|
|
|
+ let ws_temp = null
|
|
|
+ ws_temp = that.globalData.socketTask
|
|
|
+ that.globalData.socketTask = ws_temp
|
|
|
+ ws_temp = null
|
|
|
}, this.globalData.timeout)
|
|
|
},
|
|
|
// 清除心跳机制
|
|
|
@@ -212,6 +237,7 @@
|
|
|
var that = this
|
|
|
// console.log('已经手动关闭了')
|
|
|
that.globalData.socketTask.close()
|
|
|
+ that.globalData.socketTask = null
|
|
|
clearTimeout(that.globalData.timeoutObj);
|
|
|
clearTimeout(that.globalData.reconnectTimeOutObj);
|
|
|
},
|