Opentok反应本机不发布

时间:2019-03-08 13:00:21

标签: react-native opentok tokbox

我正在尝试使用opentok-react-native库构建应用。

运行该应用程序时,发布者组件将变为黑色正方形,而订阅者组件将显示我的摄像机视频。

在日志中,我可以看到流已创建,带有流ID,并且显然正在运行。但是当我转到Tokbox account时,我的仪表板上看不到任何数据: tokbox dashboard

这是我当前的代码:https://github.com/victor0402/opentok-demo

重要的部分是:

import React, {Component} from 'react';
import {View} from 'react-native';
import {OT, OTPublisher, OTSession, OTSubscriber} from "opentok-react-native";

export default class App extends Component {

  //Publisher token
  token = 'TOKEN HERE';

  //Routed session ID
  session = 'SESSION ID HERE';

  apiKey = 'API KEY';

  constructor(props) {
    super(props);

    this.state = {
      streamProperties: {},
    };

    this.publisherProperties = {
      publishVideo: true,
      publishAudio: true,
      cameraPosition: 'front'
    };

    this.publisherEventHandlers = {
      streamCreated: event => {
        console.log('publisherEventHandlers: streamCreated.... updating state');
        const streamProperties = {
          ...this.state.streamProperties, [event.streamId]: {
            subscribeToAudio: true,
            subscribeToVideo: true,
            style: {
              width: 400,
              height: 300,
            },
          }
        };
        this.setState({streamProperties});
      },
      streamDestroyed: event => {
        console.log('Publisher stream destroyed!', event);
      }
    };

    this.subscriberProperties = {
      subscribeToAudio: true,
      subscribeToVideo: true,
    };

    this.sessionEventHandlers = {
      streamCreated: event => {
        console.log('sessionEventHandlers : streamCreated');
      },

      streamDestroyed: event => {
        console.log('Stream destroyed!!!!!!', event);
      },
    };

    this.subscriberEventHandlers = {
      error: (error) => {
        console.log(`There was an error with the subscriber: ${error}`);
      },
    };
  }

  render() {
    OT.enableLogs(true);

    return (
      <View>
        <OTSession apiKey={this.apiKey} sessionId={this.session} token={this.token}
                   eventHandlers={this.sessionEventHandlers}>

          <OTPublisher
            properties={this.publisherProperties}
            eventHandlers={this.publisherEventHandlers}
            style={{ height: 100, width: 100 }}
          />

          <OTSubscriber
            properties={this.subscriberProperties}
            eventHandlers={this.subscriberEventHandlers}
            style={{height: 100, width: 100}}
            streamProperties={this.state.streamProperties}
          />
        </OTSession>
      </View>

    );
  }
}

那么,我的代码有问题吗? 如何发布视频并在帐户仪表板上获取结果和记录?

2 个答案:

答案 0 :(得分:1)

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

使用情况指标需要大约24小时才能填充在信息中心中,这就是为什么您不会立即看到它们的原因。

我还查看了您共享的代码,看起来您在streamProperties的{​​{1}}回调中设置了streamCreated对象。请注意,仅当您的发布者开始发布时,发布者的OTPublisher事件才会触发。由于您使用streamCreated来设置订阅者的属性,因此您应该在streamProperties的{​​{1}}事件回调中设置此数据,因为这是在新流(而不是自己)在会话中创建。您的代码将如下所示:

streamCreated

最后要检查并查看是否一切正常,我建议使用OpenTok Playground Tool并使用与React Native应用程序中相同的sessionId进行连接。

答案 1 :(得分:0)

希望您使用的是更新的版本

"opentok-react-native": "^0.17.2"