Polyv Help Center

Help Center

Module Events

Updated: 2024-10-10 17:27:10

1. Chat Room Information Change

Event: ChatEvents.ChatInfoChange

Callback Parameters: Object object, detailed type description as follows

Property Description Type
chatInfo Chat room information ChatModuleInfo

2. Chat Room Connection Failure Event

Description: This event is triggered when the chat room connection fails due to network disconnection or other factors.

Event: ChatEvents.ChatConnectFail

Callback Parameters: Object object, detailed type description as follows

Property Description Type
reason Reason for connection failure ChatConnectFailReason

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ChatConnectFail, (data) => {
  confirm({
    message: '聊天室连接失败,无法与其他人互动,立即刷新重试?',
    onConfirm: () => location.reload(),
  });
});

3. Chat Message Event

Description: This event is triggered when a chat message is received.

Event: ChatEvents.ChatMessage

Callback Parameters: Object object, detailed type description as follows

Property Description Type
chatMsg Chat message object ChatMsgType

Example:

// 聊天消息列表
const chatMsgList: ChatMsgType[] = [];

// 聊天消息事件
watchCore.chat.eventEmitter.on(ChatEvents.ChatMessage, (data) => {
// 插入到聊天消息列表
  chatMsgList.push(data.chatMsg);
  // 渲染聊天消息...
});

4. Replace Chat Message Event

When calling methods like sendSpeakMsg to send a message, the ChatEvents.ChatMessage event is called back before sending to the server. At this point, the message ID is a local ID. After the message is sent to the server and the message ID is called back, this event is triggered. Upon receiving this event, update to the new message object and rendering information based on the ID.

Additionally, if the server detects an inappropriate image when sending an image message, it is also updated through this event.

Event: ChatEvents.ReplaceChatMessage

Callback Parameters: Object object, detailed type description as follows

Property Description Type
id Replaced message ID string
chatMsg New message object ChatMsgType

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ReplaceChatMessage, (data) => {
  // 需要被替换的消息 id
  const replaceId = data.id;
  // 新的消息对象
  const chatMsg = data.chatMsg;

  const index = chatMsgList.findIndex((item) => item.id === replaceId);
  if (index !== -1) {
    chatMsgList[index] = chatMsg;
  }
  // 将视图的消息节点替换...
});

5. Like Event

Description: Listen for user like events through this event.

Event: ChatEvents.ChatLike

Callback Parameters: Object object, detailed type description as follows

Property Description Type
count Number of likes number
realtimeLikes Real-time like count number
userId User ID string
nick User nickname string
isSelf Whether it is a self-like boolean

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ChatLike, (data) => {
  console.log('实时点赞数:', data.realtimeLikes);
  console.log('该观众的点赞次数', data.count);
  console.log('点赞的观众 id', data.userId);
  console.log('点赞的观众昵称', data.nick);
});

6. Like Count Change Event

Description: Listen for like count change events through this event. Update the like count display on the page after the callback.

Event: ChatEvents.ChatLikeCountChange

Callback Parameters: Object object, detailed type description as follows

Property Description Type
realtimeLikes Real-time like count number

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ChatLikeCountChange, (data) => {
  console.log('实时点赞数:', data.realtimeLikes);
});

7. Chat Room User Login Event

Description: This event is triggered when a viewer enters the chat room.

Event: ChatEvents.ChatUserLogin

Callback Parameters: Object object, detailed type description as follows

Property Description Type
user User information ChatMessageUser

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ChatUserLogin, (data) => {
  const user = data.user;
  toast.info(`欢迎 ${user.nick} 进入`);
});

8. Chat Room User Logout Event

Description: This event is triggered when a viewer exits the chat room.

Event: ChatEvents.ChatUserLogout

Callback Parameters: Object object, detailed type description as follows

Property Description Type
userId User userId string

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ChatUserLogout, (data) => {
  const userId = data.userId;
  console.log('退出的用户 id', userId);
});

9. Current User Duplicate Login Event

Description: This event is triggered when a user logs into the chat room repeatedly. After triggering, the current page will not be able to receive any chat room messages.

Event: ChatEvents.CurrentUserRelogin

Example:

watchCore.chat.eventEmitter.on(ChatEvents.CurrentUserRelogin, (data) => {
  toast.errot('您已在其他地方登录,3 秒后将推出该页面');
  setTimeout(() => {
    location.replace('跳出到页面地址');
  }, 3000);
});

10. Clear Chat Room Event

Description: This event is triggered after an administrator clears the chat history.

Event: ChatEvents.ClearMsgHistory

Example:

watchCore.chat.eventEmitter.on(ChatEvents.ClearMsgHistory, () => {
  console.log('管理员清空历史记录,todo 清空聊天记录列表');
});

11. Delete a Message Event

Description: This event is triggered after an administrator deletes a historical message.

Event: ChatEvents.RemoveChatMsg

Callback Parameters: Object object, detailed type description as follows

Property Description Type
id Deleted message ID string

Example:

watchCore.chat.eventEmitter.on(ChatEvents.RemoveChatMsg, (data) => {
  console.log('管理员删除历史消息,删除的消息 id:', data.id);
});

12. Chat Room Close Event

Description: This event is triggered after the instructor or administrator closes the chat room.

Event: ChatEvents.CloseChatRoom

Example:

watchCore.chat.eventEmitter.on(ChatEvents.CloseChatRoom, () => {
  watchCore.chat.sendSystemMsg('聊天室已关闭');
});

13. Chat Room Open Event

Description: This event is triggered after the instructor or administrator opens the chat room.

Event: ChatEvents.OpenChatRoom

Example:

watchCore.chat.eventEmitter.on(ChatEvents.CloseChatRoom, () => {
  watchCore.chat.sendSystemMsg('聊天室已打开');
});

14. Online User Count Change Event

Description: When viewers come online/go offline, this event is called back to obtain the real-time online user count.

Event: ChatEvents.OnlineUserCountChange

Callback Parameters: Object object, detailed type description as follows

Property Description Type
onlineUserCount Real-time online user count number

Example:

watchCore.chat.eventEmitter.on(ChatEvents.OnlineUserCountChange, (data) => {
  console.log('在线人数改变:', data.onlineUserCount);
});
联系客服,在线咨询
在线咨询