Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-userCenter
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-userCenter
Commits
e63c5347
Commit
e63c5347
authored
Jul 28, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/bodySize' into 'master'
Feature/body size See merge request
!1
parents
606f1661
7ed5bed8
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
214 additions
and
0 deletions
+214
-0
main.go
main.go
+42
-0
roomManager.go
manager/roomManager.go
+79
-0
userCenter.proto
protocol/userCenter.proto
+41
-0
userProxy.proto
protocol/userProxy.proto
+52
-0
No files found.
main.go
View file @
e63c5347
...
...
@@ -61,6 +61,7 @@ type BroadcastChanMsg struct {
var
(
userManager
*
manager
.
UserManager
=
nil
termManager
*
manager
.
TerminalManager
=
nil
roomManager
*
manager
.
RoomManager
=
nil
)
var
logDir
=
"/var/log/hilo/"
...
...
@@ -257,6 +258,43 @@ func (s *server) Transmit(ctx context.Context, in *userCenter.BizMessage) (*user
return
rsp
,
nil
}
func
(
s
*
server
)
EnterRoom
(
ctx
context
.
Context
,
in
*
userCenter
.
EnterRoomMessage
)
(
*
userCenter
.
EnterRoomMessageRsp
,
error
)
{
if
err
:=
roomManager
.
AddRoomUser
(
in
.
GetUid
(),
in
.
GetGroupId
());
err
!=
nil
{
return
nil
,
err
}
return
&
userCenter
.
EnterRoomMessageRsp
{
Status
:
0
,
},
nil
}
func
(
s
*
server
)
LeaveRoom
(
ctx
context
.
Context
,
in
*
userCenter
.
LeaveRoomMessage
)
(
*
userCenter
.
LeaveRoomMessageRsp
,
error
)
{
if
err
:=
roomManager
.
DelRoomUser
(
in
.
GetUid
(),
in
.
GetGroupId
());
err
!=
nil
{
return
nil
,
err
}
return
&
userCenter
.
LeaveRoomMessageRsp
{
Status
:
0
,
},
nil
}
func
(
s
*
server
)
RoomHeartbeat
(
ctx
context
.
Context
,
in
*
userCenter
.
RoomHeartbeatMessage
)
(
*
userCenter
.
RoomHeartbeatMessageRsp
,
error
)
{
if
err
:=
roomManager
.
UpdateRoomUser
(
in
.
GetUid
(),
in
.
GetGroupId
());
err
!=
nil
{
return
nil
,
err
}
return
&
userCenter
.
RoomHeartbeatMessageRsp
{
Status
:
0
,
},
nil
}
func
(
s
*
server
)
GetLastRoomHeartbeat
(
ctx
context
.
Context
,
in
*
userCenter
.
GetLastRoomHeartbeatMessage
)
(
*
userCenter
.
GetLastRoomHeartbeatMessageResp
,
error
)
{
ts
,
err
:=
roomManager
.
GetLastRoomUserHeartbeat
(
in
.
GetUid
(),
in
.
GetGroupId
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
userCenter
.
GetLastRoomHeartbeatMessageResp
{
Timestamp
:
ts
,
},
nil
}
func
realBroadcast
(
addr
string
,
uids
[]
uint64
,
msg
*
userCenter
.
BroadcastMessage
)
{
mylogrus
.
MyLog
.
Infof
(
"Broadcasting: Addr %s: users: %v"
,
addr
,
uids
)
...
...
@@ -499,6 +537,10 @@ func main() {
Ctx
:
context
.
Background
(),
RedisClient
:
rdb
,
}
roomManager
=
&
manager
.
RoomManager
{
Ctx
:
context
.
Background
(),
RedisClient
:
rdb
,
}
mylogrus
.
MyLog
.
Infof
(
"Connected to Redis %s
\n
"
,
redisAddress
)
...
...
manager/roomManager.go
0 → 100644
View file @
e63c5347
package
manager
import
(
"context"
"fmt"
"github.com/go-redis/redis/v8"
"hilo-userCenter/common/mylogrus"
"log"
"time"
)
func
getRoomUserKey
(
groupId
string
)
string
{
return
fmt
.
Sprintf
(
"room:%v"
,
groupId
)
}
type
RoomManager
struct
{
Ctx
context
.
Context
RedisClient
*
redis
.
Client
}
func
(
m
*
RoomManager
)
AddRoomUser
(
uid
uint64
,
groupId
string
)
error
{
key
:=
getRoomUserKey
(
groupId
)
err
:=
m
.
RedisClient
.
ZAdd
(
m
.
Ctx
,
key
,
&
redis
.
Z
{
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Member
:
fmt
.
Sprintf
(
"%d"
,
uid
),
})
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"AddRoomUser fail:%v"
,
err
)
return
nil
}
return
err
}
func
(
m
*
RoomManager
)
DelRoomUser
(
uid
uint64
,
groupId
string
)
error
{
key
:=
getRoomUserKey
(
groupId
)
err
:=
m
.
RedisClient
.
ZRem
(
m
.
Ctx
,
key
,
fmt
.
Sprintf
(
"%d"
,
uid
))
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"DelRoomUser fail:%v"
,
err
)
return
nil
}
return
err
}
func
(
m
*
RoomManager
)
UpdateRoomUser
(
uid
uint64
,
groupId
string
)
error
{
key
:=
getRoomUserKey
(
groupId
)
err
:=
m
.
RedisClient
.
ZAdd
(
m
.
Ctx
,
key
,
&
redis
.
Z
{
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Member
:
fmt
.
Sprintf
(
"%d"
,
uid
),
})
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"AddRoomUser fail:%v"
,
err
)
return
nil
}
return
err
}
// 获取用户在房间的最后一次心跳
func
(
m
*
RoomManager
)
GetLastRoomUserHeartbeat
(
uid
uint64
,
groupId
string
)
(
int64
,
error
)
{
key
:=
getRoomUserKey
(
groupId
)
tx
,
err
:=
m
.
RedisClient
.
ZScore
(
m
.
Ctx
,
key
,
fmt
.
Sprintf
(
"%d"
,
uid
))
.
Result
()
if
err
!=
nil
&&
err
!=
redis
.
Nil
{
mylogrus
.
MyLog
.
Errorf
(
"GetLastRoomUserHeartbeat fail:%v"
,
err
)
return
0
,
err
}
// redis nil means 0
return
int64
(
tx
),
nil
}
func
(
m
*
RoomManager
)
GetAll
()
*
map
[
string
]
string
{
//ctx, _ := context.WithTimeout(m.Ctx, time.Millisecond*500)
//result := m.RedisClient.Get(ctx, field)
result
,
err
:=
m
.
RedisClient
.
HGetAll
(
m
.
Ctx
,
user_key
)
.
Result
()
if
err
!=
nil
{
log
.
Printf
(
"HGetAll error: %s
\n
"
,
err
.
Error
())
return
nil
}
else
{
return
&
result
}
}
protocol/userCenter.proto
View file @
e63c5347
...
...
@@ -85,6 +85,43 @@ 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
;
}
// 获取房间内最后一次心跳
message
GetLastRoomHeartbeatMessage
{
uint64
uid
=
1
;
string
groupId
=
2
;
}
message
GetLastRoomHeartbeatMessageResp
{
int64
timestamp
=
1
;
}
service
Router
{
rpc
route
(
RouteMessage
)
returns
(
RouteMessageRsp
)
{}
rpc
kickUser
(
KickMessage
)
returns
(
KickMessageRsp
)
{}
...
...
@@ -96,4 +133,8 @@ 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
)
{}
rpc
getLastRoomHeartbeat
(
GetLastRoomHeartbeatMessage
)
returns
(
GetLastRoomHeartbeatMessageResp
)
{}
}
\ No newline at end of file
protocol/userProxy.proto
View file @
e63c5347
...
...
@@ -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