public void SetConfiguration() { var peer = new RTCPeerConnection(); var config = GetConfiguration(); var result = peer.SetConfiguration(ref config); Assert.AreEqual(RTCErrorType.None, result); peer.Close(); peer.Dispose(); }
RTCPeerConnection CreatePeerConnection(ISignaling signaling, string connectionId, bool isOffer) { if (m_mapConnectionIdAndPeer.TryGetValue(connectionId, out var peer)) { peer.Close(); } var pc = new RTCPeerConnection(); m_mapConnectionIdAndPeer[connectionId] = pc; pc.OnDataChannel = new DelegateOnDataChannel(channel => { OnDataChannel(pc, channel); }); pc.SetConfiguration(ref m_conf); pc.OnIceCandidate = new DelegateOnIceCandidate(candidate => { signaling.SendCandidate(connectionId, candidate); }); pc.OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { if (state == RTCIceConnectionState.Disconnected) { pc.Close(); m_mapConnectionIdAndPeer.Remove(connectionId); } }); pc.OnTrack = trackEvent => { foreach (var viewer in m_listVideoReceiveViewer) { viewer.AddTrack(connectionId, trackEvent.Track); } }; pc.OnNegotiationNeeded = () => StartCoroutine(OnNegotiationNeeded(signaling, connectionId, isOffer)); return(pc); }
void OnOffer(ISignaling signaling, DescData e) { RTCSessionDescription _desc; _desc.type = RTCSdpType.Offer; _desc.sdp = e.sdp; var connectionId = e.connectionId; if (m_mapConnectionIdAndPeer.ContainsKey(connectionId)) { return; } var pc = new RTCPeerConnection(); m_mapConnectionIdAndPeer.Add(e.connectionId, pc); pc.OnDataChannel = new DelegateOnDataChannel(channel => { OnDataChannel(pc, channel); }); pc.SetConfiguration(ref m_conf); pc.OnIceCandidate = new DelegateOnIceCandidate(candidate => { signaling.SendCandidate(e.connectionId, candidate); }); pc.OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { if (state == RTCIceConnectionState.Disconnected) { pc.Close(); m_mapConnectionIdAndPeer.Remove(e.connectionId); } }); pc.SetRemoteDescription(ref _desc); foreach (var track in m_listVideoStreamTrack.Concat(m_audioStream.GetTracks())) { RTCRtpSender sender = pc.AddTrack(track); if (!m_mapTrackAndSenderList.TryGetValue(track, out List <RTCRtpSender> list)) { list = new List <RTCRtpSender>(); m_mapTrackAndSenderList.Add(track, list); } list.Add(sender); } RTCAnswerOptions options = default; var op = pc.CreateAnswer(ref options); while (op.MoveNext()) { } if (op.IsError) { Debug.LogError($"Network Error: {op.Error}"); return; } var desc = op.Desc; var opLocalDesc = pc.SetLocalDescription(ref desc); while (opLocalDesc.MoveNext()) { } if (opLocalDesc.IsError) { Debug.LogError($"Network Error: {opLocalDesc.Error}"); return; } signaling.SendAnswer(connectionId, desc); }
void OnOffer(ISignaling signaling, DescData e) { RTCSessionDescription _desc; _desc.type = RTCSdpType.Offer; _desc.sdp = e.sdp; var connectionId = e.connectionId; if (m_mapConnectionIdAndPeer.ContainsKey(connectionId)) { return; } var pc = new RTCPeerConnection(); m_mapConnectionIdAndPeer.Add(e.connectionId, pc); pc.OnDataChannel = new DelegateOnDataChannel(channel => { OnDataChannel(pc, channel); }); pc.SetConfiguration(ref m_conf); pc.OnIceCandidate = new DelegateOnIceCandidate(candidate => { signaling.SendCandidate(e.connectionId, candidate); }); pc.OnIceConnectionChange = new DelegateOnIceConnectionChange(state => { if (state == RTCIceConnectionState.Disconnected) { pc.Close(); m_mapConnectionIdAndPeer.Remove(e.connectionId); } }); //make video bit rate starts at 16000kbits, and 160000kbits at max. string pattern = @"(a=fmtp:\d+ .*level-asymmetry-allowed=.*)\r\n"; _desc.sdp = Regex.Replace(_desc.sdp, pattern, "$1;x-google-start-bitrate=16000;x-google-max-bitrate=160000\r\n"); pc.SetRemoteDescription(ref _desc); foreach (var track in m_listVideoStreamTrack) { pc.AddTrack(track); } foreach (var track in m_audioStream.GetTracks()) { pc.AddTrack(track); } RTCAnswerOptions options = default; var op = pc.CreateAnswer(ref options); while (op.MoveNext()) { } if (op.IsError) { Debug.LogError($"Network Error: {op.Error}"); return; } var desc = op.Desc; var opLocalDesc = pc.SetLocalDescription(ref desc); while (opLocalDesc.MoveNext()) { } if (opLocalDesc.IsError) { Debug.LogError($"Network Error: {opLocalDesc.Error}"); return; } signaling.SendAnswer(connectionId, desc); }