You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Javascript在Opentok(Tokbox)库中传递用户名参数

OpenTok 用户名参数配置修复方案

现有配置错误点

  • 屏幕共享名称配置被覆盖:你在外层声明了screenProperties设置了name值,但screensharing配置项中显式将screenProperties设为null,导致外层自定义配置不生效。
  • 摄像头流缺少用户名配置:当前communication.callProperties设为默认的null,没有配置发布者的名称参数,摄像头流的用户名需要在该配置项下指定。

修复步骤

  • 给摄像头流添加用户名:修改communication.callProperties,新增publisherProperties字段,将其中name属性设置为你需要的用户名。
  • 修复屏幕共享名称配置:删除screensharing配置中的screenProperties: null行,让外层的screenProperties配置生效,也可以直接把自定义配置放到screensharing.screenProperties中。

修正后完整代码

initOptions() {
    this.options = {
      credentials: {
        apiKey: Constant.VonageApiKey,
        sessionId: this.sessionId,
        token: this.token
      },
      streamContainers: function streamContainers(pubSub, type, data) {
        return {
          publisher: {
            camera: '#cameraPublisherContainer',
            screen: '#screenPublisherContainer',
          },
          subscriber: {
            camera: '#cameraSubscriberContainer',
            screen: '#screenSubscriberContainer',
          },
        }[pubSub][type];
      },
      controlsContainer: '#controls',
      packages: ['screenSharing', 'annotation'],
      communication: {
        callProperties: {
          publisherProperties: {
            name: "你需要的用户名" // 这里替换为实际用户名参数
          }
        },
      },
      screenProperties: {
        name: "Testing"
      },
      screenSharing: {
        extensionID: 'plocfffmbcclpdifaikiikgplfnepkpo',
        annotation: true,
        externalWindow: false,
        dev: true
      },
      annotation: {
        // absoluteParent: {
        //   publisher: '.video-call',
        //   subscriber: '.video-call'
        // }
      },
      // archiving: {
      //   startURL: 'https://example.com/startArchive',
      //   stopURL: 'https://example.com/stopArchive',
      // },
    }
  }

内容的提问来源于stack exchange,提问作者Robin Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 03:06:02