RTC не рендерит видео на андроид - PullRequest
0 голосов
/ 14 ноября 2018

Я работаю над Примером RTC Oney Я использовал самый простой пример, но все еще не могу просмотреть свой локальный поток в режиме RTC, я не вижу ошибок в журналах, Может ли кто-нибудь помочь мне в этом?я делаю неправильно?

Вот мой код:

'use strict';

import React from 'react';
import {
    Platform,
    Animated,
    StyleSheet,
    View,
    Text
} from 'react-native';

import {
    RTCPeerConnection,
    RTCIceCandidate,
    RTCSessionDescription,
    RTCView,
    MediaStream,
    MediaStreamTrack,
    getUserMedia
} from 'react-native-webrtc'

export default class WebRTC extends React.Component {

    state = {
        videoURL: null,
        isFront: true
    }

    componentDidMount() {
        const configuration = { "iceServers": [{ "url": "stun:stun.l.google.com:19302" }] };
        const pc = new RTCPeerConnection(configuration);
        const { isFront } = this.state;
        MediaStreamTrack.getSources(sourceInfos => {
            console.log('MediaStreamTrack.getSources', sourceInfos);
            let videoSourceId;
            for (let i = 0; i < sourceInfos.length; i++) {
                const sourceInfo = sourceInfos[i];
                if (sourceInfo.kind === 'video' && sourceInfo.facing === (isFront ? 'front' : 'back')) {
                    videoSourceId = sourceInfo.id;
                }
            }
            getUserMedia({
                audio: true,
                video: {
                    mandatory: {
                        minWidth: 500, 
                        minHeight: 500
                    },
                    facingMode: (isFront ? 'user' : 'environment'),
                    optional: (videoSourceId ? [{ sourceId: videoSourceId }] : [])
                }
            }, (stream) => {
                console.log('Streaming OK', stream);
                this.setState({
                    videoURL: stream.toURL()
                });
                pc.addStream(stream);
            }, error => {
                console.log('Oops, we getting error', error.message);
                throw error;
            });
        });
        pc.createOffer((desc) => {
            pc.setLocalDescription(desc, () => {
                console.log('pc.setLocalDescription');
            }, (e) => { throw e; });
        }, (e) => { throw e; });

        pc.onicecandidate = (event) => {
            console.log('onicecandidate', event);
        };

    }

    render() {
        if (this.state.videoURL) {
            console.warn(this.state.videoURL);
            return (
                <View style={styles.container}>
                    <Text style={styles.text}>Working On Web RTC</Text>
                    <RTCView streamURL={this.state.videoURL}  />
                </View>

            );
        }
        else {
            return (
                <View>
                    <Text style={styles.text}>Not Working On Web RTC</Text>
                </View>

            );
        }

    }
}
const styles = {
    text: {
        textAlign: "center"
    },
    container: {
        flex: 1,
        backgroundColor: '#ccc',
        borderWidth: 1,
        borderColor: '#000'
    }
};

Он говорит, что мне нужно использовать сервер сигнализации, но я следовал этому учебнику и он работает безлюбой сервер сигнализации.

Я использую: Reaction-native-cli: 2.0.1 Reaction-native: 0.57.4

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...