使用Janus-gateway的远程视频流未在react-native中显示

时间:2020-02-26 13:50:05

标签: react-native janus-gateway

我想在我的react native项目中使用janus网关显示远程流视频。 我正在使用此软件包:https://github.com/oney/react-native-webrtc从此处https://github.com/atyenoria/react-native-webrtc-janus-gateway/blob/master/src/janus.mobile.js

在我的组件和janus库(janus.mobile.js文件)中显示流式视频。

我的onremotestream函数已触发,但是我一直收到黑屏,而不是流视频。(android和ios)

我正在使用react-native-webrtc v:1.75.3 react-native:0.60.5

我在组件中这样称呼Janus: 这是我的代码:

`导出默认类VideoExample扩展了Component { componentDidMount(){ containerStreaming = this;

    Janus.init({debug: "all", callback: function() {
            if(started)
                return;
            started = true;
        }});

    this.janusStart();
}

janusStart = () => {
    containerStreaming.setState({ visible: true });
            let janus = new Janus({
                server: containerStreaming.props.server,
                iceServers: containerStreaming.props.iceServers,
                token: containerStreaming.props.token,

                success: function() {
                    janus.attach({
                        plugin: "janus.plugin.streaming",

                        success: function(pluginHandle) {
                            streaming = pluginHandle;
                            Janus.log(`Janus Plugin Attached : ${pluginHandle.getId()}`);
                            streaming.send({ "message": {"request": "watch", id: containerStreaming.props.id } });
                        },
                        error: function(error) {
                            Janus.error(`Error Attaching Janus Plugin ${error}`)
                        },
                        mediaState: function(medium, on) {
                            containerStreaming.setState({status: 'stopped', info: 'Stopped'});
                            Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
                        },
                        webrtcState: function(on) {
                            console.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
                            // $("#videolocal").parent().parent().unblock();
                        },
                        onmessage: function(msg, jsep) {
                            console.log("jsep" ,jsep.sdp);
                            Janus.log(`Janus Message received : ${JSON.stringify(msg)} and jsep ${jsep}`);
                            var result = msg['result'];
                            if (!!result && result['status'] == 'stopped') {
                                janus.destroy();
                                return;
                            }
                            if (jsep !== null && jsep !== undefined) {
                                Janus.log(`JANUS : Handling SDP as well : ${jsep}`);
                                streaming.createAnswer({
                                    jsep: jsep,
                                    media: { audioSend: false, videoSend: false }, // recvonly
                                    success: function(jsep){
                                        Janus.debug(`Janus Got SDP : ${jsep}`);
                                        streaming.send({ message: { request: 'start' }, jsep: jsep });
                                    },
                                    error: function(error) {
                                        Janus.error(`Janus WebRTC error : ${error}`)
                                    }
                                });
                            }
                        },
                        onremotestream: function(stream) {
                            Janus.log('Janus Remote stream detected');
                            Janus.log(stream);
                            containerStreaming.setState({status: 'streaming', info: 'Streaming'});
                            containerStreaming.setState({selfViewSrc: stream.toURL()});
                        },
                        oncleanup: function() {
                            Janus.log('Janus clean up notification')
                        }
                    })
                },
                error: function(error) {
                    Janus.error('Janus  -- ' + error);
                    Janus.error('Destroying Janus');
                    janus.destroy();
                },
                destroyed: function() {
                    window.location.reload();
                },

            });
};

`

render() { return ( <RTCView zOrder={0} streamURL={this.state.selfViewSrc} style={styles.streamingStyle} /> );}; }

1 个答案:

答案 0 :(得分:0)

与cefsharp.Net 桌面铬应用程序相同的故事