From 7f41bbcf5f665e0e3623bffb6a6b5c147f474624 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 24 Jul 2023 16:03:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81socket=E7=9A=84=E9=BA=A6?= =?UTF-8?q?=E4=BD=8D=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocol/userProxy.proto | 63 ++++++++++++++++++++++++++++++++++++++++ rpc/user_center_coder.go | 1 + rpc/user_center_func.go | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) diff --git a/protocol/userProxy.proto b/protocol/userProxy.proto index 85e540e..2ac061e 100644 --- a/protocol/userProxy.proto +++ b/protocol/userProxy.proto @@ -411,4 +411,67 @@ message SvipUpgrade { User user = 1; uint32 svip_level = 2; string group_id = 3; +} + +/* id == 152 用户进房 上行 */ +message EnterRoom { + string group_id = 1; +} + +/* id == 153 用户离房 上行 */ +message LeaveRoom { + string group_id = 1; +} + +/* id == 154 房间心跳 上行 */ +message RoomHeartBeat { + string group_id = 1; +} + +/* id == 155 麦位变化 下行 */ +message GroupMicChange { + string seqId = 1; + string group_id = 2; + uint32 i = 3; + bool lock = 4; + bool forbid = 5; + bool micForbid = 6; + string externalId = 7; + string agoraId = 8; + int64 timestamp = 9; + MicUserData user = 10; +} + +/* id == 156 麦位变化确认 上行 */ +message GroupMicChangeRsp { + string seqId = 1; +} + +message MicUserData { + uint64 id = 1; + string externalId = 2; + string avatar = 3; + string nick = 4; + uint32 sex = 5; + string code = 6; + bool isVip = 7; + uint32 noble = 8; + string headwearPicUrl = 9; + string headwearEffectUrl = 10; + string headwearReverseEffectUrl = 11; + int32 svipLevel = 12; + string micEffect = 14; + string headwearIcon = 15; +} + +message CvSvip { + int32 svipLevel = 1; + repeated CVSvipPrivilege privileges = 2; +} + +message CVSvipPrivilege { + int32 type = 1; + bool canSwitch = 2; + bool userSwitch = 3; + string mysteryCode = 4; } \ No newline at end of file diff --git a/rpc/user_center_coder.go b/rpc/user_center_coder.go index 4caea3f..1a4929b 100644 --- a/rpc/user_center_coder.go +++ b/rpc/user_center_coder.go @@ -66,6 +66,7 @@ const ( MsgTypeCpInvite = 149 // cp邀请 MsgTypeCpUpgrade = 150 // cp升级 MsgTypeSvipUpgrade = 151 // svip升级 + MsgTypeGroupMicChange = 155 // 麦位变化 ) const ( diff --git a/rpc/user_center_func.go b/rpc/user_center_func.go index 7603a46..09ff348 100644 --- a/rpc/user_center_func.go +++ b/rpc/user_center_func.go @@ -6,6 +6,7 @@ import ( "git.hilo.cn/hilo-common/protocol/userProxy" "git.hilo.cn/hilo-common/utils" "google.golang.org/protobuf/proto" + "time" ) func SendFruitMachine(date string, round uint32) error { @@ -397,3 +398,55 @@ func SendSvipUpgrade(nick, avatar string, svipLevel uint32, txGroupId string) er } return nil } + +// 发送socket的麦位变化 +// todo fix +func SendSocketMicChange(userId uint64) error { + var msg = &userProxy.GroupMicChange{ + SeqId: "todo", + GroupId: "todo", + I: 1, + Lock: true, + Forbid: false, + MicForbid: false, + ExternalId: "1234", + AgoraId: "todotodo", + Timestamp: time.Now().Unix(), + User: &userProxy.MicUserData{ + Id: 1, + ExternalId: "", + Avatar: "", + Nick: "", + Sex: 0, + Code: "", + IsVip: false, + Noble: 0, + HeadwearPicUrl: "", + HeadwearEffectUrl: "", + HeadwearReverseEffectUrl: "", + SvipLevel: 0, + MicEffect: "", + HeadwearIcon: "1231", + }, + } + if buffer, err := proto.Marshal(msg); err == nil { + userIds := []uint64{userId} + rspUids, err := multicast(userIds, MsgTypeGroupMicChange, buffer) + + //记录socket,注意闭包问题 + go func(userIds []uint64, msg *userProxy.GroupMicChange, rspUids []uint64, err error) { + buf, _ := json.Marshal(msg) + AddRpcLogs(MsgTypeGroupMicChange, userIds, string(buf[:]), rspUids, err) + }(userIds, msg, rspUids, err) + + if err != nil { + mylogrus.MyLog.Errorf("grpc SendSocketMicChange send fail") + return err + } else { + mylogrus.MyLog.Info("grpc SendSocketMicChange send success") + } + } else { + return err + } + return nil +} -- 2.22.0