7_6-核心common-PPT
1 Feature Overview
The PPT in the common module is implemented using the MVP pattern, encapsulating UI-independent underlying logic of the PPT within this module.
2 MVP Pattern
The PPT module includes two MVP interfaces: one for the floating window and one for the PPT:
Floating Window
/**
* date: 2020/9/16
* author: HWilliamgo
* description: 悬浮窗业务MVP
*/
public interface IPLVLiveFloatingContract {
/**
* 悬浮窗View
*/
interface IPLVLiveFloatingView {
/**
* 设置讲师信息
*
* @param nick 讲师昵称
* @param picUrl 讲师图片Url
*/
void updateTeacherInfo(String nick, String picUrl);
}
/**
* 悬浮窗业务Presenter
*/
interface IPLVLiveFloatingPresenter {
/**
* 初始化
*/
void init(IPLVLiveFloatingView view);
/**
* 销毁
*/
void destroy();
}
}
PPTView
/**
* date: 2020/9/16
* author: HWilliamgo
* description: PPT业务MVP
*/
public interface IPLVPPTContract {
/**
* PPTView
*/
interface IPLVPPTView {
/**
* 发送消息到webView
*
* @param msg 消息
*/
void sendMsgToWebView(String msg);
/**
* 发送消息到webView
*
* @param msg 消息
* @param event 事件
*/
void sendMsgToWebView(String msg, String event);
/**
* 隐藏加载中图片
* 直播时,则聊天室登录后,收到PPT控制消息时,隐藏加载中图片。
* 回放时,在收到PPT的prepare回调后,异常加载中图片。
*/
void hideLoading();
}
/**
* PPT Presenter
*/
interface IPLVPPTPresenter {
/**
* 初始化
*
* @param view view
*/
void init(IPLVPPTView view);
/**
* 移除消息延迟时间
*/
void removeMsgDelayTime();
/**
* 恢复消息延迟时间
*/
void recoverMsgDelayTime();
/**
* 发送画笔消息
*/
void sendPPTBrushMsg(String msg);
/**
* 销毁
*/
void destroy();
}
}
2.1 Presenter Implementation Logic
2.1.1 PLVLiveFloatingPresenter
The main logic of the floating window's Presenter is to use the socket manager to listen for instructor information events emitted by the chat room, parse the data, and update it to the View interface:
PolyvSocketWrapper.getInstance().getSocketObserver().addOnMessageListener(onMessageListener = new PLVSocketMessageObserver.OnMessageListener() {
@Override
public void onMessage(String listenEvent, String event, String message) {
if (PLVEventConstant.Class.O_TEACHER_INFO.equals(event)) {
PLVTeacherInfoEvent teacherInfoEvent = PLVEventHelper.toMessageEventModel(message, PLVTeacherInfoEvent.class);
if (teacherInfoEvent != null) {
String teacherNick = teacherInfoEvent.getData().getNick();
String picUrl = teacherInfoEvent.getData().getPic();
if (view != null) {
view.updateTeacherInfo(teacherNick, picUrl);
}
}
}
}
});
2.2.2 PLVPPTPresenter
PLVPPTPresenter implements the sending and receiving operations for PPT events.
Listen for PPT messages sent by the server, parse the messages, and send them to the View layer for processing by the View layer's WebView:
PolyvSocketWrapper.getInstance().getSocketObserver().addOnMessageListener( onMessageListener = new PLVSocketMessageObserver.OnMessageListener() { @Override public void onMessage(String listenEvent, String event, String message) { if (PLVEventConstant.Ppt.ON_SLICE_START_EVENT.equals(event) || PLVEventConstant.Ppt.ON_SLICE_DRAW_EVENT.equals(event) || PLVEventConstant.Ppt.ON_ASSISTANT_CONTROL.equals(event) || PLVEventConstant.Ppt.ON_SLICE_OPEN_EVENT.equals(event) || PLVEventConstant.Ppt.ON_SLICE_ID_EVENT.equals(event)) { //... } else if (PLVEventConstant.MESSAGE_EVENT_LOGIN.equals(event)) { //发送login事件到ppt //... } } } );When a user operates the PPT pen, the pen data should be sent to the server (this feature is not yet implemented):
//发送画笔事件 PolyvSocketWrapper.getInstance().emit(PLVEventConstant.MESSAGE_EVENT, message);
3 SDK Core Class Introduction
3.1 Sending and Receiving Server PPT Messages with PolyvSocketWrapper
The SDK class used by the PPT in the common module is PolyvSocketWrapper. Using this class, you can both listen for PPT events sent by the server's instructor and actively send PPT data to the server.
For specific usage, refer to the use of this class in PLVLiveFloatingPresenter and PLVPPTPresenter.
3.2 WebView Used for PPT
The PPT is rendered using the PolyvPPTWebView class provided by the SDK. The usage of this class is encapsulated in the PLVLCPPTView class of the Scene module, with the calling logic residing in the presenter.
It has three types of APIs:
General Public API
//注册被js调用的方法 public void registerHandler(); //加载webView public void loadWeb(); //发送消息到JS public void callMessage(String event, String message);Live Streaming Public API
//发送消息到JS public void callUpdateWebView(String messages);Playback Public API
//发送播放开始 public void callStart(String messages); //发送播放暂停 public void callPause(String messages); //发送seek public void callSeek(String messages); //发送PPT数据 public void callPPTParams(String messages);
