如何使用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
相关产品推荐
相关产品推荐

