未调用 setState 以在单击按钮时覆盖 red5Pro 配置中的一个属性

如何解决未调用 setState 以在单击按钮时覆盖 red5Pro 配置中的一个属性

我正在尝试使用 setState 在单击按钮时调用 Publisher 对象的 onConfigured: 属性

当我打开开始直播屏幕时,它会从 this.state 加载到配置,但我希望它在单击按钮时手动启动。我尝试了 setState 但当我按下按钮时它没有被调用并且流没有开始

这是代码:-

import React from "react";
import { findNodeHandle,View,Button,StyleSheet } from "react-native";

import { R5VideoView } from "react-native-red5pro";
import { R5LogLevel,R5ScaleMode } from "react-native-red5pro";
import {
  publish,unpublish,swapCamera,subscribe,unsubscribe,} from "react-native-red5pro";

import * as Permissions from "expo-permissions";

export default class StartLiveStream extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      publisher: {
        ref: "video",configuration: {
          host: "100.248.112.52",// IP or Fully Qualified Domain Name
          port: 8554,contextName: "live",bufferTime: 0.5,streamBufferTime: 2,key: Math.floor(Math.random() * 0x10000).toString(16),bundleID: "com.realfreedomplatform.stream",licenseKey: "794H-993S-PXKL-VZBK",streamName: "mystream",},showDebugView: true,logLevel: R5LogLevel.DEBUG,//onConfigured: this.onConfiguredPublish.bind(this),subscriber: {
        ref: "video",configuration: {
          host: "107.172.137.107",licenseKey: "694H-993S-PXKL-VZBK",streamName: "mystream2",//"test123",scaleMode: R5ScaleMode.SCALE_TO_FILL,// onConfigured: this.onConfiguredSubscribe.bind(this),};

    this.onStopPublish = this.onStopPublish.bind(this);
    this.onStopSubscribe = this.onStopSubscribe.bind(this);
    this.onSwapCamera = this.onSwapCamera.bind(this);
    this.onStatechange = this.onStatechange.bind(this);
  }

  async componentDidMount() {
    console.log("loaded publisher");

    try {
      const { status } = await Permissions.askAsync(
        Permissions.CAMERA,Permissions.CAMERA_ROLL,Permissions.AUdio_RECORDING
      );

      if (status !== "granted") {
        return (
          <View>
            <Text>Permission is not granted</Text>
          </View>
        );
      }
    } catch (error) {
      console.log("error in permisions");
    }
  }

  render() {
    return (
      <View style={styles.container}>
        <R5VideoView {...this.state.subscriber} style={styles.video1} />
        <R5VideoView {...this.state.publisher} style={styles.video} />

        <Button
          style={styles.button}
          onPress={this.onStopPublish}
          title="Stop Publish"
          accessibilityLabel="Stop Publish"
        />
        <Button
          style={styles.button}
          onPress={this.onStatechange} // I called it here to start streaming on button click
          title="Start Publish"
          accessibilityLabel="Start Publish"
        />
        <Button
          style={styles.button}
          onPress={this.onSwapCamera}
          title="Swap Camera"
          accessibilityLabel="Swap Camera"
        />
      </View>
    );
  }

  onConfiguredPublish() {
    // By providing the `configuration` state prop to the view,// the component starts the configuration process.

    const streamNamePublish = this.state.publisher.configuration.streamName;
    publish(findNodeHandle(this.refs.video),streamNamePublish);
  }

  onConfiguredSubscribe() {
    const streamNameSubscribe = this.state.subscriber.configuration.streamName;
    subscribe(findNodeHandle(this.refs.video),streamNameSubscribe);
  }

  onStatechange() { // I think I am doing something wrong here
    this.setState((prevstate) => ({

      publisher: Object.assign({},prevstate.publisher,{
        onConfigured: this.onConfiguredPublish.bind(this),}),}));
  }

  onStopSubscribe() {
    unsubscribe(findNodeHandle(this.refs.video));
  }

  onStopPublish() {
    unpublish(findNodeHandle(this.refs.video));
  }

  onSwapCamera() {
    swapCamera(findNodeHandle(this.refs.video));
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,backgroundColor: "white",justifyContent: "center",video: {
    flex: 0.5,flexDirection: "row",backgroundColor: "black",video1: {
    flex: 0.5,button: {
    position: "absolute",left: 0,right: 0,bottom: 0,height: 40,backgroundColor: "blue",color: "white",});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?