mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
ws modify
This commit is contained in:
parent
b10ba999cd
commit
edc81534c4
@ -52,6 +52,8 @@ func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
|||||||
ws.getSeqReq(conn, &m)
|
ws.getSeqReq(conn, &m)
|
||||||
case constant.WSSendMsg:
|
case constant.WSSendMsg:
|
||||||
ws.sendMsgReq(conn, &m)
|
ws.sendMsgReq(conn, &m)
|
||||||
|
case constant.WSSendSignalMsg:
|
||||||
|
ws.sendSignalMsgReq(conn, &m)
|
||||||
case constant.WSPullMsgBySeqList:
|
case constant.WSPullMsgBySeqList:
|
||||||
ws.pullMsgBySeqListReq(conn, &m)
|
ws.pullMsgBySeqListReq(conn, &m)
|
||||||
default:
|
default:
|
||||||
@ -193,6 +195,57 @@ func (ws *WServer) sendMsgResp(conn *UserConn, m *Req, pb *pbChat.SendMsgResp) {
|
|||||||
ws.sendMsg(conn, mReply)
|
ws.sendMsg(conn, mReply)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
pbData := pbChat.SendMsgReq{
|
||||||
|
Token: m.Token,
|
||||||
|
OperationID: m.OperationID,
|
||||||
|
MsgData: &data,
|
||||||
|
}
|
||||||
|
log.NewInfo(m.OperationID, "Ws call success to sendSignalMsgReq middle", m.ReqIdentifier, m.SendID, m.MsgIncr, data)
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
log.NewError(pbData.OperationID, "rpc sendMsg err", err.Error())
|
||||||
|
nReply.ErrCode = 200
|
||||||
|
nReply.ErrMsg = err.Error()
|
||||||
|
ws.sendSignalMsgResp(conn, m, nReply)
|
||||||
|
} else {
|
||||||
|
log.NewInfo(pbData.OperationID, "rpc call success to sendMsgReq", reply.String())
|
||||||
|
ws.sendSignalMsgResp(conn, m, reply)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
nReply.ErrCode = errCode
|
||||||
|
nReply.ErrMsg = errMsg
|
||||||
|
ws.sendSignalMsgResp(conn, m, nReply)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
func (ws *WServer) sendSignalMsgResp(conn *UserConn, m *Req, pb *pbChat.SendMsgResp) {
|
||||||
|
// := 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)
|
||||||
|
mReply := Resp{
|
||||||
|
ReqIdentifier: m.ReqIdentifier,
|
||||||
|
MsgIncr: m.MsgIncr,
|
||||||
|
ErrCode: pb.GetErrCode(),
|
||||||
|
ErrMsg: pb.GetErrMsg(),
|
||||||
|
OperationID: m.OperationID,
|
||||||
|
Data: b,
|
||||||
|
}
|
||||||
|
ws.sendMsg(conn, mReply)
|
||||||
|
}
|
||||||
func (ws *WServer) sendMsg(conn *UserConn, mReply interface{}) {
|
func (ws *WServer) sendMsg(conn *UserConn, mReply interface{}) {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
enc := gob.NewEncoder(&b)
|
enc := gob.NewEncoder(&b)
|
||||||
|
@ -58,7 +58,7 @@ type SeqListData struct {
|
|||||||
|
|
||||||
func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, errMsg string, returnData interface{}) {
|
func (ws *WServer) argsValidate(m *Req, r int32) (isPass bool, errCode int32, errMsg string, returnData interface{}) {
|
||||||
switch r {
|
switch r {
|
||||||
case constant.WSSendMsg:
|
case constant.WSSendMsg | constant.WSSendSignalMsg:
|
||||||
data := open_im_sdk.MsgData{}
|
data := open_im_sdk.MsgData{}
|
||||||
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
if err := proto.Unmarshal(m.Data, &data); err != nil {
|
||||||
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
log.ErrorByKv("Decode Data struct err", "", "err", err.Error(), "reqIdentifier", r)
|
||||||
|
@ -20,8 +20,10 @@ const (
|
|||||||
WSGetNewestSeq = 1001
|
WSGetNewestSeq = 1001
|
||||||
WSPullMsgBySeqList = 1002
|
WSPullMsgBySeqList = 1002
|
||||||
WSSendMsg = 1003
|
WSSendMsg = 1003
|
||||||
|
WSSendSignalMsg = 1004
|
||||||
WSPushMsg = 2001
|
WSPushMsg = 2001
|
||||||
WSKickOnlineMsg = 2002
|
WSKickOnlineMsg = 2002
|
||||||
|
WsLogoutMsg = 2003
|
||||||
WSDataError = 3001
|
WSDataError = 3001
|
||||||
|
|
||||||
///ContentType
|
///ContentType
|
||||||
@ -139,16 +141,16 @@ const (
|
|||||||
|
|
||||||
//callbackCommand
|
//callbackCommand
|
||||||
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"
|
CallbackBeforeSendSingleMsgCommand = "callbackBeforeSendSingleMsgCommand"
|
||||||
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand"
|
CallbackAfterSendSingleMsgCommand = "callbackAfterSendSingleMsgCommand"
|
||||||
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand"
|
CallbackBeforeSendGroupMsgCommand = "callbackBeforeSendGroupMsgCommand"
|
||||||
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
CallbackAfterSendGroupMsgCommand = "callbackAfterSendGroupMsgCommand"
|
||||||
CallbackWordFilterCommand = "callbackWordFilterCommand"
|
CallbackWordFilterCommand = "callbackWordFilterCommand"
|
||||||
//callback actionCode
|
//callback actionCode
|
||||||
ActionAllow = 0
|
ActionAllow = 0
|
||||||
ActionForbidden = 1
|
ActionForbidden = 1
|
||||||
//callback callbackHandleCode
|
//callback callbackHandleCode
|
||||||
CallbackHandleSuccess = 0
|
CallbackHandleSuccess = 0
|
||||||
CallbackHandleFailed = 1
|
CallbackHandleFailed = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
var ContentType2PushContent = map[int64]string{
|
var ContentType2PushContent = map[int64]string{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user