Polyv Help Center

Help Center

核心common 数据

Updated: 2023-04-27 09:43:40

1 Overview

This module is located under the folder PolyvLiveCommonModule/Modules/Room. The data it manages includes: configuration data, HTTP data, business module data, etc. These data are combined and accessed or stored using the data model class PLVRoomData, with PLVRoomDataManager serving as the external data router. When data changes, it notifies all registered listening business modules.

2 Core Class Introduction

2.1 PLVRoomData

The data model class PLVRoomData provides the following interfaces externally. The data returned by these interfaces is held by PLVRoomData:

/// 设置 roomUser
- (void)setupRoomUser:(PLVRoomUser *)roomUser;

/// 获取频道菜单信息
- (void)requestChannelDetail:(void(^)(PLVLiveVideoChannelMenuInfo *channelMenuInfo))completion;

/// 上报观看热度
- (void)reportViewerIncrease;

/// 获取功能开关
- (void)requestChannelFunctionSwitch;

Except for the interface -requestChannelFunctionSwitch, which is requested (optionally) when initializing the chat room, all other interfaces (mandatory) are called during login. For usage examples, see the login manager PLVRoomLoginClient.

2.2 PLVRoomDataManager

The data router PLVRoomDataManager is a singleton responsible for holding the PLVRoomData object, of which only one instance is allowed per live room. It performs KVO monitoring on the held roomData object. When the data managed by roomData changes, it notifies all registered listening business modules.

In the data router PLVRoomDataManager, the property-related interface definitions for roomData are as follows:

/// 当前活跃的直播间数据
@property (nonatomic, strong, readonly) PLVRoomData *roomData;

/// 单例方法
+ (instancetype)sharedManager;

/// 配置当前的直播间数据,进入直播间时调用
- (void)configRoomData:(PLVRoomData *)roomData;

/// 移除当前的直播间数据,离开直播间时调用
- (void)removeRoomData;

Usage examples are as follows. For the context of interface calls, see the login manager PLVRoomLoginClient:

// 登录时调用
[[PLVRoomDataManager sharedManager] configRoomData:roomData];
// 退出登录时调用
[[PLVRoomDataManager sharedManager] removeRoomData];

The interfaces for registering and removing data listeners are as follows:

/// 增加PLVRoomDataManagerProtocol协议的监听者
/// @param delegate 待增加的监听者
/// @param delegateQueue 执行回调的队列
- (void)addDelegate:(id<PLVRoomDataManagerProtocol>)delegate delegateQueue:(dispatch_queue_t)delegateQueue;

/// 移除PLVRoomDataManagerProtocol协议的监听者
/// @param delegate 待移除的监听者
- (void)removeDelegate:(id<PLVRoomDataManagerProtocol>)delegate;

/// 移除PLVRoomDataManagerProtocol协议的所有监听者
- (void)removeAllDelegates;

The interface -removeAllDelegates is called internally by the data router PLVRoomDataManager when invoking -removeAllDelegates to remove the currently held live room data. You only need to call the -addDelegate:delegateQueue: interface in each business module or functional page that needs to listen to roomData data, and call the -removeDelegate: interface when listening is no longer needed (e.g., when a page exits or a module is unregistered).

联系客服,在线咨询
在线咨询