1

我将使用 React 本机 iOS 通过 webRTC 创建视频聊天。为此,我为 iOS 编写了 react 本机代码。它要求我访问相机,但之后它无法加载视频并抛出一个温暖的消息,

Failed to bind EAGLDrawable: <CAEAGLLayer: 0x16d50e30> to GL_RENDERBUFFER 1
Failed to make complete framebuffer object 8cd6

我知道上面的警告是由于没有看到相机来渲染视频帧。但是我不知道我的反应代码有什么问题没有给它框架,我的代码如下,

import React, {
  AppRegistry,
  Component,
  StyleSheet,
  Text,
  View
} from 'react-native';

var WebRTC = require('react-native-webrtc');
var {
  RTCPeerConnection,
  RTCMediaStream,
  RTCIceCandidate,
  RTCSessionDescription,
  RTCView
} = WebRTC;


var container;
var configuration = {"iceServers": [{"url": "stun:stun.l.google.com:19302"}]};
  var pc = new RTCPeerConnection(configuration);
  navigator.getUserMedia({ "audio": true, "video": true }, function (stream) {
    pc.addStream(stream);
  });
  pc.createOffer(function(desc) {
    pc.setLocalDescription(desc, function () {
    // Send pc.localDescription to peer
  }, function(e) {});
  }, function(e) {});
  pc.onicecandidate = function (event) {
  // send event.candidate to peer
};

var RCTWebRTCDemo = React.createClass({
  getInitialState: function() {
    return {videoURL: null};
  },
  componentDidMount: function() {
    container = this;
  },
  render: function() {
    return (
      <View style={styles.container}>
        <RTCView streamURL={this.state.videoURL}/>
      </View>
    );
  }
});

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

AppRegistry.registerComponent('RCTWebRTCDemo', () => RCTWebRTCDemo);

我有兴趣知道我错在哪里?

4

1 回答 1

2

我之前设置了框架

<View style={styles.container}>
        <RTCView streamURL={this.state.videoURL}/>
 </View>

但这是错误的。RTCView 创建略有不同,因此我们在 RTCView 语法中设置框架。正确的做法是,

       <View>
        <RTCView streamURL={this.state.videoURL} style={styles.container}/>
      </View>
于 2016-04-06T05:11:24.200 回答