Commit 89a6028d authored by hujiebin's avatar hujiebin

获取用户在房间的最后一次心跳

parent 774b5480
...@@ -285,6 +285,16 @@ func (s *server) RoomHeartbeat(ctx context.Context, in *userCenter.RoomHeartbeat ...@@ -285,6 +285,16 @@ func (s *server) RoomHeartbeat(ctx context.Context, in *userCenter.RoomHeartbeat
}, nil }, 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) { func realBroadcast(addr string, uids []uint64, msg *userCenter.BroadcastMessage) {
mylogrus.MyLog.Infof("Broadcasting: Addr %s: users: %v", addr, uids) mylogrus.MyLog.Infof("Broadcasting: Addr %s: users: %v", addr, uids)
......
...@@ -54,6 +54,17 @@ func (m *RoomManager) UpdateRoomUser(uid uint64, groupId string) error { ...@@ -54,6 +54,17 @@ func (m *RoomManager) UpdateRoomUser(uid uint64, groupId string) error {
return err 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 {
mylogrus.MyLog.Errorf("GetLastRoomUserHeartbeat fail:%v", err)
return 0, err
}
return int64(tx), err
}
func (m *RoomManager) GetAll() *map[string]string { func (m *RoomManager) GetAll() *map[string]string {
//ctx, _ := context.WithTimeout(m.Ctx, time.Millisecond*500) //ctx, _ := context.WithTimeout(m.Ctx, time.Millisecond*500)
//result := m.RedisClient.Get(ctx, field) //result := m.RedisClient.Get(ctx, field)
......
...@@ -112,6 +112,16 @@ message RoomHeartbeatMessageRsp { ...@@ -112,6 +112,16 @@ message RoomHeartbeatMessageRsp {
uint32 status = 1; uint32 status = 1;
} }
// 获取房间内最后一次心跳
message GetLastRoomHeartbeatMessage {
uint64 uid = 1;
string groupId = 2;
}
message GetLastRoomHeartbeatMessageResp {
int64 timestamp = 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) {}
...@@ -126,4 +136,5 @@ service User { ...@@ -126,4 +136,5 @@ service User {
rpc enterRoom(EnterRoomMessage) returns (EnterRoomMessageRsp) {} rpc enterRoom(EnterRoomMessage) returns (EnterRoomMessageRsp) {}
rpc leaveRoom(LeaveRoomMessage) returns (LeaveRoomMessageRsp) {} rpc leaveRoom(LeaveRoomMessage) returns (LeaveRoomMessageRsp) {}
rpc roomHeartbeat(RoomHeartbeatMessage) returns (RoomHeartbeatMessageRsp) {} rpc roomHeartbeat(RoomHeartbeatMessage) returns (RoomHeartbeatMessageRsp) {}
rpc getLastRoomHeartbeat(GetLastRoomHeartbeatMessage) returns (GetLastRoomHeartbeatMessageResp) {}
} }
\ 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