1、創建offer的時候帶上參數:{ offerToReceiveAudio: true, offerToReceiveVideo: true }
2、onicecandidate 必須寫在 setLocalDescription 之前,因為一調用setLocalDescription,立馬會產生icecandidate。
3、pc.addTrack(或者addStream)必須在pc.createAnswer之前,如果你的offer沒有帶上參數(第一條),那么也應該在pc.createOffer()之前。因為offer或者answer帶有媒體信息。
4、webrtc 是 peer to peer ,不是peers to peers。A與B 相連,A需要new RTCPeerConnection,B也需要。A再與C相連,A還需要new RTCPeerConnection
5、stun 服務器,是提供打洞的東西,turn服務器是提供數據中轉的東西。打洞(Nat類型及穿透)請看我的另一篇博客,webrtc只支持 https和 localhost,所以局內網主機能開視頻,另一端(另一台電腦)只能看。
6、火狐報錯:xxx failed(需要turn但根本沒有turn服務器),還有一種,turn Server appears to be broken:這個是turn服務器限制連接數量,就是說人較多,你擠不上去了。
免費的turn 是http://numb.viagenie.ca,去申請賬號密碼。
免費的stun : stun:stun.freeswitch.org 、stun.ekiga.net
自己布turn: github 搜 coturn
個人網頁:gusheng123.top,可測試多對多視頻。