准备增加定时切断

pull/23/head
630892807@qq.com 3 years ago
parent 29aceb65a0
commit 177c5e8a23

@ -9,9 +9,10 @@ import (
)
var (
PageSize uint = 10
VisitorPageSize uint = 8
Version = "0.1.2"
PageSize uint = 10
VisitorPageSize uint = 8
Version = "0.1.2"
VisitorExpire float64 = 600
GoflyConfig *Config
)

@ -84,6 +84,10 @@ func SendMessageV2(c *gin.Context) {
})
}
if cType == "visitor" {
guest, ok := ws.ClientList[vistorInfo.VisitorId]
if ok && guest != nil {
guest.UpdateTime = time.Now()
}
//kefuConns, ok := ws.KefuList[kefuInfo.Name]
//if kefuConns == nil || !ok {
// c.JSON(200, gin.H{

@ -10,6 +10,7 @@ var GOFLY_LANG={
"textarea":"请输入内容",
"closemes":"系统自动关闭连接!点击会重连",
"forceclosemes":"客服关闭连接!请重新打开页面",
"autoclosemes":"长时间未回应关闭连接!请刷新页面",
},
"en":{
"sent":"Send",
@ -22,5 +23,6 @@ var GOFLY_LANG={
"textarea":"Enter your message",
"closemes":"The system automatically closes the connection!",
"forceclosemes":"Admin closes the connection! please reload",
"autoclosemes":"session closed!please reload",
},
};

@ -100,6 +100,13 @@ new Vue({
this.socket.close();
this.socketClosed=true;
}
if (redata.type == "auto_close") {
this.chatTitle=GOFLY_LANG[LANG]['autoclosemes'];
$(".chatBox").append("<div class=\"chatTime\">"+this.chatTitle+"</div>");
this.scrollBottom();
this.socket.close();
this.socketClosed=true;
}
window.parent.postMessage(redata,"*");
},
//发送给客户

@ -4,6 +4,7 @@ import (
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"github.com/taoshihan1991/imaptool/config"
"github.com/taoshihan1991/imaptool/models"
"log"
"time"
@ -26,11 +27,12 @@ func NewVisitorServer(c *gin.Context) {
return
}
user := &User{
Conn: conn,
Name: vistorInfo.Name,
Avator: vistorInfo.Avator,
Id: vistorInfo.VisitorId,
To_id: vistorInfo.ToId,
Conn: conn,
Name: vistorInfo.Name,
Avator: vistorInfo.Avator,
Id: vistorInfo.VisitorId,
To_id: vistorInfo.ToId,
UpdateTime: time.Now(),
}
go models.UpdateVisitorStatus(vistorInfo.VisitorId, 1)
//go SendServerJiang(vistorInfo.Name, "来了", c.Request.Host)
@ -170,3 +172,29 @@ func VisitorAutoReply(vistorInfo models.Visitor, kefuInfo models.User, content s
models.CreateMessage(kefuInfo.Name, vistorInfo.VisitorId, welcome.Content, "kefu")
}
}
func cleanVisitorExpire() {
go func() {
return
log.Println("cleanVisitorExpire start...")
for {
for _, user := range ClientList {
diff := time.Now().Sub(user.UpdateTime).Seconds()
if diff >= config.VisitorExpire {
msg := TypeMessage{
Type: "auto_close",
Data: user.Id,
}
str, _ := json.Marshal(msg)
if err := user.Conn.WriteMessage(websocket.TextMessage, str); err != nil {
user.Conn.Close()
delete(ClientList, user.Id)
}
log.Println(user.Name + ":cleanVisitorExpire finshed")
}
}
// 计算下一个零点
t := time.NewTimer(time.Second * 10)
<-t.C
}
}()
}

@ -15,13 +15,14 @@ import (
)
type User struct {
Conn *websocket.Conn
Name string
Id string
Avator string
To_id string
Role_id string
Mux sync.Mutex
Conn *websocket.Conn
Name string
Id string
Avator string
To_id string
Role_id string
Mux sync.Mutex
UpdateTime time.Time
}
type Message struct {
conn *websocket.Conn
@ -65,6 +66,7 @@ func init() {
},
}
go UpdateVisitorStatusCron()
cleanVisitorExpire()
}
func SendServerJiang(title string, content string, domain string) string {
noticeServerJiang, err := strconv.ParseBool(models.FindConfig("NoticeServerJiang"))

Loading…
Cancel
Save