package roomapi import ( "net/http" "time" "hyapp/pkg/tencentrtc" "hyapp/services/gateway-service/internal/client" "hyapp/services/gateway-service/internal/transport/http/appapi" "hyapp/services/gateway-service/internal/transport/http/httproutes" ) // Handler owns room-facing HTTP endpoints in gateway. // It keeps gateway as protocol adapter only: room state still belongs to room-service. type Handler struct { roomClient client.RoomClient roomGuardClient client.RoomGuardClient roomQueryClient client.RoomQueryClient userProfileClient client.UserProfileClient userCountryClient client.UserCountryQueryClient userRegionClient client.UserRegionClient userSocialClient client.UserSocialClient userHostClient client.UserHostClient appConfigReader appapi.ConfigReader walletClient client.WalletClient giftPanelCache *roomGiftPanelConfigCache growthLevelClient client.GrowthLevelClient achievementClient client.AchievementClient rtcTokenConfig tencentrtc.TokenConfig // gift-panel 的预算保留在 handler 内,生产使用固定安全值;测试可缩短预算验证真实超时分支, // 避免把 Flutter 的 15 秒客户端超时当成后端取消机制。 giftPanelTotalBudget time.Duration giftPanelRecipientCoreBudget time.Duration } type Config struct { RoomClient client.RoomClient RoomGuardClient client.RoomGuardClient RoomQueryClient client.RoomQueryClient UserProfileClient client.UserProfileClient UserCountryClient client.UserCountryQueryClient UserRegionClient client.UserRegionClient UserSocialClient client.UserSocialClient UserHostClient client.UserHostClient AppConfigReader appapi.ConfigReader WalletClient client.WalletClient GrowthLevelClient client.GrowthLevelClient AchievementClient client.AchievementClient RTCTokenConfig tencentrtc.TokenConfig } func New(config Config) *Handler { return &Handler{ roomClient: config.RoomClient, roomGuardClient: config.RoomGuardClient, roomQueryClient: config.RoomQueryClient, userProfileClient: config.UserProfileClient, userCountryClient: config.UserCountryClient, userRegionClient: config.UserRegionClient, userSocialClient: config.UserSocialClient, userHostClient: config.UserHostClient, appConfigReader: config.AppConfigReader, walletClient: config.WalletClient, giftPanelCache: newRoomGiftPanelConfigCache(45 * time.Second), growthLevelClient: config.GrowthLevelClient, achievementClient: config.AchievementClient, rtcTokenConfig: config.RTCTokenConfig, giftPanelTotalBudget: roomGiftPanelTotalBudget, giftPanelRecipientCoreBudget: roomGiftPanelRecipientCoreBudget, } } func (h *Handler) RoomHandlers() httproutes.RoomHandlers { return httproutes.RoomHandlers{ GetMyRoom: h.getMyRoom, ListRoomFeeds: h.listRoomFeeds, ListRooms: h.listRooms, GetCurrentRoom: h.getCurrentRoom, GetRoomSnapshot: h.getRoomSnapshot, GetRoomDetail: h.getRoomDetail, GetRoomShare: h.getRoomShare, GetRoomShareLanding: h.getRoomShareLanding, ListRoomOnlineUsers: h.listRoomOnlineUsers, ListRoomBannedUsers: h.listRoomBannedUsers, GetRoomContributionRank: h.getRoomContributionRank, GetRoomGiftPanel: h.getRoomGiftPanel, GetRoomRocket: h.getRoomRocket, FollowRoom: h.handleRoomFollow, CreateRoom: h.createRoom, UpdateRoomProfile: h.updateRoomProfile, SaveRoomBackground: h.saveRoomBackground, ListRoomBackgrounds: h.listRoomBackgrounds, SetRoomBackground: h.setRoomBackground, JoinRoom: h.joinRoom, RoomHeartbeat: h.roomHeartbeat, LeaveRoom: h.leaveRoom, CloseRoom: h.closeRoom, MicUp: h.micUp, MicDown: h.micDown, ChangeMicSeat: h.changeMicSeat, ConfirmMicPublishing: h.confirmMicPublishing, MicHeartbeat: h.micHeartbeat, SetMicMute: h.setMicMute, SetMicSeatLock: h.setMicSeatLock, SetChatEnabled: h.setChatEnabled, SetRoomPassword: h.setRoomPassword, SetRoomAdmin: h.setRoomAdmin, MuteUser: h.muteUser, KickUser: h.kickUser, UnbanUser: h.unbanUser, SendGift: h.sendGift, SendGiftBatch: h.sendGiftBatch, } } func (h *Handler) IssueTencentRTCToken(writer http.ResponseWriter, request *http.Request) { h.issueTencentRTCToken(writer, request) } func (h *Handler) BatchRoomDisplayProfiles(writer http.ResponseWriter, request *http.Request) { h.batchRoomDisplayProfiles(writer, request) }