2026-05-14 00:25:02 +08:00

85 lines
2.8 KiB
Go

package roomapi
import (
"net/http"
"hyapp/pkg/tencentrtc"
"hyapp/services/gateway-service/internal/client"
"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
userSocialClient client.UserSocialClient
walletClient client.WalletClient
rtcTokenConfig tencentrtc.TokenConfig
}
type Config struct {
RoomClient client.RoomClient
RoomGuardClient client.RoomGuardClient
RoomQueryClient client.RoomQueryClient
UserProfileClient client.UserProfileClient
UserSocialClient client.UserSocialClient
WalletClient client.WalletClient
RTCTokenConfig tencentrtc.TokenConfig
}
func New(config Config) *Handler {
return &Handler{
roomClient: config.RoomClient,
roomGuardClient: config.RoomGuardClient,
roomQueryClient: config.RoomQueryClient,
userProfileClient: config.UserProfileClient,
userSocialClient: config.UserSocialClient,
walletClient: config.WalletClient,
rtcTokenConfig: config.RTCTokenConfig,
}
}
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,
ListRoomOnlineUsers: h.listRoomOnlineUsers,
GetRoomGiftPanel: h.getRoomGiftPanel,
FollowRoom: h.handleRoomFollow,
CreateRoom: h.createRoom,
UpdateRoomProfile: h.updateRoomProfile,
JoinRoom: h.joinRoom,
RoomHeartbeat: h.roomHeartbeat,
LeaveRoom: h.leaveRoom,
CloseRoom: h.closeRoom,
MicUp: h.micUp,
MicDown: h.micDown,
ChangeMicSeat: h.changeMicSeat,
ConfirmMicPublishing: h.confirmMicPublishing,
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,
}
}
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)
}