修复连接重连问题

pull/23/head
taoshihan1991 3 years ago
parent bcfb6a61d9
commit 8102711af0

@ -259,7 +259,7 @@ func SendCloseMessageV2(c *gin.Context) {
oldUser, ok := ws.ClientList[visitorId]
if oldUser != nil || ok {
msg := TypeMessage{
Type: "close",
Type: "force_close",
Data: visitorId,
}
str, _ := json.Marshal(msg)

@ -331,5 +331,5 @@ location /
### 版权声明
当前项目是完整功能代码 , 但是仍然仅支持个人演示测试 , 不包含线上使用 . 赞赏并联系作者后可以获取完整技术支持,包括安装/部署/bug修改以及后期功能升级 .
当前项目是完整功能代码 , 但是仍然仅支持个人演示测试 , 不包含线上使用 . 赞赏并联系作者后可以获取完整专属技术支持,包括安装/部署/bug修改以及后期功能升级 .
使用本软件时,请遵守当地法律法规,任何违法用途一切后果请自行承担.

@ -28,7 +28,7 @@ func InitApiRouter(engine *gin.Engine) {
//前后聊天
engine.GET("/chat_server", middleware.Ipblack, controller.NewChatServer)
engine.GET("/ws_kefu", middleware.JwtApiMiddleware, ws.NewKefuServer)
engine.GET("/ws_visitor", ws.NewVisitorServer)
engine.GET("/ws_visitor", middleware.Ipblack, ws.NewVisitorServer)
go ws.WsServerBackend()
engine.GET("/messages", controller.GetVisitorMessage)

@ -13,6 +13,7 @@ new Vue({
face:[],
showKfonline:false,
socketClosed:false,
focusSendConn:false,
timer:null,
sendDisabled:false,
flyLang:GOFLY_LANG[LANG],
@ -32,9 +33,11 @@ new Vue({
OnOpen:function() {
this.chatTitle=GOFLY_LANG[LANG]['connectok'];
this.socketClosed=false;
this.focusSendConn=false;
},
OnMessage:function(e) {
this.socketClosed=false;
this.focusSendConn=false;
const redata = JSON.parse(e.data);
if (redata.type == "kfOnline") {
let msg = redata.data
@ -78,7 +81,15 @@ new Vue({
this.alertSound();//提示音
}
if (redata.type == "close") {
this.chatTitle="系统关闭连接!请重新打开页面";
this.chatTitle="系统自动关闭连接!点击会重连";
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom();
this.socket.close();
//this.socketClosed=true;
this.focusSendConn=true;
}
if (redata.type == "force_close") {
this.chatTitle="客服关闭连接!请重新打开页面";
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom();
this.socket.close();
@ -152,7 +163,8 @@ new Vue({
this.socket.send(JSON.stringify(message));
},
OnClose:function() {
this.socketClosed=true;
this.focusSendConn=true;
//this.socketClosed=true;
// this.chatTitle="连接关闭!请重新打开页面";
// $(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
// this.scrollBottom();
@ -354,8 +366,10 @@ new Vue({
$('.faceBox').hide();
});
window.onfocus = function () {
_this.scrollBottom();
if(!_this.socketClosed){
if(_this.socketClosed){
return;
}
if(!_this.focusSendConn){
return;
}
_this.initConn();

Loading…
Cancel
Save