import { BuiltinMsg, LiveMsg } from './LiveMsg'; import { LiveState } from './LiveState'; import { UserInfo } from './UserInfo'; /** * 带看事件列表 */ export type LiveEventType = { /** * 带看连接状态变化事件 * * @param state 当前连接状态 * @param prevState 之前的连接状态(可选) * @example * ```typescript * live.on('stateChange', (state, prevState) => { * console.log(`状态从 ${prevState} 变为 ${state}`) * }) * ``` */ 'stateChange'(state: LiveState, prevState?: LiveState): void; /** * 内置消息事件 * * 当收到任何内置消息时触发,包括用户变化和房间变化。 * * @param builtinMsg 内置消息对象 * @example * ```typescript * live.on('builtinEvent', (msg) => { * console.log('内置消息:', msg.event_type, msg.action) * }) * ``` */ 'builtinEvent'(builtinMsg: BuiltinMsg): void; /** * 用户信息改变事件 * * 当用户信息发生变化时触发,是 builtinEvent 的子集。 * * @param builtinMsg 内置消息对象,event_type 为 UserChange * @example * ```typescript * live.on('userChange', (msg) => { * if (msg.action === BuiltinActionType.UserMicroStatus) { * console.log('麦克风状态变化:', msg.data.status) * } * }) * ``` */ 'userChange'(builtinMsg: BuiltinMsg): void; /** * 房间信息改变事件 * * 当房间信息发生变化时触发,是 builtinEvent 的子集。 * * @param builtinMsg 内置消息对象,event_type 为 RoomChange * @example * ```typescript * live.on('roomChange', (msg) => { * if (msg.action === BuiltinActionType.RoomClose) { * console.log('房间已关闭') * } * }) * ``` */ 'roomChange'(builtinMsg: BuiltinMsg): void; /** * 收到其他用户的广播消息事件 * * 当收到其他用户通过 broadcast 方法发送的自定义消息时触发。 * * @param evtMsg 广播消息数据对象 * @param frontRequestId 前端请求ID,用于匹配请求和响应 * @example * ```typescript * live.on('broadcast', (data, requestId) => { * console.log('收到广播:', data, '请求ID:', requestId) * }) * ``` */ 'broadcast'(evtMsg: Record, frontRequestId: string): void; /** * 带看已经就绪,可以发送帧数据。 * @param lastKeyframe 带看最后一帧数据(链接切换、断网等重连恢复上次会话帧状态),你可以通过此数据拉齐当前UI状态。 * @deprecated 此事件已废弃,请使用 `keyframes` 事件替代,最后的帧数据会通过 `keyframes` 事件发送,同时 keyframes 对象在 ready 后会自动更新。 */ 'readyKeyframeSync'(lastKeyframe: Partial): void; /** * 获取其他用户输送的帧数据:根据此帧数据更新UI状态。 * @param keyframes */ 'keyframes'(keyframes: Partial, frontRequestId: string): void; /** * 个人信息发生更新。 * @param userInfo */ 'selfInfoUpdate'(userInfo: UserInfo, frontRequestId: string): void; /** * 用户列表更新。 * @param userList */ 'userListUpdate'(userList: UserInfo[], frontRequestId: string): void; /** * 被踢出房间 * */ 'kickOut'(): void; /** * 异常消息:不符合规范。 * @param liveMsg */ 'error'(liveMsg: LiveMsg): void; }; /** * 帧数据订阅发布的事件描述 */ export type KeyframeEventType = { [key in keyof KeyframesSnapshot]: (nextKeyframes: KeyframesSnapshot[key], prevKeyframes: KeyframesSnapshot[key], frontRequestId: string) => void; }; /** * 事件解析 */ export type EventType = LiveEventType;