Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript WebRTC PeerConnection在Safari 11上显示黑屏(Mac OS X 10.13)_Javascript_Macos_Safari_Webrtc - Fatal编程技术网

Javascript WebRTC PeerConnection在Safari 11上显示黑屏(Mac OS X 10.13)

Javascript WebRTC PeerConnection在Safari 11上显示黑屏(Mac OS X 10.13),javascript,macos,safari,webrtc,Javascript,Macos,Safari,Webrtc,我正在使用WebRTC将视频(无音频)从Raspberry Pi上的网络摄像头传输到用户的浏览器。在RPi上,我已经安装了,并且从该repo复制了浏览器客户端的一些测试代码 在我的Mac OS X 10.13桌面上,客户端代码在Chrome 63和Firefox 58上显示的视频很好,但在Safari 11上,我得到的只是这些。虽然Safari在WebRTC中的支持似乎是最近才出现的,但我所读到的内容表明,在这个版本的Safari中,它至少应该能够支持与H.264编解码器的RTPeerConne

我正在使用WebRTC将视频(无音频)从Raspberry Pi上的网络摄像头传输到用户的浏览器。在RPi上,我已经安装了,并且从该repo复制了浏览器客户端的一些测试代码

在我的Mac OS X 10.13桌面上,客户端代码在Chrome 63和Firefox 58上显示的视频很好,但在Safari 11上,我得到的只是这些。虽然Safari在WebRTC中的支持似乎是最近才出现的,但我所读到的内容表明,在这个版本的Safari中,它至少应该能够支持与H.264编解码器的RTPeerConnection。对可能出现的问题有什么想法吗

下面是我们的JavaScript摘录(这不是最好的,但希望这里的部分可以理解):

var pcConfig={“iceServers”:[{“URL”:“stun:stun.l.google.com:19302”};
var pcOptions={可选:[{DtlsSrtpKeyAgreement:true}]};
this.createPeerConnection=函数(){
var=这个;
this.peerConnection=新的RTCPeerConnection(pcConfig,pcOptions);
this.peerConnection.onicecandidate=函数(事件){
if(事件候选){
变量候选={
键入:“候选人”,
标签:event.candidate.sdpMLineIndex,
id:event.candidate.sdpMid,
候选人:event.candidate.candidate
};
//发送(数据)通过已建立的WebSocket连接发送数据
send(JSON.stringify(候选者));
}
};
this.peerConnection.onconnecting=onSessionConnecting.bind(this);
this.peerConnection.onopen=onSessionOpened.bind(this);
this.peerConnection.onaddstream=onRemoteStreamAdded.bind(this);
this.peerConnection.onremovestream=onRemoteStreamRemoved.bind(this);
}
添加了函数onRemoteStream(事件){
this.videoEl.srcObject=event.stream;
}
//其余的回调只记录日志,不做其他事情
//包括OnSessionConnection、OnSessionOpen、onRemoteStreamRemoved
this.doHandlePeerMessage=函数(数据){
++这个.messageCounter;
var dataJson=JSON.parse(数据);
if(dataJson[“type”]=“offer”){
var=这个;
var数据=“”;
var sdp_returned=forceChosenVideoCodec(dataJson.sdp,'H264/90000');
dataJson.sdp=sdp_返回;
this.createPeerConnection();
this.peerConnection.setRemoteDescription(
新的RTCSessionDescription(dataJson),
onRemoteSdpSuccess,
OnRemotesDPEROR
);
this.peerConnection.createAnswer({iceRestart:false})。然后(函数(sessionDescription){
data=JSON.stringify(sessionDescription);
返回.peerConnection.setLocalDescription(sessionDescription);
}).然后(函数(){
//同样,send(data)通过已建立的WebSocket连接发送数据
发送(数据);
}).catch(函数(错误){
//日志错误
});
}else if(dataJson[“type”]=“candidate”){
var-candidate=new-RTCIceCandidate({sdpMLineIndex:dataJson.label,candidate:dataJson.candidate});
this.peerConnection.addIceCandidate(候选者、aic\u成功\u cb、aic\u失败\u cb);
}
}
//同样,回调只记录日志,不做其他事情
//包括aic_成功_cb、aic_失败_cb、OnRemoteSDPSAccess、OnRemoteSDPeror

(我是WebRTC的新手,所以如果有什么明显的错误,请告诉我!)

我认为您的问题是由于没有将
playsinline
添加到html视频元素中造成的

所以它必须是这样的:

<video id="local-video" playsinline autoplay muted></video>
<video id="remote-video" playsinline autoplay></video>

您需要在视频标签中添加一些道具

<video playsinline controls autoplay/>

我遇到了类似的问题,建议的视频元素道具没有帮助。解决这个问题的方法是为Safari用户添加一个按钮,在视频元素上调用
play
方法:

播放

如果尝试从控制台或以编程方式调用
play
方法,您将得到:

未处理的承诺拒绝:NotAllowedError(DOM异常35):当前上下文中的用户代理或平台不允许该请求,可能是因为用户拒绝了权限


你能解决这个问题吗?