【问题标题】:Opentok react native not publishingOpentok 反应原生不发布
【发布时间】:2023-03-10 14:31:01
【问题描述】:

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

应用运行时,发布者组件变成黑色方块,订阅者组件显示我的摄像头视频。

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

这是我当前的代码: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>

    );
  }
}

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

【问题讨论】:

  • 这是在 ios 还是 android 上发生的?
  • @10101010 在安卓 5.1 上

标签: react-native opentok tokbox


【解决方案1】:

这里是 TokBox 开发者宣传员。

使用指标大约需要 24 小时才能填充到仪表板中,这就是您没有立即看到它们的原因。

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

this.sessionEventHandlers = {
  streamCreated: event => {
      const streamProperties = {
      ...this.state.streamProperties, [event.streamId]: {
        subscribeToAudio: true,
        subscribeToVideo: true,
        style: {
          width: 400,
          height: 300,
        },
      }
    };
    this.setState({streamProperties});
  },
};

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

【讨论】:

  • 我认为我的代码会有问题。很高兴了解游乐场工具。非常感谢@manik。
  • 乐于帮助@Victor!
【解决方案2】:

希望您使用的是更新的 vrsion

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

【讨论】:

    猜你喜欢
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-19
    相关资源
    最近更新 更多