mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-06-30 06:48:14 +08:00
群通话状态查询
This commit is contained in:
parent
ce689db007
commit
89d65f0d2b
@ -44,6 +44,7 @@ type rtcServer struct {
|
||||
roomClient *lksdk.RoomServiceClient
|
||||
msgClient *rpcli.MsgClient
|
||||
userClient *rpcli.UserClient
|
||||
groupClient *rpcli.GroupClient
|
||||
relationClient *rpcli.RelationClient
|
||||
tokenExpiry time.Duration
|
||||
}
|
||||
@ -75,6 +76,11 @@ func Start(ctx context.Context, cfg *Config, client discovery.SvcDiscoveryRegist
|
||||
return err
|
||||
}
|
||||
|
||||
groupConn, err := client.GetConn(ctx, cfg.Share.RpcRegisterName.Group)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lk := cfg.RpcConfig.LiveKit
|
||||
roomClient := lksdk.NewRoomServiceClient(lk.InternalAddress, lk.APIKey, lk.APISecret)
|
||||
|
||||
@ -89,6 +95,7 @@ func Start(ctx context.Context, cfg *Config, client discovery.SvcDiscoveryRegist
|
||||
roomClient: roomClient,
|
||||
msgClient: rpcli.NewMsgClient(msgConn),
|
||||
userClient: rpcli.NewUserClient(userConn),
|
||||
groupClient: rpcli.NewGroupClient(groupConn),
|
||||
relationClient: rpcli.NewRelationClient(friendConn),
|
||||
tokenExpiry: tokenExpiry,
|
||||
}
|
||||
|
||||
@ -554,16 +554,75 @@ func (s *rtcServer) handleGetTokenByRoomID(ctx context.Context, req *rtc.SignalG
|
||||
|
||||
// SignalGetRoomByGroupID returns room information for a group.
|
||||
func (s *rtcServer) SignalGetRoomByGroupID(ctx context.Context, req *rtc.SignalGetRoomByGroupIDReq) (*rtc.SignalGetRoomByGroupIDResp, error) {
|
||||
inv, err := s.db.GetInvitationByGroupID(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
if req.GroupID == "" {
|
||||
return nil, errs.ErrArgs.WrapMsg("groupID is empty")
|
||||
}
|
||||
opUserID := mcontext.GetOpUserID(ctx)
|
||||
if opUserID == "" {
|
||||
return nil, errs.ErrArgs.WrapMsg("op user id is empty")
|
||||
}
|
||||
if _, err := s.groupClient.GetGroupMemberCache(ctx, req.GroupID, opUserID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
inv, err := s.db.GetInvitationByGroupID(ctx, req.GroupID)
|
||||
if err != nil {
|
||||
if errs.ErrRecordNotFound.Is(err) {
|
||||
return &rtc.SignalGetRoomByGroupIDResp{InCall: false}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
participants, inCall, _ := s.livekitRoomParticipantsMeta(ctx, inv.RoomID)
|
||||
return &rtc.SignalGetRoomByGroupIDResp{
|
||||
Invitation: modelToInvitationInfo(inv),
|
||||
RoomID: inv.RoomID,
|
||||
Invitation: modelToInvitationInfo(inv),
|
||||
RoomID: inv.RoomID,
|
||||
Participant: participants,
|
||||
InCall: inCall,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// livekitRoomParticipantsMeta lists LiveKit participants (identity = OpenIM userID) and builds ParticipantMetaData.
|
||||
func (s *rtcServer) livekitRoomParticipantsMeta(ctx context.Context, roomID string) ([]*rtc.ParticipantMetaData, bool, error) {
|
||||
if roomID == "" {
|
||||
return nil, false, nil
|
||||
}
|
||||
lp, err := s.roomClient.ListParticipants(ctx, &livekit.ListParticipantsRequest{Room: roomID})
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, "LiveKit ListParticipants failed", err, "roomID", roomID)
|
||||
return nil, false, err
|
||||
}
|
||||
uids := make([]string, 0, len(lp.Participants))
|
||||
for _, p := range lp.Participants {
|
||||
if id := p.GetIdentity(); id != "" {
|
||||
uids = append(uids, id)
|
||||
}
|
||||
}
|
||||
if len(uids) == 0 {
|
||||
return nil, false, nil
|
||||
}
|
||||
userMap, err := s.userClient.GetUsersInfoMap(ctx, uids)
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, "GetUsersInfoMap for room participants failed", err, "roomID", roomID)
|
||||
out := make([]*rtc.ParticipantMetaData, 0, len(uids))
|
||||
for _, id := range uids {
|
||||
out = append(out, &rtc.ParticipantMetaData{UserInfo: &sdkws.PublicUserInfo{UserID: id}})
|
||||
}
|
||||
return out, true, nil
|
||||
}
|
||||
out := make([]*rtc.ParticipantMetaData, 0, len(uids))
|
||||
for _, id := range uids {
|
||||
ui := &sdkws.PublicUserInfo{UserID: id}
|
||||
if u := userMap[id]; u != nil {
|
||||
ui.Nickname = u.Nickname
|
||||
ui.FaceURL = u.FaceURL
|
||||
ui.Ex = u.Ex
|
||||
}
|
||||
out = append(out, &rtc.ParticipantMetaData{UserInfo: ui})
|
||||
}
|
||||
return out, true, nil
|
||||
}
|
||||
|
||||
// SignalGetTokenByRoomID returns a token for joining a room directly (HTTP API path).
|
||||
// Fix P0(安全): 同 handleGetTokenByRoomID,添加参与者身份校验。
|
||||
func (s *rtcServer) SignalGetTokenByRoomID(ctx context.Context, req *rtc.SignalGetTokenByRoomIDReq) (*rtc.SignalGetTokenByRoomIDResp, error) {
|
||||
@ -596,9 +655,12 @@ func (s *rtcServer) SignalGetRooms(ctx context.Context, req *rtc.SignalGetRoomsR
|
||||
}
|
||||
roomList := make([]*rtc.SignalGetRoomByGroupIDResp, 0, len(invs))
|
||||
for _, inv := range invs {
|
||||
participants, inCall, _ := s.livekitRoomParticipantsMeta(ctx, inv.RoomID)
|
||||
roomList = append(roomList, &rtc.SignalGetRoomByGroupIDResp{
|
||||
Invitation: modelToInvitationInfo(inv),
|
||||
RoomID: inv.RoomID,
|
||||
Invitation: modelToInvitationInfo(inv),
|
||||
RoomID: inv.RoomID,
|
||||
Participant: participants,
|
||||
InCall: inCall,
|
||||
})
|
||||
}
|
||||
return &rtc.SignalGetRoomsResp{RoomList: roomList}, nil
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user