68 lines
2.8 KiB
Go
68 lines
2.8 KiB
Go
package chat
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
)
|
||
|
||
// LiveKit 表示一台LiveKit服务器配置
|
||
type LiveKit struct {
|
||
ID string `bson:"_id" json:"id"` // 服务器唯一标识
|
||
Name string `bson:"name" json:"name"` // 服务器名称
|
||
URL string `bson:"url" json:"url"` // LiveKit服务器地址
|
||
Key string `bson:"key" json:"key"` // API Key
|
||
Secret string `bson:"secret" json:"secret"` // API Secret
|
||
Region string `bson:"region" json:"region"` // 服务器区域
|
||
Status int `bson:"status" json:"status"` // 状态:0-禁用,1-启用
|
||
Priority int `bson:"priority" json:"priority"` // 优先级,数字越小优先级越高
|
||
MaxRooms int `bson:"max_rooms" json:"max_rooms"` // 最大房间数
|
||
MaxUsers int `bson:"max_users" json:"max_users"` // 最大用户数
|
||
Description string `bson:"description" json:"description"` // 描述信息
|
||
CreateTime time.Time `bson:"create_time" json:"create_time"` // 创建时间
|
||
UpdateTime time.Time `bson:"update_time" json:"update_time"` // 更新时间
|
||
}
|
||
|
||
// TableName 返回表名
|
||
func (LiveKit) TableName() string {
|
||
return "livekits"
|
||
}
|
||
|
||
// LiveKitInterface 定义LiveKit数据库操作接口
|
||
type LiveKitInterface interface {
|
||
// Create 创建LiveKit服务器配置
|
||
Create(ctx context.Context, livekits ...*LiveKit) error
|
||
// Delete 删除LiveKit服务器配置
|
||
Delete(ctx context.Context, ids []string) error
|
||
// Update 更新LiveKit服务器配置
|
||
Update(ctx context.Context, livekit *LiveKit) error
|
||
// FindByID 根据ID查找LiveKit配置
|
||
FindByID(ctx context.Context, id string) (*LiveKit, error)
|
||
// FindByStatus 根据状态查找LiveKit配置列表
|
||
FindByStatus(ctx context.Context, status int) ([]*LiveKit, error)
|
||
// FindAll 查找所有LiveKit配置
|
||
FindAll(ctx context.Context) ([]*LiveKit, error)
|
||
// FindAvailable 查找可用的LiveKit服务器(按优先级排序)
|
||
FindAvailable(ctx context.Context) ([]*LiveKit, error)
|
||
// FindByRegion 根据区域查找LiveKit配置
|
||
FindByRegion(ctx context.Context, region string) ([]*LiveKit, error)
|
||
// UpdateStatus 更新服务器状态
|
||
UpdateStatus(ctx context.Context, id string, status int) error
|
||
// UpdatePriority 更新服务器优先级
|
||
UpdatePriority(ctx context.Context, id string, priority int) error
|
||
// GetNextAvailable 获取下一个可用的LiveKit服务器(负载均衡)
|
||
GetNextAvailable(ctx context.Context) (*LiveKit, error)
|
||
}
|
||
|
||
// 状态常量
|
||
const (
|
||
LiveKitStatusDisabled = 0 // 禁用
|
||
LiveKitStatusEnabled = 1 // 启用
|
||
)
|
||
|
||
// 默认值
|
||
const (
|
||
DefaultMaxRooms = 1000 // 默认最大房间数
|
||
DefaultMaxUsers = 100 // 默认最大用户数
|
||
DefaultPriority = 100 // 默认优先级
|
||
)
|