@coze/realtime-api
Version:
A powerful real-time communication SDK for voice interactions with Coze AI bots | 扣子官方实时通信 SDK,用于与 Coze AI bots 进行语音交互
87 lines (86 loc) • 2.22 kB
TypeScript
/**
* WebRTC资源状态
*/
export declare enum ResourceStatus {
IDLE = "idle",// 初始状态
CONNECTING = "connecting",// 连接中
CONNECTED = "connected",// 已连接
FAILED = "failed",// 连接失败
CLOSING = "closing",// 关闭中
CLOSED = "closed"
}
export type StatusChangeCallback = (status: ResourceStatus) => void;
/**
* 同声传译客户端
*/
export declare class WebLiveClient {
private peerConnection;
private resourceUrl;
private status;
private player;
private statusListeners;
private liveId;
constructor(liveId: string);
/**
* 获取当前连接状态
*/
getStatus(): ResourceStatus;
/**
* 添加状态变化监听器
* @param callback 状态变化回调函数
*/
onStatusChange(callback: StatusChangeCallback): void;
/**
* 移除状态变化监听器
* @param callback 要移除的回调函数
*/
offStatusChange(callback: StatusChangeCallback): void;
/**
* 移除状态变化监听器
* @param callback 要移除的回调函数
*/
removeStatusListener(callback: StatusChangeCallback): void;
/**
* 订阅音频资源
* @param appId 应用ID
* @param streamId 流ID
* @param clientId 客户端ID
*/
subscribe(appId: string, streamId: string, clientId?: string): Promise<{
status: ResourceStatus;
peerConnection: RTCPeerConnection;
}>;
/**
* 销毁订阅资源
*/
unsubscribe(): Promise<boolean>;
/**
* 静音/取消静音
* @param muted 是否静音
*/
setMuted(muted: boolean): void;
/**
* 关闭并清理资源
*/
close(): void;
/**
* 获取直播信息
*/
getLiveData: () => Promise<import("@coze/api").RetrieveLiveData>;
/**
* 等待ICE收集完成
* @param pc RTCPeerConnection实例
*/
private waitForIceGathering;
private setupPeerConnectionListeners;
/**
* 关闭PeerConnection
*/
private closePeerConnection;
/**
* 设置状态并触发监听回调
* @param newStatus 新状态
* @private 私有方法,仅内部使用
*/
private setStatus;
}