@bililive-tools/douyin-recorder
Version:
@bililive-tools douyin recorder implemention
72 lines (71 loc) • 1.9 kB
TypeScript
import type { APIType, APIEndpoint, APIEndpointStatus, LoadBalancerConfig } from "../types.js";
/**
* API 负载均衡器类
* 实现多个 API 接口的负载均衡调用,具备失败重试和禁用机制
*/
export declare class APILoadBalancer {
private endpoints;
private config;
constructor(config?: Partial<LoadBalancerConfig>);
/**
* 初始化 API 端点配置
*/
private initializeEndpoints;
/**
* 获取下一个可用的 API 端点
* 使用加权轮询算法,优先选择权重高且未被禁用的端点
*/
private getNextEndpoint;
/**
* 记录 API 调用失败
*/
private recordFailure;
/**
* 记录 API 调用成功
*/
private recordSuccess;
/**
* 使用负载均衡策略调用 getRoomInfo
*/
callWithLoadBalance(webRoomId: string, opts?: {
auth?: string;
doubleScreen?: boolean;
uid?: string | number;
}): Promise<{
living: boolean;
roomId: string;
owner: string;
title: string;
streams: any[];
sources: any[];
avatar: string;
cover: string;
liveId: string;
uid: string;
}>;
/**
* 获取当前端点状态(用于调试和监控)
*/
getEndpointStatus(): APIEndpointStatus[];
/**
* 手动重置某个端点的状态
*/
resetEndpoint(apiType: APIType): void;
/**
* 重置所有端点状态
*/
resetAllEndpoints(): void;
/**
* 更新端点配置
*/
updateEndpointConfig(apiType: APIType, updates: Partial<APIEndpoint>): void;
/**
* 获取负载均衡器配置
*/
getConfig(): LoadBalancerConfig;
/**
* 更新负载均衡器配置
*/
updateConfig(updates: Partial<LoadBalancerConfig>): void;
}
export declare const globalLoadBalancer: APILoadBalancer;