2016-05-17 12 views
2

我創建了一個非常基本的WebRTC視頻聊天界面(僅限Chrome測試)。我通過websockets發送SDP信號,並使用Twilio服務進行STUN/TURN配置。WebRTC:MediaStream已添加,但沒有媒體可見

的「提供應答舞」似乎運作良好,我得到遠程流(用ID標識)和BLOB網址添加到視頻標籤:

<video controls="true" autoplay="autoplay" width="640" height="480" src="blob:http%3A//localhost%3A3000/76ea7cb1-3ded-4c8d-b486-ea8856fe259e"></video> 

然而,視圖是空的。


這是我如何接聽來電報價:

navigator.getUserMedia({video: true, audio: true}, function (stream) { 
         console.log("Stream Created:", stream.id); 
         pc.addStream(stream); 
         pc.setRemoteDescription(new RTCSessionDescription({type: "offer", sdp: sdp}), function() { 
          console.log("Remote description set"); 
          pc.createAnswer(function (answer) { 
           pc.setLocalDescription(answer, function() { 
            // send the answer to a server to be forwarded back to the caller 
            ws.send(JSON.stringify({action: "answer", to: callerID, from:myId, message: answer.sdp})); 
           }, error); 
          }, error); 
         }, error); 
        }); 

這裏是onaddstream功能:

pc.onaddstream = function(e){ 
     console.log("Stream Added:", e.stream.id); 
     $("video")[0].src = URL.createObjectURL(e.stream); 
     $("video")[0].play(); 
    }; 

編輯添加SDP:

Offer SDP v=0 
    o=- 69925770258960282 2 IN IP4 127.0.0.1 
    s=- 
     t=0 0 
    a=group:BUNDLE audio video 
    a=msid-semantic: WMS sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 
    m=audio 9 UDP/TLS/RTP/SAVPF 111 103 104 9 0 8 106 105 13 126 
    c=IN IP4 0.0.0.0 
    a=rtcp:9 IN IP4 0.0.0.0 
    a=ice-ufrag:ADj3FEdod3ks08kE 
    a=ice-pwd:3W5QU38oyiB2Sj7EZql8p8Gn 
    a=fingerprint:sha-256 ED:D2:A4:8C:E0:5F:38:25:D3:D9:86:FC:BD:7C:1E:5C:DE:DE:6D:01:75:DA:3A:8F:F5:3E:27:83:D2:FD:DF:FD 
    a=setup:actpass 
    a=mid:audio 
    a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level 
    a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time 
     a=sendrecv 
    a=rtcp-mux 
    a=rtpmap:111 opus/48000/2 
    a=rtcp-fb:111 transport-cc 
    a=fmtp:111 minptime=10; useinbandfec=1 
    a=rtpmap:103 ISAC/16000 
    a=rtpmap:104 ISAC/32000 
    a=rtpmap:9 G722/8000 
    a=rtpmap:0 PCMU/8000 
    a=rtpmap:8 PCMA/8000 
    a=rtpmap:106 CN/32000 
    a=rtpmap:105 CN/16000 
    a=rtpmap:13 CN/8000 
    a=rtpmap:126 telephone-event/8000 
    a=maxptime:60 
    a=ssrc:349223883 cname:07HrC4w/vFw0loFv 
    a=ssrc:349223883 msid:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 282288d1-5b9a-4912-9ced-f6188b33139e 
    a=ssrc:349223883 mslabel:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 
    a=ssrc:349223883 label:282288d1-5b9a-4912-9ced-f6188b33139e 
    m=video 9 UDP/TLS/RTP/SAVPF 100 101 116 117 96 97 98 
    c=IN IP4 0.0.0.0 
    a=rtcp:9 IN IP4 0.0.0.0 
    a=ice-ufrag:ADj3FEdod3ks08kE 
    a=ice-pwd:3W5QU38oyiB2Sj7EZql8p8Gn 
    a=fingerprint:sha-256 ED:D2:A4:8C:E0:5F:38:25:D3:D9:86:FC:BD:7C:1E:5C:DE:DE:6D:01:75:DA:3A:8F:F5:3E:27:83:D2:FD:DF:FD 
    a=setup:actpass 
    a=mid:video 
    a=extmap:2 urn:ietf:params:rtp-hdrext:toffset 
    a=extmap:3 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time 
     a=extmap:4 urn:3gpp:video-orientation 
    a=sendrecv 
    a=rtcp-mux 
    a=rtpmap:100 VP8/90000 
    a=rtcp-fb:100 ccm fir 
    a=rtcp-fb:100 nack 
    a=rtcp-fb:100 nack pli 
    a=rtcp-fb:100 goog-remb 
    a=rtcp-fb:100 transport-cc 
    a=rtpmap:101 VP9/90000 
    a=rtcp-fb:101 ccm fir 
    a=rtcp-fb:101 nack 
    a=rtcp-fb:101 nack pli 
    a=rtcp-fb:101 goog-remb 
    a=rtcp-fb:101 transport-cc 
    a=rtpmap:116 red/90000 
    a=rtpmap:117 ulpfec/90000 
    a=rtpmap:96 rtx/90000 
    a=fmtp:96 apt=100 
    a=rtpmap:97 rtx/90000 
    a=fmtp:97 apt=101 
    a=rtpmap:98 rtx/90000 
    a=fmtp:98 apt=116 
    a=ssrc-group:FID 2207775072 661034986 
    a=ssrc:2207775072 cname:07HrC4w/vFw0loFv 
    a=ssrc:2207775072 msid:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 4b45d0b6-877f-400e-8e3d-42cefcd8808e 
    a=ssrc:2207775072 mslabel:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 
    a=ssrc:2207775072 label:4b45d0b6-877f-400e-8e3d-42cefcd8808e 
    a=ssrc:661034986 cname:07HrC4w/vFw0loFv 
    a=ssrc:661034986 msid:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 4b45d0b6-877f-400e-8e3d-42cefcd8808e 
    a=ssrc:661034986 mslabel:sY6R8GGwtIDPcK4uDv3W66jBseIXZvAq2Nbp 
    a=ssrc:661034986 label:4b45d0b6-877f-400e-8e3d-42cefcd8808e 

我錯過了什麼?

+1

是否有錯誤信息? - 可能沒有幫助,但我建議在'getUserMedia'之前立即調用'setRemoteDescription',否則那個對手可能會錯過冰上候選人。你在做'pc.onicecandidate'吧? – jib

+0

感謝您的回覆,沒有錯誤信息。我的錯誤是在沒有候選人的情況下發送報價 –

回答

1

社民黨不會起初有任何ICE候選人它,你似乎缺少代碼 - 並沒有提及 - 滴在你的信令信道ICE候選人,因爲他們成爲可用:

pc.onicecandidate = e => yourSignaling.send({ ice: e.candidate }); 

和另一端:

var incoming = msg => pc.addIceCandidate(msg.ice).catch(log); 

請參閱Sending ICE candidates關於MDN。

此外,在收到優惠時,儘快撥打setRemoteDescription,然後getUserMedia,否則該對方尚未準備好接收可能在優惠後立即到達的ICE候選人。

+0

還有一個問題,如果我連接的同伴不支持涓流冰,那麼什麼纔是正確的信號發送方式? onicecandidate事件是多餘的? –

+0

@ShlomiSchwartz我想不出會發生什麼情況。同行不會運行他們自己的軟件,相反,您的軟件通常是兩端的。 - 如果你不想涓流,只需在發送'pc.localDescription'(它將包含所有候選者)之前等待'null'候選者,但在某些系統上可能需要1到20秒。 – jib

+0

我的其他同伴是FreeSwitch服務器,所以webrtc模塊是專有的,而服務器不支持涓流。我會等待null –

相關問題