# type: Barrage

针对拉取逻辑封装的弹幕组件。

# demo

注:设备模板基于数据内容进行动态绑定的方法请参考表达式语法

# props

名称 类型 默认值 可选值 必填 描述
src string - - 弹幕拉取的 url 地址
delayMs number 5000 - 弹幕与视频的延迟,同时也作为弹幕拉取间隔,单位毫秒
channel number 11 - 弹道数量
expiresLimitMs number 1000 - 判断需要丢弃过期弹幕的临界时间,单位毫秒

# methods

可以通过 InvokeMethod 指令调用的组件方法:

方法名 参数 参数说明 方法描述
init - - 调用该方法初始化弹幕组件,开始拉取新的弹幕内容

# 后端接口返回

# 返回数据结构

根据 src 给定的请求地址,后端需要返回的数据结构是:

type Response = {
  // 弹幕数据内容结构体,见 interface Barrage
  data: Barrage[],
  // 弹幕列表的截止时间
  endtime: number,
  // 下次请求弹幕的URL
  url: string
}

interface Barrage {
  // 弹幕时间戳,单位秒
  msgsendtime: number;
  // 弹幕内容
  msgcontent: string;
  // 弹幕发送方:目前支持两种弹幕类型:MINE(本人发送),OTHER (非本人发送),会在弹幕呈现时有效果区分
  author?: 'MINE';
}

# 弹幕获取通用策略

注意:在第一次之后的每次请求会用 Response.url 并在请求中拼接上 begintime=${Response.endtime} 作为完整的请求地址。倘若某一次请求超时,则直接用上次的 Response.url 作为完整地址请求(不再额外的去拼接 begintime)。

所以服务器端的逻辑应该是:

  • 若客户端请求链接地址不带 begintime 拼接字段,则应该返回最新 delayMs / 1000 秒的弹幕,并将弹幕的终止时间作为 endtime 字段放在响应中
  • 若客户端请求链接地址有带 begintime 拼接字段,则应该返回以 begintime 为起点,往后截取 delayMs / 1000 秒内的弹幕,并将弹幕的终止时间作为 endtime 字段放在响应数据中

# 组件样例(example)

// 弹幕容器的大小依赖于外层给定
{
    "type": "Container",
    "componentId": "barrage_container",
    "styles":{
        "flex":1,
        "border-radius":"16dp",
        "background-color": "rgba(1, 1, 1, .2)",
        "margin-left":"16dp"
    },
    "items": [
        {
            "type": "Barrage",
            "componentId": "barrage_test",
            "props": {
                "delayMs": 2000,
                "channel": 4,
                "expiresLimitMs": 2000,
                "src": "https://www.skylc.top/lt_danmu"
            }
        }
    ],
    "events": {
        "onLoaded": [
            {
                "type": "InvokeMethod",
                "componentId": "barrage_test",
                "methodName": "init"
            }
        ]
    }
}