WhiteWebSdk
对象是一切的开始,使用它,可以间接构造出 room
、player
对象。业务代码中,应该以单例模式构造它。
var whiteWebSdk = new WhiteWebSdk({
appIdentifier: "$APP_IDENTIFIER",
...{otherConfiguration},
});
其中,appIdentifier
是必填的。你可以阅读《AppIdentifier|项目与权限》来了了解如何获取 appIdentifier
。
此外,WhiteWebSdk
的构造函数格式如下。
class WhiteWebSdk {
constructor(configuration: WhiteWebSdkConfiguration);
}
WhiteWebSdkConfiguration
是 WhiteWebSdk
构造函数的参数,其定义如下。
type WhiteWebSdkConfiguration = {
readonly appIdentifier: string;
readonly useMobXState?: boolean;
readonly deviceType?: DeviceType;
readonly screenType?: ScreenType;
readonly renderEngine?: RenderEngine;
readonly fonts?: UserFonts;
readonly handToolKey?: string;
readonly fontFamily?: string;
readonly preloadDynamicPPT?: boolean;
readonly loggerOptions?: LoggerOptions;
readonly reconnectionOptions?: Partial<ReconnectionOptions> | false;
readonly onlyCallbackRemoteStateModify?: boolean;
readonly pptParams?: PptParams;
readonly urlInterrupter?: (url: string) => string;
readonly onWhiteSetupFailed?: (error: Error) => void;
readonly plugins?: Plugins;
readonly invisiblePlugins?: ReadonlyArray<InvisiblePluginClass<string, any>>;
readonly wrappedComponents?: WrappedComponents;
};
从管理控制台获取的参数,用于让 Netless 识别该客户端属于哪个账号的哪个项目,以便处理好权限和计费相关事宜。你可以阅读《AppIdentifier|项目与权限》来了了解如何获取 appIdentifier
设置成 true
后,displayer.state
会变成一个 MobX observable object,其成员变量只读,相当于都被修饰了 @observable
。这意味着,当它的成员发生变化时,你可以用 MobX 的方式监听它的变化并自动响应。
MobX 是 JavaScript 社区的透明的函数响应式编程库,你可以阅读《@observable》 来了解 observable object 是什么意思。
如果该值不填,或填为 false
,则 displayer.state
是一个普通的 JavaScript object。
该客户端的设备类型,决定 SDK 如何处理鼠标事件和触碰事件。如果填写错误,会导致 SDK 对设备输入响应行为不符合预期。如果不填,则会根据内在逻辑自动判断设备的类型。
其类型为 DeviceType
,定义如下。
enum DeviceType {
// 桌面端设备,如 PC、笔记本电脑
Desktop = "desktop",
// 触摸设备,如智能手机、平板电脑
Touch = "touch",
// 同时支持键盘鼠标和触摸屏的设备
Surface = "surface",
}
该客户端的屏幕类型,用于调整手势识别参数,默认为 ScreenType.Desktop
。其类型 ScreenType
的定义如下。
enum ScreenType {
// 桌面端屏幕,如 PC、笔记本电脑
Desktop = "desktop",
// 智能手机
Phone = "phone",
// 平板电脑
Pad = "pad",
// 电视
TV = "tv",
}
对画面的渲染模式,默认值为 RenderEngine.Canvas
。其类型 RenderEngine
的定义如下。
enum RenderEngine {
// 以 SVG 的形式渲染图形
SVG = "svg",
// 以 Canvas 的形式渲染图形
Canvas = "canvas",
}
这两种渲染模式渲染出的画面没有区别,其中 RenderEngine.Canvas
的性能更好,我们强烈建议你用该模式渲染画面。
为 PPT 提供自定义字体文件。如果你使用了 PPT 转网页服务,并且 PPT 中使用了非默认字体,并将转化后的文件在房间里展示,你必须正确配置这个字段,才能让 PPT 正确展示。
抓手工具热键。按下该键时,会自动切换成抓手工具(currentApplianceName="hand"
),松开后,切回原来的工具。如果不传,则关闭该功能。
设置文字工具(currentApplianceName="text"
)的字体。若不传,文字工具则展示浏览器默认字体。
2.11.12 新增 useServerWrap 功能
type PptParams = {
useServerWrap?: boolean;
};
动态 ppt 专用参数。
目前字段 useServerWrap 默认关闭,后续版本会变更为打开状态。开启后,会使用服务器端排版结果,避免各平台显示效果不一致。该功能要求 ppt 在 2021-02-10 进行转换,之前转换的 ppt 没有服务器端排版结果。
2.12.14 后该参数调整为是否自动加载下一页资源
是否自动加载下一页 ppt 资源,默认是 false
。
SDK 如何处理日志上报,默认是开启自动上报。更多关于日志的信息,可以参考《线上日志》。其类型为 LoggerOptions
,定义为。
type LoggerOptions = {
// 上报 debug 日志的模式
readonly reportDebugLogMode?: LoggerReportMode;
// 上报质量日志的模式
readonly reportQualityMode?: LoggerReportMode;
// 上报过滤等级,低于该等级则不上报,默认为 "info"
readonly reportLevelMask?: Level;
// 打印到控制台的过滤等级,低于该等级则不打印,默认为 "info"
readonly printLevelMask?: Level;
};
// 日志等级,从左到右等级越来越高
type Level = "debug" | "info" | "warn" | "error";
// 上报日志的行为模式
enum LoggerReportMode {
// 总是上报日志
AlwaysReport = "alwaysReport",
// 禁止上报日志
BanReport = "banReport",
// 根据管理控制台的配置决定是否上报日志
DependsOnRemote = "dependsOnRemote",
}
断线重连设置,如果传入 false
或 {disableReconnect: true}
则可以关闭断线重连。默认开启自动断线重连。你可以参考《实时房间状态管理》了解更多关于断线重连相关的状态变化。
默认为 true
。开启该功能后,若是主动调用 room
对象的方法来修改 room.state
的值,导致值变化,是不会调用回调方法通知说 room.state
发生改变了的。
关闭该功能后,只要 room.state
发生改变,就会回调。
如何判断是主动修改 room.state
?如果调用这些方法:room.setGlobalState
、room.setMemberState
、room.setViewMode
、room.setScenePath
、room.setSceneIndex
、room.moveCamera
、room.moveCameraToContain
、room.putScenes
、room.removeScenes
、room.moveScene
。那么通过调用这些方法所修改的字段本身的变化,都是为主动修改导致的变化。
将白板中的图片等资源的 URL 拦截并替换。例如,如下代码可以自动给所有图片 URL 加一个尾缀。
var whiteWebSdk = new WhiteWebSdk({
appIdentifier: "$APP_IDENTIFIER",
urlInterrupter: function(url) {
return url + "?token=bm1n4pisugWrWK";
},
});
用于处理 WhiteWebSdk
初始化失败的回调。
var whiteWebSdk = new WhiteWebSdk({
appIdentifier: "$APP_IDENTIFIER",
onWhiteSetupFailed: function(error) {
console.error(error);
},
});
如果是因为参数原因构造失败,会在调用 new WhiteWebSdk({...})
时抛出错误。该回调仅用来处理涉及网络或鉴权失败时的错误处理。
插件列表。
不可见插件列表。
默认值为 []
。这是一个装满 React.ComponentType
类型的数组,用于包装白板的 view。你可以用它对白板的 view 进行自定义包装。例如使用如下代码。
import React from "react";
class WrappedCompnent extends React.Component {
render() {
return (
<div>
<span>hello world</span>
{this.props.children}
</div>
);
}
}
var whiteWebSdk = new WhiteWebSdk({
appIdentifier: "$APP_IDENTIFIER",
wrappedComponents: [WrappedCompnent],
});