在使用SDK之前需要进行初始化。您需要在该步骤中填入项目的enterpriseId,如果您已经完成准备工作中的内容,则可以从管理平台获取到enterpriseId。
建议在Application的onCreate方法中调用init方法进行初始化。请注意,一次运行过程中只初始化一次,不要频繁调用init方法。
首先需要获取SDK实例:
const engine = XYRTCEngine.getInstance();
SDK配置接口的字段如下:
字段名 | 类型 | 说明 |
cloudServer | string | 服务器地址 |
openapiServer | string | 开放平台地址, 暂不自定义, 请传"" |
openapiToken | string | 开放平台口令, 暂不自定义, 请传"" |
logFolder | string | 日志目录 必须设置有权限的路径 |
logFileName | string | 日志文件名称 |
platformTag | string | 平台标识,用于上传log使用, 请传 HarmonyOS |
appType | 应用标识, sdk请使用 XYSDKBusinessType.Sdk | |
appVersion | string | App版本号,用于上传log使用 |
clientId | string | 应用clientId |
clientSecret | string | 应用clientSecret |
clientType | string | 应用clientType, 请使用 harmony_sdk |
osVersion | string | 操作系统版本 |
hwVersion | string | 硬件系统版本 |
pemFile | string | pem证书路径 暂不自定义, 请传"" |
eid | string | 企业id |
capture | number | 采集方法 暂不支持, 请传0 |
render | number | 渲染方法 暂不支持, 请传0 |
useUnityLayout | boolean | 是否使用统一layout 暂不自定义, 请传true |
appDataDir | string | app data路径 必须设置有权限的路径 |
supportCapabilities | boolean | 是否支持能力集 暂不自定义, 请传true |
customKey | string | 定制ck |
logFilterKey | string | 日志过滤规则 - 将设置的key替换为* |
logFilterKeyNum | string | 日志过滤规则 - 将设置的key后num个字符替换为* |
logFilterKeys | string | 日志过滤规则 - 将设置的两个key之间的字符替换为* |
cloudConfigJsonPath | string | 云控配置数据文件路径,暂不自定义, 请传"" |
ability | 客户端能力集 sdk 请使用 [XYSDKAbilityType.DynamicErrorCode, XYSDKAbilityType.APIGateway, XYSDKAbilityType.UnsafeHttpMethod] | |
useNativeCamera | boolean | 是否采用NativeCamera, 暂不自定义, 请传 false |
forceApiGateway | boolean | 强制接口使用网关 暂不自定义, 请传 false |
configLoginType | string | 登录类型 暂不自定义, 请传 "" |
deviceType | number | 设备类型 pc 5, 手机 1 |
deviceSn | string | 设备标识 |
export class XYSDKConfigInfo implements XYSDKConfig {
cloudServer: string = '';
openapiServer: string = '';
openapiToken: string = '';
logFolder: string = '';
useNativeCamera: boolean = false;
configLoginType: string = "";
forceApiGateway: boolean = false;
logFileName: string = 'xylog';
platformTag: string = 'HarmonyOS';
appType: XYSDKBusinessType = XYSDKBusinessType.Sdk;
appVersion: string = '3.3.0';
clientId: string = '';
clientSecret: string = '';
clientType: string = 'harmony_sdk';
osVersion: string = '';
hwVersion: string = '';
pemFile: string = '';
eid: string = '';
capture: number = 0;
render: number = 0;
useUnityLayout: boolean = true;
appDataDir: string = '';
supportCapabilities: boolean = true;
customKey: string = '';
logFilterKey: string = '';
logFilterKeyNum: string = '';
logFilterKeys: string = '';
cloudConfigJsonPath: string = "";
deviceType: number = 1;
deviceSn: string = XYDeviceInfoUtil.getODID().replaceAll("-", "");
ability: XYSDKAbilityType[] = [
XYSDKAbilityType.DynamicErrorCode,
XYSDKAbilityType.APIGateway,
XYSDKAbilityType.UnsafeHttpMethod
];
}
// 初始化SDK
let xySdkConfig: XYSDKConfig = new XYSDKConfigInfo();
xySdkConfig.cloudServer = this.host;
xySdkConfig.clientId = this.clientId;
xySdkConfig.clientSecret = this.clientSecret;
xySdkConfig.eid = this.extId;
xySdkConfig.logFolder = getContext(this).filesDir;
xySdkConfig.appDataDir = getContext(this).filesDir;
const error = XYRTCEngine.getInstance().init(xySdkConfig);