mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 03:25:59 +08:00
send msg change
This commit is contained in:
@@ -4,12 +4,12 @@ import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
||||
@@ -4,13 +4,13 @@ import (
|
||||
"Open_IM/src/common/config"
|
||||
"Open_IM/src/common/constant"
|
||||
"Open_IM/src/common/log"
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/src/proto/relay"
|
||||
"Open_IM/src/utils"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/skiffer-git/grpc-etcdv3/getcdv3"
|
||||
"google.golang.org/grpc"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
@@ -80,23 +80,40 @@ func (ws *WServer) writeMsg(conn *websocket.Conn, a int, msg []byte) error {
|
||||
func (ws *WServer) addUserConn(uid string, conn *websocket.Conn) {
|
||||
rwLock.Lock()
|
||||
defer rwLock.Unlock()
|
||||
if oldConn, ok := ws.wsUserToConn[uid]; ok {
|
||||
err := oldConn.Close()
|
||||
delete(ws.wsConnToUser, oldConn)
|
||||
if err != nil {
|
||||
log.ErrorByKv("close err", "", "uid", uid, "conn", conn)
|
||||
}
|
||||
} else {
|
||||
log.InfoByKv("this user is first login", "", "uid", uid)
|
||||
}
|
||||
ws.wsConnToUser[conn] = uid
|
||||
ws.wsUserToConn[uid] = conn
|
||||
log.WarnByKv("WS Add operation", "", "wsUser added", ws.wsUserToConn, "uid", uid)
|
||||
log.WarnByKv("WS Add operation", "", "wsUser added", ws.wsUserToConn, "uid", uid, "online_num", len(ws.wsUserToConn))
|
||||
|
||||
}
|
||||
|
||||
func (ws *WServer) delUserConn(conn *websocket.Conn) {
|
||||
rwLock.Lock()
|
||||
defer rwLock.Unlock()
|
||||
var uidPlatform string
|
||||
if uid, ok := ws.wsConnToUser[conn]; ok {
|
||||
uidPlatform = uid
|
||||
if _, ok = ws.wsUserToConn[uid]; ok {
|
||||
delete(ws.wsUserToConn, uid)
|
||||
log.WarnByKv("WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "uid", uid)
|
||||
log.WarnByKv("WS delete operation", "", "wsUser deleted", ws.wsUserToConn, "uid", uid, "online_num", len(ws.wsUserToConn))
|
||||
} else {
|
||||
log.WarnByKv("uid not exist", "", "wsUser deleted", ws.wsUserToConn, "uid", uid, "online_num", len(ws.wsUserToConn))
|
||||
}
|
||||
delete(ws.wsConnToUser, conn)
|
||||
}
|
||||
conn.Close()
|
||||
err := conn.Close()
|
||||
if err != nil {
|
||||
log.ErrorByKv("close err", "", "uid", uidPlatform, "conn", conn)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (ws *WServer) getUserConn(uid string) *websocket.Conn {
|
||||
|
||||
Reference in New Issue
Block a user