React Opentok如何更新发布者分辨率?

时间:2018-11-21 19:40:20

标签: reactjs opentok

我有一个opentok-react实现,我希望能够更新发布者的分辨率。不幸的是,似乎OTPublisher仅在某些值更改时才会更新,而分辨率不是其中之一。我在文档中看到,应该在初始化发布者之后使用getPublisher()来更新发布者,但是我没有看到任何有关此操作的示例。这是我需要更新的组件:

import React, { Component } from 'react';
import { OTSession, OTPublisher } from 'opentok-react';

const styles = {
  publisherWindow: {
    height: '155px',
    width: '230px',
    style: { buttonDisplayMode: 'off' },
  },
};

type Props = {
  sessionId: string,
  sessionToken: string,
  apiKey: string,
  muted: boolean,
  style?: Object,
  onError: Function,
  eventHandlers: Object,
  lowerResolution: boolean,
};

type State = {
  publish: boolean,
};

class TokboxPublisher extends Component<Props, State> {
  state = {
    publish: true,
  };

  static SURVEYOR_STREAM_NAME = 'Surveyor Stream';

  componentWillMount() {
    this.retryTimeout = setTimeout(this.retry, 6000);
  };

  componentWillUnmount() {
    if (this.retryTimeout) {
      clearTimeout(this.retryTimeout);
    }
  };

  onPublish = () => {
    console.log('Publishing...');
    if (this.retryTimeout) {
      clearTimeout(this.retryTimeout);
    }
  };

  retry = () => {
    this.retryTimeout = undefined;
    console.log('Retrying publish...');
    this.setState({ publish: false }, () => this.setState({ publish: true }));
  };

  render() {
    if (!this.state.publish) {
      return null;
    }
    console.log('lowerResolution: ', this.props.lowerResolution);
    return (
      <OTSession
        apiKey={this.props.apiKey}
        sessionId={this.props.sessionId}
        token={this.props.sessionToken}
        eventHandlers={this.props.eventHandlers}
      >
        <OTPublisher
          ref={this.otPublisher}
          properties={{
            publishAudio: !this.props.muted,
            resolution: this.props.lowerResolution ? '320x240' : '640x480',
            frameRate: this.props.lowerResolution ? 1 : 30,
            name: TokboxPublisher.SURVEYOR_STREAM_NAME,
            ...styles.publisherWindow,
            ...this.props.style,
          }}
          onPublish={this.onPublish}
          onError={this.props.onError}
        />
      </OTSession>
    );
  }
}

export default TokboxPublisher;

当lowerResolution属性更改为“ true”时,如何在此代码中使用getPublisher()获取更新的分辨率?

2 个答案:

答案 0 :(得分:0)

此处是TokBox开发人员的传播者。

当调用getPublisher()组件的OTPublisher方法时,将返回一个Publisher对象。然后,您可以在任何给定时间调用Publisher对象上的videoWidth()videoHeight()方法,以了解发布者的分辨率。有关发布者方法的更多信息,请访问:https://tokbox.com/developer/sdks/js/reference/Publisher.html#methods

答案 1 :(得分:0)

创建发布服务器后,底层的opentok.js API不支持更改分辨率或帧速率。当分辨率发生以下变化时,您将需要创建一个新的发布者对象:

in.open(argv[1], std::ios::binary);

这意味着,尽管创建了新的发布者,会议室中的每个人都会看到用户离开,然后短暂地再次返回。这也意味着可以根据是否再次提示用户允许访问其相机/麦克风。