Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-userProxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-userProxy
Commits
7aea0b98
Commit
7aea0b98
authored
Jul 28, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Feature/body size
parent
01804402
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
206 additions
and
0 deletions
+206
-0
coder.go
common/coder.go
+4
-0
main.go
main.go
+120
-0
userCenter.proto
protocol/userCenter.proto
+30
-0
userProxy.proto
protocol/userProxy.proto
+52
-0
No files found.
common/coder.go
View file @
7aea0b98
...
...
@@ -69,6 +69,10 @@ const (
MsgTypeMatchV2Confirm
=
141
// 匹配-v2-确认
MsgTypeMatchV2CallReady
=
142
// 匹配-v2-callReady
MsgTypeMatchV2AddTimeGift
=
143
// 匹配-v2-送礼加时长
MsgTypeEnterRoom
=
152
// 用户进房
MsgTypeLeaveRoom
=
153
// 用户离房
MsgTypeRoomHeartbeat
=
154
// 房间心跳
MsgTypeGroupMicChangeRsp
=
156
// 麦位变化确认
)
const
(
...
...
main.go
View file @
7aea0b98
...
...
@@ -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
{
logger
.
Warnf
(
"Unknown message type %d"
,
msgType
)
}
...
...
@@ -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
)
{
rsp
:=
"Home Page"
...
...
@@ -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
{
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
...
...
protocol/userCenter.proto
View file @
7aea0b98
...
...
@@ -85,6 +85,33 @@ message BizMessageRsp {
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
{
rpc
route
(
RouteMessage
)
returns
(
RouteMessageRsp
)
{}
rpc
kickUser
(
KickMessage
)
returns
(
KickMessageRsp
)
{}
...
...
@@ -96,4 +123,7 @@ service User {
rpc
multicast
(
MulticastMessage
)
returns
(
MulticastMessageRsp
)
{}
rpc
broadcast
(
BroadcastMessage
)
returns
(
BroadcastMessageRsp
)
{}
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
protocol/userProxy.proto
View file @
7aea0b98
...
...
@@ -412,3 +412,55 @@ message SvipUpgrade {
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
;
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment