mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
add Signal message
This commit is contained in:
parent
965dac5ff9
commit
d60039454a
@ -199,15 +199,16 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||
sendMsgCount++
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq start", m.MsgIncr, m.ReqIdentifier, m.SendID)
|
||||
nReply := new(pbChat.SendMsgResp)
|
||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendMsg)
|
||||
if isPass {
|
||||
data := pData.(sdk_ws.MsgData)
|
||||
isPass, errCode, errMsg, pData := ws.argsValidate(m, constant.WSSendSignalMsg)
|
||||
isPass2, errCode2, errMsg2, signalResp, msgData := ws.signalMessageAssemble(pData.(*sdk_ws.SignalReq))
|
||||
|
||||
if isPass && isPass2 {
|
||||
pbData := pbChat.SendMsgReq{
|
||||
Token: m.Token,
|
||||
OperationID: m.OperationID,
|
||||
MsgData: &data,
|
||||
MsgData: msgData,
|
||||
}
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, data)
|
||||
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, msgData)
|
||||
etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImOfflineMessageName)
|
||||
client := pbChat.NewChatClient(etcdConn)
|
||||
reply, err := client.SendMsg(context.Background(), &pbData)
|
||||
@ -215,32 +216,30 @@ func (ws *WServer) sendSignalMsgReq(conn *UserConn, m *Req) {
|
||||
log.NewError(pbData.OperationID, "rpc sendMsg err", err.Error())
|
||||
nReply.ErrCode = 200
|
||||
nReply.ErrMsg = err.Error()
|
||||
ws.sendSignalMsgResp(conn, m, nReply)
|
||||
ws.sendSignalMsgResp(conn, 200, err.Error(), m, signalResp)
|
||||
} else {
|
||||
log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String())
|
||||
ws.sendSignalMsgResp(conn, m, reply)
|
||||
ws.sendSignalMsgResp(conn, 0, "", m, signalResp)
|
||||
}
|
||||
|
||||
} else {
|
||||
nReply.ErrCode = errCode
|
||||
nReply.ErrMsg = errMsg
|
||||
ws.sendSignalMsgResp(conn, m, nReply)
|
||||
if isPass {
|
||||
ws.sendSignalMsgResp(conn, errCode2, errMsg2, m, signalResp)
|
||||
} else {
|
||||
ws.sendSignalMsgResp(conn, errCode, errMsg, m, signalResp)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, m *Req, pb *pbChat.SendMsgResp) {
|
||||
func (ws *WServer) sendSignalMsgResp(conn *UserConn, errCode int32, errMsg string, m *Req, pb *sdk_ws.SignalResp) {
|
||||
// := make(map[string]interface{})
|
||||
|
||||
var mReplyData sdk_ws.UserSendMsgResp
|
||||
mReplyData.ClientMsgID = pb.GetClientMsgID()
|
||||
mReplyData.ServerMsgID = pb.GetServerMsgID()
|
||||
mReplyData.SendTime = pb.GetSendTime()
|
||||
b, _ := proto.Marshal(&mReplyData)
|
||||
b, _ := proto.Marshal(pb)
|
||||
mReply := Resp{
|
||||
ReqIdentifier: m.ReqIdentifier,
|
||||
MsgIncr: m.MsgIncr,
|
||||
ErrCode: pb.GetErrCode(),
|
||||
ErrMsg: pb.GetErrMsg(),
|
||||
ErrCode: errCode,
|
||||
ErrMsg: errMsg,
|
||||
OperationID: m.OperationID,
|
||||
Data: b,
|
||||
}
|
||||
|
@ -7,9 +7,12 @@
|
||||
package gate
|
||||
|
||||
import (
|
||||
"Open_IM/internal/msg_gateway/gate/open_im_media"
|
||||
"Open_IM/pkg/common/constant"
|
||||
"Open_IM/pkg/common/log"
|
||||
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
|
||||
"Open_IM/pkg/utils"
|
||||
"errors"
|
||||
"github.com/golang/protobuf/proto"
|
||||
)
|
||||
|
||||
@ -71,7 +74,7 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
}
|
||||
return true, 0, "", data
|
||||
case constant.WSSendSignalMsg:
|
||||
data := open_im_sdk.MsgData{}
|
||||
data := open_im_sdk.SignalReq{}
|
||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||
return false, 203, err.Error(), nil
|
||||
@ -113,3 +116,122 @@ func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, er
|
||||
//} else
|
||||
|
||||
}
|
||||
|
||||
func (ws *WServer) signalMessageAssemble(s *open_im_sdk.SignalReq) (isPass bool, errCode int32, errMsg string, r *open_im_sdk.SignalResp, msgData *open_im_sdk.MsgData) {
|
||||
var msg open_im_sdk.MsgData
|
||||
var resp open_im_sdk.SignalResp
|
||||
media := open_im_media.NewMedia()
|
||||
msg.MsgFrom = constant.UserMsgType
|
||||
msg.ContentType = constant.SignalingNotification
|
||||
reqData, e := proto.Marshal(s)
|
||||
if e != nil {
|
||||
return false, 201, e.Error(), nil, nil
|
||||
}
|
||||
msg.Content = reqData
|
||||
msg.CreateTime = utils.GetCurrentTimestampByMill()
|
||||
options := make(map[string]bool, 6)
|
||||
utils.SetSwitchFromOptions(options, constant.IsHistory, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsPersistent, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsSenderSync, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsConversationUpdate, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsUnreadCount, false)
|
||||
utils.SetSwitchFromOptions(options, constant.IsOfflinePush, true)
|
||||
msg.Options = options
|
||||
switch payload := s.Payload.(type) {
|
||||
case *open_im_sdk.SignalReq_Invite:
|
||||
_, err := media.CreateRoom(payload.Invite.Invitation.RoomID)
|
||||
if err != nil {
|
||||
return false, 201, err.Error(), nil, nil
|
||||
|
||||
}
|
||||
token, err2 := media.GetJoinToken(payload.Invite.Invitation.RoomID, payload.Invite.Invitation.InviterUserID)
|
||||
if err2 != nil {
|
||||
return false, 201, err2.Error(), nil, nil
|
||||
}
|
||||
invite := open_im_sdk.SignalResp_Invite{&open_im_sdk.SignalInviteReply{
|
||||
Token: token,
|
||||
LiveURL: media.GetUrl(),
|
||||
}}
|
||||
resp.Payload = &invite
|
||||
msg.SenderPlatformID = payload.Invite.Invitation.PlatformID
|
||||
msg.SessionType = payload.Invite.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.Invite.OfflinePushInfo
|
||||
msg.SendID = payload.Invite.Invitation.InviterUserID
|
||||
if len(payload.Invite.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.RecvID = payload.Invite.Invitation.InviteeUserIDList[0]
|
||||
} else {
|
||||
return false, 201, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.Invite.Invitation.InviterUserID)
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_InviteInGroup:
|
||||
_, err := media.CreateRoom(payload.InviteInGroup.Invitation.RoomID)
|
||||
if err != nil {
|
||||
return false, 201, err.Error(), nil, nil
|
||||
|
||||
}
|
||||
token, err2 := media.GetJoinToken(payload.InviteInGroup.Invitation.RoomID, payload.InviteInGroup.Invitation.InviterUserID)
|
||||
if err2 != nil {
|
||||
return false, 201, err2.Error(), nil, nil
|
||||
}
|
||||
inviteGroup := open_im_sdk.SignalResp_InviteInGroup{&open_im_sdk.SignalInviteInGroupReply{
|
||||
RoomID: payload.InviteInGroup.Invitation.RoomID,
|
||||
Token: token,
|
||||
LiveURL: media.GetUrl(),
|
||||
}}
|
||||
resp.Payload = &inviteGroup
|
||||
msg.SenderPlatformID = payload.InviteInGroup.Invitation.PlatformID
|
||||
msg.SessionType = payload.InviteInGroup.Invitation.SessionType
|
||||
msg.OfflinePushInfo = payload.InviteInGroup.OfflinePushInfo
|
||||
msg.SendID = payload.InviteInGroup.Invitation.InviterUserID
|
||||
if len(payload.InviteInGroup.Invitation.InviteeUserIDList) > 0 {
|
||||
msg.GroupID = payload.InviteInGroup.Invitation.GroupID
|
||||
} else {
|
||||
return false, 201, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
msg.ClientMsgID = utils.GetMsgID(payload.InviteInGroup.Invitation.InviterUserID)
|
||||
|
||||
return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_Cancel:
|
||||
// cancel:=open_im_sdk.SignalResp_Cancel{&open_im_sdk.SignalCancelReply{
|
||||
// }}
|
||||
// resp.Payload = &cancel
|
||||
// msg.OfflinePushInfo = payload.Cancel.Invitation.OfflinePushInfo
|
||||
// msg.SendID = payload.Cancel.Invitation.Invitation.InviterUserID
|
||||
// msg.SessionType = payload.Cancel.Invitation.Invitation.SessionType
|
||||
// if len(payload.Cancel.Invitation.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Cancel.Invitation.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Cancel.Invitation.Invitation.InviteeUserIDList[0]
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Cancel.Invitation.Invitation.GroupID
|
||||
// }
|
||||
// }else {
|
||||
// return false, 201, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Cancel.Invitation.Invitation.InviterUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
//case *open_im_sdk.SignalReq_Accept:
|
||||
// cancel:=open_im_sdk.SignalResp_Accept{&open_im_sdk.SignalCancelReply{
|
||||
// }}
|
||||
// resp.Payload = &cancel
|
||||
// msg.OfflinePushInfo = payload.Cancel.Invitation.OfflinePushInfo
|
||||
// msg.SendID = payload.Cancel.Invitation.Invitation.InviterUserID
|
||||
// msg.SessionType = payload.Cancel.Invitation.Invitation.SessionType
|
||||
// if len(payload.Cancel.Invitation.Invitation.InviteeUserIDList) > 0 {
|
||||
// switch payload.Cancel.Invitation.Invitation.SessionType {
|
||||
// case constant.SingleChatType:
|
||||
// msg.RecvID = payload.Cancel.Invitation.Invitation.InviteeUserIDList[0]
|
||||
// case constant.GroupChatType:
|
||||
// msg.GroupID = payload.Cancel.Invitation.Invitation.GroupID
|
||||
// }
|
||||
// }else {
|
||||
// return false, 201, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
// }
|
||||
// msg.ClientMsgID = utils.GetMsgID(payload.Cancel.Invitation.Invitation.InviterUserID)
|
||||
// return true, 0, "", &resp, &msg
|
||||
case *open_im_sdk.SignalReq_HungUp:
|
||||
case *open_im_sdk.SignalReq_Reject:
|
||||
}
|
||||
return false, 201, errors.New("InviteeUserIDList is null").Error(), nil, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user