聊天?

This commit is contained in:
苏尹岚
2020-10-22 15:46:58 +08:00
parent 51a9c62beb
commit 382f59f545
2 changed files with 28 additions and 6 deletions

View File

@@ -86,12 +86,15 @@ func (c *EventController) TestWebsocket() {
}
defer ws.Close()
var (
// userID = c.GetString("userID")
userID = c.GetString("userID")
msgMap = make(map[int]*model.ImMessageRecord)
groupID int
)
//将当前客户端放入map中
// clients[vendorOrderID] = append(clients[vendorOrderID], ws)
messageGroups, _ := dao.GetUserMessageGroups(dao.GetDB(), userID)
for _, v := range messageGroups {
clients[v.GroupID] = append(clients[v.GroupID], ws)
}
db := dao.GetDB()
if globals.IsProductEnv() {
@@ -111,7 +114,6 @@ func (c *EventController) TestWebsocket() {
for {
//接收客户端的消息
err := ws.ReadJSON(&s)
clients[s.GroupID] = append(clients[s.GroupID], ws)
if err != nil {
globals.SugarLogger.Debugf("页面可能断开啦 ws.ReadJSON error: %v", err.Error())
index := 0
@@ -130,9 +132,10 @@ func (c *EventController) TestWebsocket() {
//接受消息 业务逻辑
msgMap[s.GroupID] = s
broadcast <- msgMap
dao.WrapAddIDCULDEntity(s, "")
dao.CreateEntity(db, s)
// fmt.Println("接受到从页面上反馈回来的信息 ", utils.Format4Output(s, false))
go func() {
dao.WrapAddIDCULDEntity(s, "")
dao.CreateEntity(db, s)
}()
}
}
}