Skip to content

TypeScript

变量传递

tsapp传递Array<Interface>数据到napi层时,定义的变量必须显示定义其每个成员变量:

JavaScript
1
2
3
4
    const arrayList: Array<SurfaceConfig> = [
    { surfaceId: '155', type: 0 },
    { surfaceId: '654', type: 1 }
    ];

其中必须写明surfaceId, type等,因为在napi处解析时需要用到。其中的传递解析貌似是通过protobuf来完成的

XComponent使用

获取创建的XComponentController()窗口的surfaceId,必须在布局时获取getXComponentSurfaceId()前初始化一下,否则搞出来的id是 个无效的id

JavaScript
// 可以的初始化方法
XComponent({
    id: 'xcomponent',
    type: 'surface',
    controller: this.controllerList[index][index2]
}).onLoad(() => {
        let ComponentController = this.controllerList[index][index2]
        ComponentController.setXComponentSurfaceSize({ surfaceWidth: 640, surfaceHeight: 360 })
        this.surfaceIdList[index][index2] = ComponentController.getXComponentSurfaceId()
    })
    .width('100%')
    .height('100%')
    .padding(10)
    .borderRadius(20)
    .borderWidth(3)
    .borderColor('#fff')

Napi

  • c++转js 结构体struct对应js中的object,数组vector对应js中的array,napi_set_named_property用于向object中添加元素, napi_set_element用于向array中添加元素
  • napi_unwrap可以将env,jsThis中的js对象拆出来即jsPlayerNapi这种对象。