mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
pb file
This commit is contained in:
parent
2e0cb09cdd
commit
d88ba3545b
@ -7,23 +7,27 @@ import (
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbChat "Open_IM/src/proto/chat"
|
||||
"Open_IM/src/utils"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"runtime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (ws *WServer) msgParse(conn *UserConn, jsonMsg []byte) {
|
||||
func (ws *WServer) msgParse(conn *UserConn, binaryMsg []byte) {
|
||||
//ws online debug data
|
||||
//{"ReqIdentifier":1001,"Token":"123","SendID":"c4ca4238a0b923820dcc509a6f75849b","Time":"123","OperationID":"123","MsgIncr":0}
|
||||
//{"ReqIdentifier":1002,"Token":"123","SendID":"c4ca4238a0b923820dcc509a6f75849b","Time":"123","OperationID":"123","MsgIncr":0,"SeqBegin":1,"SeqEnd":6}
|
||||
//{"ReqIdentifier":1003,"Token":"123","SendID":"c4ca4238a0b923820dcc509a6f75849b",
|
||||
//"RecvID":"a87ff679a2f3e71d9181a67b7542122c","ClientMsgID":"2343","Time":"147878787","OperationID":
|
||||
//"123","MsgIncr":0,"SubMsgType":101,"MsgType":100,"MsgFrom":1,"Content":"sdfsdf"}
|
||||
b := bytes.NewBuffer(binaryMsg)
|
||||
m := Req{}
|
||||
if err := json.Unmarshal(jsonMsg, &m); err != nil {
|
||||
dec := gob.NewDecoder(b)
|
||||
err := dec.Decode(&m)
|
||||
if err != nil {
|
||||
log.ErrorByKv("ws json Unmarshal err", "", "err", err.Error())
|
||||
ws.sendErrMsg(conn, 200, err.Error(), constant.WSDataError, "")
|
||||
err = conn.Close()
|
||||
@ -238,8 +242,13 @@ func (ws *WServer) sendMsgReq(conn *UserConn, m *Req, sendTime int64) {
|
||||
}
|
||||
|
||||
func (ws *WServer) sendMsg(conn *UserConn, mReply interface{}) {
|
||||
bMsg, _ := json.Marshal(mReply)
|
||||
err := ws.writeMsg(conn, websocket.TextMessage, bMsg)
|
||||
var b bytes.Buffer
|
||||
enc := gob.NewEncoder(&b)
|
||||
err := enc.Encode(mReply)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
err = ws.writeMsg(conn, websocket.BinaryMessage, b.Bytes())
|
||||
if err != nil {
|
||||
log.ErrorByKv("WS WriteMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err, "mReply", mReply)
|
||||
}
|
||||
|
@ -7,8 +7,9 @@ import (
|
||||
"Open_IM/src/grpc-etcdv3/getcdv3"
|
||||
pbRelay "Open_IM/src/proto/relay"
|
||||
"Open_IM/src/utils"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"encoding/gob"
|
||||
"fmt"
|
||||
"github.com/gorilla/websocket"
|
||||
"google.golang.org/grpc"
|
||||
@ -74,7 +75,12 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
|
||||
msg["sendTime"] = in.SendTime
|
||||
msg["senderPlatformID"] = in.PlatformID
|
||||
mReply["data"] = msg
|
||||
bMsg, _ := json.Marshal(mReply)
|
||||
var b bytes.Buffer
|
||||
enc := gob.NewEncoder(&b)
|
||||
err := enc.Encode(mReply)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
switch in.GetSessionType() {
|
||||
case constant.SingleChatType:
|
||||
RecvID = in.GetRecvID()
|
||||
@ -87,7 +93,7 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
|
||||
if conn := ws.getUserConn(v); conn != nil {
|
||||
UIDAndPID := strings.Split(v, " ")
|
||||
tag = true
|
||||
resultCode := sendMsgToUser(conn, bMsg, in, UIDAndPID[1], UIDAndPID[0])
|
||||
resultCode := sendMsgToUser(conn, b.Bytes(), in, UIDAndPID[1], UIDAndPID[0])
|
||||
temp := &pbRelay.SingleMsgToUser{
|
||||
ResultCode: resultCode,
|
||||
RecvID: UIDAndPID[0],
|
||||
@ -165,7 +171,7 @@ func (r *RPCServer) MsgToUser(_ context.Context, in *pbRelay.MsgToUserReq) (*pbR
|
||||
}
|
||||
|
||||
func sendMsgToUser(conn *UserConn, bMsg []byte, in *pbRelay.MsgToUserReq, RecvPlatForm, RecvID string) (ResultCode int64) {
|
||||
err := ws.writeMsg(conn, websocket.TextMessage, bMsg)
|
||||
err := ws.writeMsg(conn, websocket.BinaryMessage, bMsg)
|
||||
if err != nil {
|
||||
log.ErrorByKv("PushMsgToUser is failed By Ws", "", "Addr", conn.RemoteAddr().String(),
|
||||
"error", err, "senderPlatform", utils.PlatformIDToName(in.PlatformID), "recvPlatform", RecvPlatForm, "args", in.String(), "recvID", RecvID)
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package pbAuth;
|
||||
option go_package = "auth;pbAuth";
|
||||
option go_package = "./auth;pbAuth";
|
||||
|
||||
message UserRegisterReq {
|
||||
string UID = 1;
|
||||
|
@ -1,6 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package pbChat;//The package name to which the proto file belongs
|
||||
option go_package = "chat;pbChat";//The generated go pb file is in the current directory, and the package name is pbChat
|
||||
option go_package = "./chat;pbChat";//The generated go pb file is in the current directory, and the package name is pbChat
|
||||
|
||||
message WSToMsgSvrChatMsg{
|
||||
string SendID = 1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "friend;friend";
|
||||
option go_package = "./friend;friend";
|
||||
package friend;
|
||||
|
||||
message CommonResp{
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "group;group";
|
||||
option go_package = "./group;group";
|
||||
package group;
|
||||
|
||||
message CommonResp{
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "push;pbPush";
|
||||
option go_package = "./push;pbPush";
|
||||
package push;
|
||||
|
||||
message PushMsgReq {
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "relay;pbRelay";
|
||||
option go_package = "./relay;pbRelay";
|
||||
package relay;
|
||||
|
||||
message MsgToUserReq {
|
||||
|
@ -1,5 +1,5 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "user;user";
|
||||
option go_package = "./user;user";
|
||||
package user;
|
||||
|
||||
message CommonResp{
|
||||
|
Loading…
x
Reference in New Issue
Block a user