From c40dc64bd0c6162ecad41db73c1ae4c21dfe2b04 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 7 Jun 2022 16:59:05 +0800 Subject: [PATCH 1/6] set group memberInfo --- internal/rpc/group/group.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index bd7aa3264..551606ffe 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -1432,6 +1432,7 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetGroupMemberInfo failed", err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error() + return resp, nil } chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) From 269df23851eb1f18e03fa29f6dc20af93df2e946 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 7 Jun 2022 17:06:47 +0800 Subject: [PATCH 2/6] set group memberInfo --- internal/rpc/group/group.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 551606ffe..ad98775f6 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -1426,7 +1426,6 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr if req.Ex != nil { m["ex"] = req.Ex.Value } - err = imdb.UpdateGroupMemberInfoByMap(groupMember, m) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "SetGroupMemberInfo failed", err.Error()) From dbcfcafdfc36c64f4c04f637591456f8230beb23 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 9 Jun 2022 18:16:23 +0800 Subject: [PATCH 3/6] fix word --- pkg/common/constant/constant.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index a726111b3..7728efda9 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -222,7 +222,7 @@ var ContentType2PushContent = map[int64]string{ AtText: "[有人@你]", GroupMsg: "你收到一条群聊消息", Common: "你收到一条新消息", - SignalMsg: "音視頻通話邀請", + SignalMsg: "音视频通话邀请", } const ( From 891738747a20779b48056294004b17726d795833 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 9 Jun 2022 19:36:51 +0800 Subject: [PATCH 4/6] fix word --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 196b7e231..6a39e3747 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -700,4 +700,4 @@ demo: imAPIURL: http://127.0.0.1:10002 rtc: - signalTimeout: 3000 + signalTimeout: 300 From 1687b70bded150397b1833d3becbd1a1355bbccb Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 10 Jun 2022 17:31:30 +0800 Subject: [PATCH 5/6] fix signal --- internal/api/third/rtc.go | 8 ++-- internal/msg_gateway/gate/logic.go | 9 +---- internal/push/logic/push_to_client.go | 6 +++ pkg/common/db/newRedisModel.go | 55 +++++++++++++++------------ 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/internal/api/third/rtc.go b/internal/api/third/rtc.go index 4986558d7..eaa1a1959 100644 --- a/internal/api/third/rtc.go +++ b/internal/api/third/rtc.go @@ -21,9 +21,7 @@ func GetRTCInvitationInfo(c *gin.Context) { return } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req) - var ok bool - var errInfo string - ok, _, errInfo = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + ok, userID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) if !ok { errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token") log.NewError(req.OperationID, errMsg) @@ -37,6 +35,10 @@ func GetRTCInvitationInfo(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()}) return } + if err := db.DB.DelUserSignalList(userID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelUserSignalList result:", err.Error()) + } + resp.Data.OpUserID = invitationInfo.OpUserID resp.Data.Invitation.RoomID = invitationInfo.Invitation.RoomID resp.Data.Invitation.SessionType = invitationInfo.Invitation.SessionType diff --git a/internal/msg_gateway/gate/logic.go b/internal/msg_gateway/gate/logic.go index 47b58cde2..884f5f842 100644 --- a/internal/msg_gateway/gate/logic.go +++ b/internal/msg_gateway/gate/logic.go @@ -3,7 +3,6 @@ package gate import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbChat "Open_IM/pkg/proto/chat" @@ -238,13 +237,7 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) { ws.sendSignalMsgResp(conn, 200, err.Error(), m, &signalResp) } else { log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String()) - // save invitation info for offline push - if err := db.DB.NewCacheSignalInfo(pbData.MsgData); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), m, &signalResp) - ws.sendSignalMsgResp(conn, 200, err.Error(), m, &signalResp) - } else { - ws.sendSignalMsgResp(conn, 0, "", m, &signalResp) - } + ws.sendSignalMsgResp(conn, 0, "", m, &signalResp) } } else { log.NewError(m.OperationID, utils.GetSelfFuncName(), respPb.IsPass, respPb.CommonResp.ErrCode, respPb.CommonResp.ErrMsg) diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index da5e680ec..81afb72d4 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -10,6 +10,7 @@ import ( "Open_IM/internal/push" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" + "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbPush "Open_IM/pkg/proto/push" @@ -126,6 +127,11 @@ func MsgToUser(pushMsg *pbPush.PushMsgReq) { if err != nil { log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), "GetOfflinePushOpts failed", pushMsg, err.Error()) } + // save invitation info for offline push + if err := db.DB.HandleSignalInfo(pushMsg.MsgData); err != nil { + log.NewError(pushMsg.OperationID, utils.GetSelfFuncName(), err.Error(), pushMsg.MsgData) + continue + } log.NewInfo(pushMsg.OperationID, utils.GetSelfFuncName(), UIDList, content, jsonCustomContent, "opts:", opts) pushResult, err := offlinePusher.Push(UIDList, content, jsonCustomContent, pushMsg.OperationID, opts) log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "offline pushResult: ", pushResult) diff --git a/pkg/common/db/newRedisModel.go b/pkg/common/db/newRedisModel.go index ab7a28d8c..ae044f049 100644 --- a/pkg/common/db/newRedisModel.go +++ b/pkg/common/db/newRedisModel.go @@ -108,42 +108,47 @@ func (d *DataBases) CleanUpOneUserAllMsgFromRedis(userID string, operationID str return nil } -func (d *DataBases) NewCacheSignalInfo(msg *pbCommon.MsgData) error { +func (d *DataBases) HandleSignalInfo(msg *pbCommon.MsgData) error { req := &pbRtc.SignalReq{} if err := proto.Unmarshal(msg.Content, req); err != nil { return err } //log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "SignalReq: ", req.String()) var inviteeUserIDList []string - switch invitationInfo := req.Payload.(type) { + var isInviteSignal bool + switch signalInfo := req.Payload.(type) { case *pbRtc.SignalReq_Invite: - inviteeUserIDList = invitationInfo.Invite.Invitation.InviteeUserIDList + inviteeUserIDList = signalInfo.Invite.Invitation.InviteeUserIDList + isInviteSignal = true case *pbRtc.SignalReq_InviteInGroup: - inviteeUserIDList = invitationInfo.InviteInGroup.Invitation.InviteeUserIDList + inviteeUserIDList = signalInfo.InviteInGroup.Invitation.InviteeUserIDList + isInviteSignal = true default: - log2.NewDebug("", utils.GetSelfFuncName(), "req type not invite", string(msg.Content)) + log2.NewDebug("", utils.GetSelfFuncName(), "req invalid type", string(msg.Content)) return nil } - for _, userID := range inviteeUserIDList { - timeout, err := strconv.Atoi(config.Config.Rtc.SignalTimeout) - if err != nil { - return err - } - keyList := SignalListCache + userID - err = d.rdb.LPush(context.Background(), keyList, msg.ClientMsgID).Err() - if err != nil { - return err - } - err = d.rdb.Expire(context.Background(), keyList, time.Duration(timeout)*time.Second).Err() - if err != nil { - return err - } - key := SignalCache + msg.ClientMsgID - err = d.rdb.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err() - if err != nil { + if isInviteSignal { + for _, userID := range inviteeUserIDList { + timeout, err := strconv.Atoi(config.Config.Rtc.SignalTimeout) + if err != nil { + return err + } + keyList := SignalListCache + userID + err = d.rdb.LPush(context.Background(), keyList, msg.ClientMsgID).Err() + if err != nil { + return err + } + err = d.rdb.Expire(context.Background(), keyList, time.Duration(timeout)*time.Second).Err() + if err != nil { + return err + } + key := SignalCache + msg.ClientMsgID + err = d.rdb.Set(context.Background(), key, msg.Content, time.Duration(timeout)*time.Second).Err() + if err != nil { + return err + } return err } - return err } return nil } @@ -183,14 +188,14 @@ func (d *DataBases) GetAvailableSignalInvitationInfo(userID string) (invitationI if err != nil { return nil, utils.Wrap(err, "GetSignalInfoFromCacheByClientMsgID") } - err = d.delUserSingalList(userID) + err = d.DelUserSignalList(userID) if err != nil { return nil, utils.Wrap(err, "GetSignalInfoFromCacheByClientMsgID") } return invitationInfo, nil } -func (d *DataBases) delUserSingalList(userID string) error { +func (d *DataBases) DelUserSignalList(userID string) error { keyList := SignalListCache + userID err := d.rdb.Del(context.Background(), keyList).Err() return err From 25f9e28230548b2d8d5adcc00014e623d3981a81 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Fri, 10 Jun 2022 17:33:36 +0800 Subject: [PATCH 6/6] fix signal --- config/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.yaml b/config/config.yaml index 6a39e3747..35029a766 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -700,4 +700,4 @@ demo: imAPIURL: http://127.0.0.1:10002 rtc: - signalTimeout: 300 + signalTimeout: 60