Polyv Help Center

Help Center

3_5-云课堂场景-连麦

Updated: 2023-04-17 15:27:57

1 Feature Overview

The Polyv Cloud Classroom SDK supports the link mic feature, allowing free selection of hand-raising, audio, and video link mic options. It also supports multi-user link mic to enrich classroom content.

Link mic process: The instructor initiates a link mic -> Students raise hands to apply -> The instructor approves the student's application -> The student officially joins the link mic.

2 Usage Demo

In the demo project, PLVLCCloudClassViewController demonstrates how to create a link mic layout and how to call the initialization method.

self.linkMicAreaView = [[PLVLCLinkMicAreaView alloc] init];
self.linkMicAreaView.delegate = self;

Here, PLVLCLinkMicAreaView is responsible for managing the PLVLinkMicPresenter link mic manager, PLVLCLinkMicControlBar the link mic floating control bar, and PLVLCLinkMicWindowsView the link mic window list view. Therefore, PLVLCLinkMicAreaView can be integrated as a link mic module.

Additionally, PLVLCCloudClassViewController must conform to the protocol PLVLCLinkMicAreaViewDelegate. This protocol provides callbacks for first-screen switching, link mic status changes, and other related callbacks for view updates and switching. The protocol provides the following delegate methods:

@protocol PLVLCLinkMicAreaViewDelegate <NSObject>

/// RTC画面窗口 需外部展示 ‘第一画面连麦窗口’
///
/// @param linkMicAreaView 连麦区域视图
/// @param canvasView 第一画面连麦窗口视图 (需外部进行添加展示)
- (void)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView showFirstSiteCanvasViewOnExternal:(UIView *)canvasView;

/// RTC画面窗口被点击 (表示用户希望视图位置交换)
///
/// @note 当接收到此回调时,表示用户希望 某个Rtc画布视图(即canvasView) 在外部位置中显示,可对 canvasView 作相应布局处理
///
/// @param linkMicAreaView 连麦区域视图
/// @param canvasView Rtc画布视图
- (UIView *)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView rtcWindowDidClickedCanvasView:(UIView *)canvasView;

/// 恢复外部视图位置
///
/// @note 当外部视图需要回归原位时,此回调将被触发;接收到此回调后,可将 externalView 重新布局在原位上
///
/// @param linkMicAreaView 连麦区域视图
/// @param externalView 被添加在连麦区域视图上的外部视图
- (void)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView rollbackExternalView:(UIView *)externalView;

/// ‘是否在RTC房间中’ 状态值发生改变
///
/// @param linkMicAreaView 连麦区域视图
/// @param inRTCRoom 当前 是否在RTC房间中
- (void)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView inRTCRoomChanged:(BOOL)inRTCRoom;

/// ‘RTC房间在线用户数’ 发生改变
///
/// @param linkMicAreaView 连麦区域视图
/// @param currentRTCRoomUserCount 当前 RTC房间在线用户数
- (void)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView currentRTCRoomUserCountChanged:(NSInteger)currentRTCRoomUserCount;

/// ‘是否正在连麦’ 状态值改变
///
/// @param linkMicAreaView 连麦区域视图
/// @param inLinkMic 当前是否正在连麦 (YES:正在连麦中 NO:不在连麦中)
- (void)plvLCLinkMicAreaView:(PLVLCLinkMicAreaView *)linkMicAreaView inLinkMicChanged:(BOOL)inLinkMic;

/// 需获知 ‘当前频道是否直播中’
///
/// @note 此回调不保证在主线程触发
///
/// @param linkMicAreaView 连麦区域视图
- (BOOL)plvLCLinkMicAreaViewGetChannelInLive:(PLVLCLinkMicAreaView *)linkMicAreaView;

/// 需获知 ‘主讲的PPT 当前是否在主屏’
///
/// @note 此回调不保证在主线程触发
///
/// @param linkMicAreaView 连麦区域视图
- (BOOL)plvLCLinkMicAreaViewGetMainSpeakerPPTOnMain:(PLVLCLinkMicAreaView *)linkMicAreaView;

@end

In the -viewWillLayoutSubviews method, layout PLVLCLinkMicAreaView. For details, refer to the implementation of PLVLCCloudClassViewController in the demo project.

3 Implementation Introduction

3.1 PLVLinkMicPresenter

The PLVLinkMicPresenter link mic manager is managed by PLVLCLinkMicAreaView in the demo project. Refer to the instructions below to learn how to use PLVLinkMicPresenter independently.

The link mic feature module uses the MVP pattern, so the Presenter must be initialized first during implementation.

self.presenter = [[PLVLinkMicPresenter alloc] init];

self.presenter.delegate = self;

self.presenter.preRenderContainer = self;

Default values also need to be configured, based on those declared in the link mic floating control bar. See PLVLCLinkMicControlBarProtocol.h in the demo project for details. If business requirements change, modify the default values of PLVLCLinkMicControlBarProtocol.h directly, and the link mic manager will take effect simultaneously.

self.presenter.micDefaultOpen = PLVLCLinkMicControlBarMicDefaultOpen;

self.presenter.cameraDefaultOpen = PLVLCLinkMicControlBarCameraDefaultOpen;

self.presenter.cameraDefaultFront = PLVLCLinkMicControlBarSwitchCameraDefaultFront;

Additionally, using PLVLinkMicPresenter can conform to the protocol PLVLinkMicPresenterDelegate, and implement its delegate methods as needed. For more details, refer to the demonstration of PLVLCLinkMicAreaView in the demo project.

3.2 PLVLCLinkMicControlBar

The PLVLCLinkMicControlBar link mic floating control bar is managed by PLVLCLinkMicAreaView in the demo project. Refer to the instructions below to learn how to use PLVLCLinkMicControlBar for minor modifications or to rewrite it to implement business scenarios.

PLVLCLinkMicControlBar is initialized in PLVLCLinkMicAreaView, handling click events of the link mic floating control bar and refreshing its UI state. The main logic focuses on animations, click event responses, and keeping the UI synchronized between portrait and landscape orientations.

3.2.1 Initialization Method

PLVLCLinkMicLandscapeControlBar and PLVLCLinkMicPortraitControlBar are the portrait and landscape implementations of the link mic floating control bar PLVLCLinkMicControlBar, respectively.

_portraitControlBar = [[PLVLCLinkMicPortraitControlBar alloc] init];
_portraitControlBar.delegate = self;
_landscapeControlBar = [[PLVLCLinkMicLandscapeControlBar alloc] init];
_landscapeControlBar.delegate = self;

PLVLCLinkMicControlBarProtocol is an abstract protocol for the link mic control bar object, used in PLVLCLinkMicAreaView to control the current link mic floating control bar, currentControlBar. To implement [setCurrentControlBar], refer to the demonstration of PLVLCLinkMicAreaView in the demo project.

 self.currentControlBar = self.landscapeControlBar; //设置当前悬浮控制条为竖屏样式

At the appropriate time in PLVLCCloudClassViewController, currentControlBar needs to be inserted. For the specific implementation, refer to the demonstration of PLVLCCloudClassViewController in the demo project.

3.2.2 PLVLCLinkMicControlBarDelegate

PLVLCLinkMicAreaView must conform to the protocol PLVLCLinkMicControlBarDelegate and implement its delegate methods. Taking the link mic switch button click as an example, call PLVLinkMicPresenter's methods for applying to join, canceling the application, and exiting the link mic based on different states:

- (void)plvLCLinkMicControlBar:(id<PLVLCLinkMicControlBarProtocol>)bar onOffButtonClickedCurrentStatus:(PLVLCLinkMicControlBarStatus)status{
    __weak typeof(self) weakSelf = self;
    if (status == PLVLCLinkMicControlBarStatus_Open) {
        // Bar 处于显示 ‘申请连麦’,点击表示希望申请连麦
        [self.presenter requestJoinLinkMic];
    }else if (status == PLVLCLinkMicControlBarStatus_Waiting){
        // Bar 处于显示 ‘请求中...’,点击表示希望取消申请连麦
        [PLVFdUtil showAlertWithTitle:@"确认取消申请连麦吗?" message:nil viewController:[PLVFdUtil getCurrentViewController] cancelActionTitle:@"按错了" cancelActionStyle:UIAlertActionStyleDefault cancelActionBlock:nil confirmActionTitle:@"取消申请连麦" confirmActionStyle:UIAlertActionStyleDestructive confirmActionBlock:^(UIAlertAction * _Nonnull action) {
            [weakSelf.presenter cancelRequestJoinLinkMic];
        }];
    }else if (status == PLVLCLinkMicControlBarStatus_Joined){
        // Bar 处于已连麦,点击表示希望取消申请连麦
        [PLVFdUtil showAlertWithTitle:@"确认挂断连麦吗?" message:nil viewController:[PLVFdUtil getCurrentViewController] cancelActionTitle:@"按错了" cancelActionStyle:UIAlertActionStyleDefault cancelActionBlock:nil confirmActionTitle:@"挂断" confirmActionStyle:UIAlertActionStyleDestructive confirmActionBlock:^(UIAlertAction * _Nonnull action) {
            [weakSelf.presenter leaveLinkMic];
        }];
    }
}

For more details, refer to the demonstration of PLVLCLinkMicAreaView in the demo project.

3.3 PLVLCLinkMicWindowsView

PLVLCLinkMicWindowsView is the main component of the link mic feature module, responsible for displaying multiple link mic members' RTC video windows. This view supports left-right swipe browsing. The initialization method is as follows:

_windowsView = [[PLVLCLinkMicWindowsView alloc] init];
_windowsView.delegate = self;

Additionally, PLVLCLinkMicAreaView must conform to the protocol PLVLCLinkMicWindowsViewDelegate and implement its delegate methods to exchange data with the PLVLinkMicPresenter link mic manager. An example is shown below:

#pragma mark PLVLCLinkMicWindowsViewDelegate
/// 连麦窗口列表视图 需获知 ‘当前频道连麦场景类型’
- (PLVChannelLinkMicSceneType)plvLCLinkMicWindowsViewGetCurrentLinkMicSceneType:(PLVLCLinkMicWindowsView *)windowsView{
    return self.presenter.linkMicSceneType;//获取连麦管理当前频道连麦场景类型
}
/// 连麦窗口被点击事件 (表示用户希望某个窗口成为‘第一画面’)
- (void)plvLCLinkMicWindowsView:(PLVLCLinkMicWindowsView *)windowsView linkMicUserWantToBecomeFirstSite:(NSInteger)index{
    [self.presenter changeMainSpeakerInLocalWithLinkMicUserIndex:index];//连麦管理器请求变更‘第一画面’
}

/// 连麦窗口列表视图 需要获取当前用户数组
- (NSArray *)plvLCLinkMicWindowsViewGetCurrentUserModelArray:(PLVLCLinkMicWindowsView *)windowsView{
    return self.presenter.onlineUserArray;//获取连麦管理器当前RTC房间在线用户数组
}

For more details, refer to the demonstration of PLVLCLinkMicAreaView in the demo project.

联系客服,在线咨询