diff --git a/src/msg_gateway/gate/rpc_server.go b/src/msg_gateway/gate/rpc_server.go index 151da3feb..e1f564934 100644 --- a/src/msg_gateway/gate/rpc_server.go +++ b/src/msg_gateway/gate/rpc_server.go @@ -73,50 +73,69 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR msg["senderPlatformID"] = in.PlatformID mReply["data"] = msg bMsg, _ := json.Marshal(mReply) - switch in.GetContentType() { - case constant.SyncSenderMsg: - log.InfoByKv("come sync", in.OperationID, "args", in.String()) - RecvID = in.GetSendID() - if in.MsgFrom != constant.SysMsgType { - for key, conn := range ws.wsUserToConn { - UIDAndPID := strings.Split(key, " ") - if UIDAndPID[0] == RecvID && utils.PlatformIDToName(in.GetPlatformID()) != UIDAndPID[1] { - resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0]) - temp := &pbRelay.SingleMsgToUser{ - ResultCode: resultCode, - RecvID: UIDAndPID[0], - RecvPlatFormID: utils.PlatformNameToID(UIDAndPID[1]), - } - resp = append(resp, temp) - } - - } - } - default: - log.InfoByKv("not come sync", in.OperationID, "args", in.String()) - switch in.SessionType { - case constant.SingleChatType: - log.InfoByKv("come single", in.OperationID, "args", in.String()) - RecvID = in.GetRecvID() - case constant.GroupChatType: - RecvID = strings.Split(in.GetRecvID(), " ")[0] - default: - } - log.InfoByKv("come for range", in.OperationID, "args", in.String()) - - for key, conn := range ws.wsUserToConn { - UIDAndPID := strings.Split(key, " ") - if UIDAndPID[0] == RecvID { - resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0]) - temp := &pbRelay.SingleMsgToUser{ - ResultCode: resultCode, - RecvID: UIDAndPID[0], - RecvPlatFormID: utils.PlatformNameToID(UIDAndPID[1]), - } - resp = append(resp, temp) + switch in.GetSessionType() { + case constant.SingleChatType: + RecvID = in.GetRecvID() + case constant.GroupChatType: + RecvID = strings.Split(in.GetRecvID(), " ")[0] + } + log.InfoByKv("test", in.OperationID, "wsUserToConn", ws.wsUserToConn) + for key, conn := range ws.wsUserToConn { + UIDAndPID := strings.Split(key, " ") + if UIDAndPID[0] == RecvID { + resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0]) + temp := &pbRelay.SingleMsgToUser{ + ResultCode: resultCode, + RecvID: UIDAndPID[0], + RecvPlatFormID: utils.PlatformNameToID(UIDAndPID[1]), } + resp = append(resp, temp) } } + //switch in.GetContentType() { + //case constant.SyncSenderMsg: + // log.InfoByKv("come sync", in.OperationID, "args", in.String()) + // RecvID = in.GetSendID() + // if in.MsgFrom != constant.SysMsgType { + // for key, conn := range ws.wsUserToConn { + // UIDAndPID := strings.Split(key, " ") + // if UIDAndPID[0] == RecvID && utils.PlatformIDToName(in.GetPlatformID()) != UIDAndPID[1] { + // resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0]) + // temp := &pbRelay.SingleMsgToUser{ + // ResultCode: resultCode, + // RecvID: UIDAndPID[0], + // RecvPlatFormID: utils.PlatformNameToID(UIDAndPID[1]), + // } + // resp = append(resp, temp) + // } + // + // } + // } + //default: + // log.InfoByKv("not come sync", in.OperationID, "args", in.String()) + // switch in.SessionType { + // case constant.SingleChatType: + // log.InfoByKv("come single", in.OperationID, "args", in.String()) + // RecvID = in.GetRecvID() + // case constant.GroupChatType: + // RecvID = strings.Split(in.GetRecvID(), " ")[0] + // default: + // } + // log.InfoByKv("come for range", in.OperationID, "args", in.String()) + // + // for key, conn := range ws.wsUserToConn { + // UIDAndPID := strings.Split(key, " ") + // if UIDAndPID[0] == RecvID { + // resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0]) + // temp := &pbRelay.SingleMsgToUser{ + // ResultCode: resultCode, + // RecvID: UIDAndPID[0], + // RecvPlatFormID: utils.PlatformNameToID(UIDAndPID[1]), + // } + // resp = append(resp, temp) + // } + // } + //} return &pbRelay.MsgToUserResp{ Resp: resp, }, nil diff --git a/src/msg_gateway/gate/ws_server.go b/src/msg_gateway/gate/ws_server.go index ef9d126d6..a62007fc7 100644 --- a/src/msg_gateway/gate/ws_server.go +++ b/src/msg_gateway/gate/ws_server.go @@ -57,11 +57,13 @@ func (ws *WServer) wsHandler(w http.ResponseWriter, r *http.Request) { func (ws *WServer) readMsg(conn *websocket.Conn) { for { - _, msg, err := conn.ReadMessage() + msgType, msg, err := conn.ReadMessage() if err != nil { log.ErrorByKv("WS ReadMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err) ws.delUserConn(conn) return + } else { + log.ErrorByKv("test", "", "msgType", msgType, "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn)) } ws.msgParse(conn, msg) //ws.writeMsg(conn, 1, chat)