![](/img/trans.png)
[英]How to keep WebRTC dataChannel open in phone browser inactive tab?
[英]WebRTC dataChannel is never open
我在Codepen上創建了一個演示,它基於https://codelabs.developers.google.com/codelabs/webrtc-web/#0文章工作。
我有兩個按鈕, first
是執行偵聽(如文章中的join
事件),第二個是創建連接(如在就緒事件之后創建)。 主要功能如下所示:
function createPeerConnection(isInitiator, config) {
console.log('Creating Peer connection as initiator?', isInitiator, 'config:',
config);
peerConn = new RTCPeerConnection(config);
// send any ice candidates to the other peer
peerConn.onicecandidate = function(event) {
console.log('icecandidate event:', event);
if (event.candidate) {
sendMessage({
type: 'candidate',
label: event.candidate.sdpMLineIndex,
id: event.candidate.sdpMid,
candidate: event.candidate.candidate
});
} else {
console.log('End of candidates.');
}
};
if (isInitiator) {
console.log('Creating Data Channel');
dataChannel = peerConn.createDataChannel('photos');
onDataChannelCreated(dataChannel);
console.log('Creating an offer');
peerConn.createOffer(onLocalSessionCreated, logError);
} else {
peerConn.ondatachannel = function(event) {
console.log('ondatachannel:', event.channel);
dataChannel = event.channel;
onDataChannelCreated(dataChannel);
};
}
}
但是數據通道上的onopen
事件永遠不會執行並且通道處於連接狀態。 當我在 Chromium 中的同一台計算機(一台處於隱身模式的計算機)上打開它時,該代碼正在運行。
我在互聯網上找到的 Turn 和 Stun 服務器。 有沒有辦法測試他們是否正常?
我正在使用連接到同一路由器的兩台計算機測試此代碼,但其中一台正在使用 VPN。
1.) 您可以使用 webRTC-tester 測試您的網絡是否為通話設置正確: https ://test.webrtc.org/
2.) 您可以使用以下方法測試 Turn and Stun Server 是否正常工作: https : //webrtc.github.io/samples/src/content/peerconnection/trickle-ice/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.