Android 反应本机Webrtc复制图像流
我想在我的项目中使用。我开始使用文档中的示例,结果是前凸轮“出现”,但图像似乎是 代码与文档基本相同,只是对somme进行了修改,以显示RTCView:Android 反应本机Webrtc复制图像流,android,react-native,webrtc,Android,React Native,Webrtc,我想在我的项目中使用。我开始使用文档中的示例,结果是前凸轮“出现”,但图像似乎是 代码与文档基本相同,只是对somme进行了修改,以显示RTCView: let isFront = true; useEffect(() => { const configuration = {iceServers: [{url: 'stun:stun.l.google.com:19302'}]}; const pc = new RTCPeerConnection(configura
let isFront = true;
useEffect(() => {
const configuration = {iceServers: [{url: 'stun:stun.l.google.com:19302'}]};
const pc = new RTCPeerConnection(configuration);
mediaDevices.enumerateDevices().then((sourceInfos) => {
let videoSourceId;
console.log(sourceInfos);
for (let i = 0; i < sourceInfos.length; i++) {
const sourceInfo = sourceInfos[i];
if (
sourceInfo.kind == 'videoinput' &&
sourceInfo.facing == (isFront ? 'front' : 'environment')
) {
videoSourceId = sourceInfo.deviceId;
}
}
mediaDevices
.getUserMedia({
audio: true,
video: {
mandatory: {
minWidth: 500, // Provide your own width, height and frame rate here
minHeight: 300,
},
},
})
.then((stream) => {
setStream(stream);
console.log('set stream');
// Got stream!
})
.catch((error) => {
console.log('error', error);
// Log error
});
});
pc.createOffer().then((desc) => {
pc.setLocalDescription(desc).then(() => {
// Send pc.localDescription to peer
});
});
pc.onicecandidate = function (event) {
// send event.candidate to peer
};
}, [isFront]);
const styles = {
wrapper: {
flex: 1,
justifyContent: 'flex-end',
},
buttonWrapper: {
width: '100%',
height: '20%',
alignItems: 'center',
justifyContent: 'center',
},
} as React.CSSProperties;
return (
<View style={styles.wrapper}>
<View style={{width: '100%', height: '70%', backgroundColor: 'red'}}>
{stream != null ? (
<RTCView
style={{flex: 1, height: 150, margin: 10}}
streamURL={stream.toURL()}
/>
) : (
<Text>No RTC</Text>
)}
</View>
<View style={styles.buttonWrapper}>
<NitaButton
title="Contact Help"
onPress={() => navigation.navigate('WaitingRoom')}
/>
</View>
</View>
);
让isFront=true;
useffect(()=>{
const配置={iceServers:[{url:'stun:stun.l.google.com:19302'}]};
const pc=新的RTPeerConnection(配置);
mediaDevices.enumerateDevices()。然后((sourceInfos)=>{
让videoSourceId;
console.log(sourceInfos);
for(设i=0;i{
溪流;
log('set stream');
//有小溪!
})
.catch((错误)=>{
console.log('error',error);
//日志错误
});
});
pc.createOffer()。然后((描述)=>{
pc.setLocalDescription(desc).然后(()=>{
//将pc.localDescription发送给对等方
});
});
pc.onicecandidate=函数(事件){
//将event.candidate发送到对等方
};
},[isFront]);
常量样式={
包装器:{
弹性:1,
justifyContent:“柔性端”,
},
按钮振打器:{
宽度:“100%”,
身高:20%,
对齐项目:“居中”,
为内容辩护:“中心”,
},
}as React.csp属性;
返回(
{stream!=null(
) : (
无RTC
)}
导航。导航('WaitingRoom')}
/>
);
我似乎在网上找不到类似的问题。我错过什么了吗?谢谢
我使用的是华为P30 pro,react-native:0.62.2和react-native-webrtc:1.75.3
编辑
模拟器运行时出现类似问题
编辑
我通过更改视频修复了它:真的你能用其他手机或任何模拟器试试吗?我在编辑中添加了一个屏幕截图,但它仍然不能用模拟器工作。今天我将试用P20 pro。你能用其他手机或任何模拟器试用一下吗?我在编辑中添加了一个屏幕截图,但它仍然不能用模拟器工作。今天我将用P20专业版试一试。