7_6-核心common-PPT
更新時間:2023-04-17 15:27:57
1 功能概述
common模組的PPT是使用MVP模式實作的,將PPT的一些與UI無關的底層邏輯封裝在此模組中。
2 MVP模式
PPT模組包含兩個MVP的介面,分別是懸浮窗和PPT:
懸浮窗
/**
* 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實作邏輯
2.1.1 PLVLiveFloatingPresenter
懸浮窗的Presenter主要邏輯是,使用socket管理器監聽聊天室發出的講師資訊事件,並將資料解析後更新到View介面:
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中實作了對PPT事件的收發操作。
監聽server發來的PPT訊息,解析後將訊息發送到View層,由View層的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 //... } } } );當使用者操作PPT畫筆時,要將畫筆資料發送到server(該功能暫未實作)
//发送画笔事件 PolyvSocketWrapper.getInstance().emit(PLVEventConstant.MESSAGE_EVENT, message);
3 SDK核心類別介紹
3.1 用PolyvSocketWrapper收發服務端PPT訊息
common模組的PPT用到的SDK類別是PolyvSocketWrapper,利用此類別,既可以監聽服務端老師發送的PPT事件,也可以主動發送PPT資料到服務端。
具體可參考PLVLiveFloatingPresenter和PLVPPTPresenter中對該類別的使用。
3.2 PPT使用的WebView
PPT使用的是SDK提供的PolyvPPTWebView類別進行渲染,對該類別的使用均封裝在Scene模組的PLVLCPPTView類別中,只是呼叫邏輯在presenter。
他有3類API:
通用對外API
//注册被js调用的方法 public void registerHandler(); //加载webView public void loadWeb(); //发送消息到JS public void callMessage(String event, String message);直播對外API
//发送消息到JS public void callUpdateWebView(String messages);回放對外API
//发送播放开始 public void callStart(String messages); //发送播放暂停 public void callPause(String messages); //发送seek public void callSeek(String messages); //发送PPT数据 public void callPPTParams(String messages);
