Commit d3c3d90e authored by haoyanbin's avatar haoyanbin

1

parent 43001efb
...@@ -25,7 +25,7 @@ const ( ...@@ -25,7 +25,7 @@ const (
// //
closeWait = 60 * 30 * time.Second closeWait = 60 * 30 * time.Second
// // time for auto end
endDate = 60 * 2 * time.Second endDate = 60 * 2 * time.Second
) )
...@@ -142,7 +142,7 @@ func (c *Client) readPump() { ...@@ -142,7 +142,7 @@ func (c *Client) readPump() {
close(c.sendPing) close(c.sendPing)
c.grpool.Close() c.grpool.Close()
c.hub.RemoveClient(c) c.hub.RemoveClient(c)
Redis.HDel(cliKey, c.Id) DelClient(c.Id)
dump() dump()
}() }()
Loop: Loop:
......
...@@ -27,7 +27,7 @@ var ( ...@@ -27,7 +27,7 @@ var (
// clients. // clients.
type hub struct { type hub struct {
// Registered clients. // Registered clients.
clients map[string]*Client // //新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了 clients map[string]*Client //新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了
oldClients map[string]*Client //缓存断开的连接消息队列 oldClients map[string]*Client //缓存断开的连接消息队列
// Inbound messages from the clients. // Inbound messages from the clients.
......
...@@ -28,8 +28,7 @@ func InitWsPool(errfun func(err interface{})) { ...@@ -28,8 +28,7 @@ func InitWsPool(errfun func(err interface{})) {
} }
func initWsPoolData() { func initWsPoolData() {
clientsData := Redis.HGetAll(cliKey) clientsAll := GetAllList(cliKey)
clientsAll := clientsData.Val()
for _, v := range clientsAll { for _, v := range clientsAll {
if v == "" { if v == "" {
......
...@@ -10,8 +10,6 @@ import ( ...@@ -10,8 +10,6 @@ import (
"time" "time"
) )
var toConverstaionLock sync.Mutex
type SetMsgReq struct { type SetMsgReq struct {
ProcedureType int `json:"procedureType"` ProcedureType int `json:"procedureType"`
GroupId string `json:"groupId" db:"group_id"` GroupId string `json:"groupId" db:"group_id"`
...@@ -78,8 +76,7 @@ func NewClient(conf *Config) *Client { ...@@ -78,8 +76,7 @@ func NewClient(conf *Config) *Client {
client.OnPing(nil) client.OnPing(nil)
client.OnPong(nil) client.OnPong(nil)
wsSever.hub.AddClient(client) wsSever.hub.AddClient(client)
jsonData := string(SerializeJson(conf)) AppendClient(client.Id,string(SerializeJson(conf)))
Redis.HSet(cliKey, client.Id, jsonData)
return client return client
} }
...@@ -509,8 +506,8 @@ func PublishData(mqData *SetMsgReq) { ...@@ -509,8 +506,8 @@ func PublishData(mqData *SetMsgReq) {
return return
} }
func GetConversationList() map[string]string { func GetAllList(key string) map[string]string {
jsonData := Redis.HGetAll(convKey) jsonData := Redis.HGetAll(key)
jsonDataAll := jsonData.Val() jsonDataAll := jsonData.Val()
return jsonDataAll return jsonDataAll
} }
...@@ -525,8 +522,18 @@ func DelConversation(customerClientId, userClientId string) { ...@@ -525,8 +522,18 @@ func DelConversation(customerClientId, userClientId string) {
return return
} }
func AppendClient(clientId, data string){
Redis.HSet(cliKey, clientId, data)
return
}
func DelClient(clientId string) {
Redis.HDel(cliKey, clientId)
return
}
func SetEnd() { func SetEnd() {
conversationList := GetConversationList() conversationList := GetAllList(convKey)
for _, vClients := range conversationList { for _, vClients := range conversationList {
conversationData := &Conversation{} conversationData := &Conversation{}
UnserislizeJson([]byte(vClients), conversationData) UnserislizeJson([]byte(vClients), conversationData)
......
...@@ -164,6 +164,7 @@ func ws(w http.ResponseWriter, r *http.Request) { ...@@ -164,6 +164,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
pool.PublishData(closeMsg) pool.PublishData(closeMsg)
fmt.Println("专家关闭连接", client.Id) fmt.Println("专家关闭连接", client.Id)
} }
pool.DelClient(client.Id)
fmt.Printf("连接己经关闭%s", client.Id) fmt.Printf("连接己经关闭%s", client.Id)
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment