Polyv Help Center

Help Center

5-聊天室

Updated: 2025-08-29 11:30:56

1. Chat Room

The core external class of the chat room manager is PLVChatroomManager, which can be accessed via the chatroomManager property of the SDK object.

2. Login

Message sending and receiving in the chat room rely on sockets, so socket login must be performed first before the chat room can be used normally. The core external class of the socket manager is PLVSocketManager, which can be accessed via the socketManager property of the SDK object:

// 监听socket连接状态
sdk.socketManager.onStatus()
// socket登录
sdk.socketManager.login()

For detailed usage code, refer to the PLVLWWatchLayout class in the demo project.

3. Callbacks

Chat room socket channel messages and business event messages are monitored through callback registration, including:

  • onData: Socket channel message callback registration
  • eventNotify.on: Business event message callback registration

For example, to listen for announcement/remove announcement messages on the socket channel, you can monitor them as follows:

sdk.chatroomManager.onData(PLVSocketOnEvent.MESSAGE, (data: string, event: string) => {
  switch (event) {
  // 公告
    case PLVBulletinEvent.EVENT:
      break;
  // 移除公告
    case PLVRemoveBulletinEvent.EVENT:
      break;
    default:
      break;
  }
}, this)

For detailed usage code, refer to the PLVLWWatchLayout and PLVLIChatListLayout classes in the demo project.

4. Speaking

You can use the speak method of the chat room to speak:

// messsage:要发言的消息,replay:携带的回复消息,非回复时为undefined
sdk.chatroomManager.speak(message, replay)

For detailed usage code, refer to the PLVLIChatInputView class in the demo project.

5. Asking Questions

You can use the quiz method of the chat room to ask questions:

sdk.chatroomManager.quiz(message)

For detailed usage code, refer to the PLVLIChatInputView class in the demo project.

联系客服,在线咨询