From 8102711af0bb6042895613a177f9622a32092c6a Mon Sep 17 00:00:00 2001 From: taoshihan1991 <630892807@qq.com> Date: Wed, 10 Mar 2021 13:27:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=9E=E6=8E=A5=E9=87=8D?= =?UTF-8?q?=E8=BF=9E=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/message.go | 2 +- readme.md | 2 +- router/api.go | 2 +- static/js/chat-page.js | 22 ++++++++++++++++++---- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/controller/message.go b/controller/message.go index 415b352..b5e95e7 100644 --- a/controller/message.go +++ b/controller/message.go @@ -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) diff --git a/readme.md b/readme.md index 80497f4..9e3f7ba 100644 --- a/readme.md +++ b/readme.md @@ -331,5 +331,5 @@ location / ### 版权声明 -当前项目是完整功能代码 , 但是仍然仅支持个人演示测试 , 不包含线上使用 . 赞赏并联系作者后可以获取完整技术支持,包括安装/部署/bug修改以及后期功能升级 . +当前项目是完整功能代码 , 但是仍然仅支持个人演示测试 , 不包含线上使用 . 赞赏并联系作者后可以获取完整专属技术支持,包括安装/部署/bug修改以及后期功能升级 . 使用本软件时,请遵守当地法律法规,任何违法用途一切后果请自行承担. \ No newline at end of file diff --git a/router/api.go b/router/api.go index 50aec00..9bb7c38 100644 --- a/router/api.go +++ b/router/api.go @@ -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) diff --git a/static/js/chat-page.js b/static/js/chat-page.js index 29bae49..bf05ebb 100644 --- a/static/js/chat-page.js +++ b/static/js/chat-page.js @@ -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("
"+this.chatTitle+"
"); + this.scrollBottom(); + this.socket.close(); + //this.socketClosed=true; + this.focusSendConn=true; + } + if (redata.type == "force_close") { + this.chatTitle="客服关闭连接!请重新打开页面"; $(".chatBox").append("
"+this.chatTitle+"
"); 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("
"+this.chatTitle+"
"); // 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();