Commit d4e1afb6 authored by hujiebin's avatar hujiebin

Merge branch 'feature/bodySize' into 'master'

Feature/body size

See merge request !1
parents 01804402 7aea0b98
...@@ -69,6 +69,10 @@ const ( ...@@ -69,6 +69,10 @@ const (
MsgTypeMatchV2Confirm = 141 // 匹配-v2-确认 MsgTypeMatchV2Confirm = 141 // 匹配-v2-确认
MsgTypeMatchV2CallReady = 142 // 匹配-v2-callReady MsgTypeMatchV2CallReady = 142 // 匹配-v2-callReady
MsgTypeMatchV2AddTimeGift = 143 // 匹配-v2-送礼加时长 MsgTypeMatchV2AddTimeGift = 143 // 匹配-v2-送礼加时长
MsgTypeEnterRoom = 152 // 用户进房
MsgTypeLeaveRoom = 153 // 用户离房
MsgTypeRoomHeartbeat = 154 // 房间心跳
MsgTypeGroupMicChangeRsp = 156 // 麦位变化确认
) )
const ( const (
......
...@@ -241,6 +241,22 @@ func serverWebsocket(w http.ResponseWriter, r *http.Request) { ...@@ -241,6 +241,22 @@ func serverWebsocket(w http.ResponseWriter, r *http.Request) {
} }
} }
} }
} else if msgType == common.MsgTypeEnterRoom {
if err := processEnterRoom(logger, ci.Uid, pbData); err != nil {
logger.Errorf("processEnterRoom fail:%v", err)
}
} else if msgType == common.MsgTypeLeaveRoom {
if err := processLeaveRoom(logger, ci.Uid, pbData); err != nil {
logger.Errorf("processLeaveRoom fail:%v", err)
}
} else if msgType == common.MsgTypeRoomHeartbeat {
if err := processRoomHeartbeat(logger, ci.Uid, pbData); err != nil {
logger.Errorf("processRoomHeartbeat fail:%v", err)
}
} else if msgType == common.MsgTypeGroupMicChangeRsp {
if err := processGroupMicChangeRsp(logger, ci.Uid, pbData); err != nil {
logger.Errorf("processGroupMicChangeRsp fail:%v", err)
}
} else { } else {
logger.Warnf("Unknown message type %d", msgType) logger.Warnf("Unknown message type %d", msgType)
} }
...@@ -401,6 +417,65 @@ func processBizRequest(logger *log.Entry, uid uint64, pbData []byte) (*userProxy ...@@ -401,6 +417,65 @@ func processBizRequest(logger *log.Entry, uid uint64, pbData []byte) (*userProxy
} }
} }
func processEnterRoom(logger *log.Entry, uid uint64, pbData []byte) error {
msg := &userProxy.EnterRoom{}
err := proto.Unmarshal(pbData, msg)
if err == nil {
err, status := doEnterRoom(uid, msg.GroupId)
if err == nil && status == common.Login_success {
logger.Infof("enter room success,uid:%v,group:%v", uid, msg.GroupId)
} else {
logger.Warnf("login RPC failed for %d, %v", status, err)
}
return err
} else {
return err
}
}
func processLeaveRoom(logger *log.Entry, uid uint64, pbData []byte) error {
msg := &userProxy.LeaveRoom{}
err := proto.Unmarshal(pbData, msg)
if err == nil {
err, status := doLeaveRoom(uid, msg.GroupId)
if err == nil && status == common.Login_success {
logger.Infof("leave room success,uid:%v,group:%v", uid, msg.GroupId)
} else {
logger.Warnf("login RPC failed for %d, %v", status, err)
}
return err
} else {
return err
}
}
func processRoomHeartbeat(logger *log.Entry, uid uint64, pbData []byte) error {
msg := &userProxy.RoomHeartBeat{}
err := proto.Unmarshal(pbData, msg)
if err == nil {
err, status := doRoomHeartbeat(uid, msg.GroupId)
if err == nil && status == common.Login_success {
logger.Infof("room heartbeat success,uid:%v,group:%v", uid, msg.GroupId)
} else {
logger.Warnf("login RPC failed for %d, %v", status, err)
}
return err
} else {
return err
}
}
func processGroupMicChangeRsp(logger *log.Entry, uid uint64, pbData []byte) error {
msg := &userProxy.GroupMicChangeRsp{}
err := proto.Unmarshal(pbData, msg)
if err == nil {
logger.Infof("groupMicChangeRsp,uid:%v,seqId:%v", uid, msg.SeqId)
} else {
return err
}
return err
}
// 直接发匹配成功消息,调试用 // 直接发匹配成功消息,调试用
func homePage(w http.ResponseWriter, r *http.Request) { func homePage(w http.ResponseWriter, r *http.Request) {
rsp := "Home Page" rsp := "Home Page"
...@@ -568,6 +643,51 @@ func doBizRequest(uid uint64, msgType uint32, payLoad string) (uint32, error) { ...@@ -568,6 +643,51 @@ func doBizRequest(uid uint64, msgType uint32, payLoad string) (uint32, error) {
} }
} }
func doEnterRoom(uid uint64, groupId string) (error, uint32) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
r, err := userClient.EnterRoom(ctx, &userCenter.EnterRoomMessage{
Uid: uid,
GroupId: groupId,
})
if err == nil && r != nil {
return err, r.Status
} else {
return err, 0
}
}
func doLeaveRoom(uid uint64, groupId string) (error, uint32) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
r, err := userClient.LeaveRoom(ctx, &userCenter.LeaveRoomMessage{
Uid: uid,
GroupId: groupId,
})
if err == nil && r != nil {
return err, r.Status
} else {
return err, 0
}
}
func doRoomHeartbeat(uid uint64, groupId string) (error, uint32) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
r, err := userClient.RoomHeartbeat(ctx, &userCenter.RoomHeartbeatMessage{
Uid: uid,
GroupId: groupId,
})
if err == nil && r != nil {
return err, r.Status
} else {
return err, 0
}
}
var kacp = keepalive.ClientParameters{ var kacp = keepalive.ClientParameters{
Time: 10 * time.Second, // send pings every 10 seconds if there is no activity Time: 10 * time.Second, // send pings every 10 seconds if there is no activity
Timeout: time.Second, // wait 1 second for ping ack before considering the connection dead Timeout: time.Second, // wait 1 second for ping ack before considering the connection dead
......
...@@ -85,6 +85,33 @@ message BizMessageRsp { ...@@ -85,6 +85,33 @@ message BizMessageRsp {
uint32 status = 1; uint32 status = 1;
} }
message EnterRoomMessage {
uint64 uid = 1;
string groupId = 2;
}
message EnterRoomMessageRsp {
uint32 status = 1;
}
message LeaveRoomMessage {
uint64 uid = 1;
string groupId = 2;
}
message LeaveRoomMessageRsp {
uint32 status = 1;
}
message RoomHeartbeatMessage {
uint64 uid = 1;
string groupId = 2;
}
message RoomHeartbeatMessageRsp {
uint32 status = 1;
}
service Router { service Router {
rpc route(RouteMessage) returns (RouteMessageRsp) {} rpc route(RouteMessage) returns (RouteMessageRsp) {}
rpc kickUser(KickMessage) returns (KickMessageRsp) {} rpc kickUser(KickMessage) returns (KickMessageRsp) {}
...@@ -96,4 +123,7 @@ service User { ...@@ -96,4 +123,7 @@ service User {
rpc multicast(MulticastMessage) returns (MulticastMessageRsp) {} rpc multicast(MulticastMessage) returns (MulticastMessageRsp) {}
rpc broadcast(BroadcastMessage) returns (BroadcastMessageRsp) {} rpc broadcast(BroadcastMessage) returns (BroadcastMessageRsp) {}
rpc transmit(BizMessage) returns (BizMessageRsp) {} rpc transmit(BizMessage) returns (BizMessageRsp) {}
rpc enterRoom(EnterRoomMessage) returns (EnterRoomMessageRsp) {}
rpc leaveRoom(LeaveRoomMessage) returns (LeaveRoomMessageRsp) {}
rpc roomHeartbeat(RoomHeartbeatMessage) returns (RoomHeartbeatMessageRsp) {}
} }
\ No newline at end of file
...@@ -411,4 +411,56 @@ message SvipUpgrade { ...@@ -411,4 +411,56 @@ message SvipUpgrade {
User user = 1; User user = 1;
uint32 svip_level = 2; uint32 svip_level = 2;
string group_id = 3; 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;
uint32 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;
uint32 svipLevel = 12;
string micEffect = 14;
string headwearIcon = 15;
Svip svip = 16;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment