void OnAnswer(ISignaling signaling, DescData e) { if (!_mapConnectionIdAndPeer.TryGetValue(e.connectionId, out var pc)) { Debug.Log($"connectionId:{e.connectionId}, peerConnection not exist"); return; } _startCoroutine(GotAnswerCoroutine(e.connectionId, pc, e.sdp)); }
void OnOffer(ISignaling signaling, DescData e) { var connectionId = e.connectionId; if (!_mapConnectionIdAndPeer.TryGetValue(connectionId, out var pc)) { pc = CreatePeerConnection(connectionId, false); } _startCoroutine(GotOfferCoroutine(connectionId, pc, e.sdp)); }
IEnumerator OnOffer(ISignaling signaling, DescData e) { var connectionId = e.connectionId; RTCPeerConnection pc = null; if (!m_mapConnectionIdAndPeer.TryGetValue(connectionId, out pc)) { pc = CreatePeerConnection(signaling, connectionId, false); } RTCSessionDescription _desc; _desc.type = RTCSdpType.Offer; _desc.sdp = e.sdp; var opRemoteDesc = pc.SetRemoteDescription(ref _desc); yield return(opRemoteDesc); if (opRemoteDesc.IsError) { Debug.LogError($"Network Error: {opRemoteDesc.Error.message}"); yield break; } AddTracks(connectionId, pc); RTCAnswerOptions options = default; var op = pc.CreateAnswer(ref options); yield return(op); if (op.IsError) { Debug.LogError($"Network Error: {op.Error.message}"); yield break; } var desc = op.Desc; var opLocalDesc = pc.SetLocalDescription(ref desc); yield return(opLocalDesc); if (opLocalDesc.IsError) { Debug.LogError($"Network Error: {opLocalDesc.Error.message}"); yield break; } signaling.SendAnswer(connectionId, desc); }
IEnumerator OnAnswer(ISignaling signaling, DescData e) { if (!m_mapConnectionIdAndPeer.TryGetValue(e.connectionId, out var pc)) { Debug.Log($"connectiondId:{e.connectionId}, peerConnection not exist"); yield break; } var desc = new RTCSessionDescription(); desc.type = RTCSdpType.Answer; desc.sdp = e.sdp; var opRemoteSdp = pc.SetRemoteDescription(ref desc); yield return(opRemoteSdp); if (opRemoteSdp.IsError) { Debug.LogError($"Network Error: {opRemoteSdp.Error.message}"); yield break; } }
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); }
IEnumerator OnOffer(ISignaling signaling, DescData e) { var connectionId = e.connectionId; if (m_mapConnectionIdAndPeer.ContainsKey(connectionId)) { Debug.LogError($"connection:{connectionId} peerConnection already exist"); yield break; } var pc = CreatePeerConnection(signaling, connectionId, false); RTCSessionDescription _desc; _desc.type = RTCSdpType.Offer; _desc.sdp = e.sdp; var opRemoteDesc = pc.SetRemoteDescription(ref _desc); yield return(opRemoteDesc); if (opRemoteDesc.IsError) { Debug.LogError($"Network Error: {opRemoteDesc.Error.message}"); yield break; } // ToDo: need webrtc package version 2.3 // foreach (var transceiver in pc.GetTransceivers() // .Where(x => x.Receiver.Track.Kind == TrackKind.Video) // .Select((x, index) => new {x, index}) // .Take(m_listVideoStreamTrack.Count)) // { // RTCRtpSender sender = transceiver.x.Sender; // VideoStreamTrack track = m_listVideoStreamTrack[transceiver.index]; // transceiver.x.Sender.ReplaceTrack(track); // transceiver.x.Direction = RTCRtpTransceiverDirection.SendOnly; // // if (!m_mapTrackAndSenderList.TryGetValue(track, out List<RTCRtpSender> list)) // { // list = new List<RTCRtpSender>(); // m_mapTrackAndSenderList.Add(track, list); // } // // list.Add(sender); // } foreach (var track in m_listVideoStreamTrack) { 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); } foreach (var track in 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); yield return(op); if (op.IsError) { Debug.LogError($"Network Error: {op.Error.message}"); yield break; } var desc = op.Desc; var opLocalDesc = pc.SetLocalDescription(ref desc); yield return(opLocalDesc); if (opLocalDesc.IsError) { Debug.LogError($"Network Error: {opLocalDesc.Error.message}"); yield break; } 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); }
void OnAnswer(ISignaling signaling, DescData e) { // TODO: Answer sdp SetRemoteDescription }
IEnumerator OnOffer(ISignaling signaling, DescData e) { var connectionId = e.connectionId; if (m_mapConnectionIdAndPeer.ContainsKey(connectionId)) { Debug.LogError($"connection:{connectionId} peerConnection already exist"); yield break; } var pc = CreatePeerConnection(signaling, connectionId, false); RTCSessionDescription _desc; _desc.type = RTCSdpType.Offer; _desc.sdp = e.sdp; var opRemoteDesc = pc.SetRemoteDescription(ref _desc); yield return(opRemoteDesc); if (opRemoteDesc.IsError) { Debug.LogError($"Network Error: {opRemoteDesc.Error.message}"); yield break; } 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); yield return(op); if (op.IsError) { Debug.LogError($"Network Error: {op.Error.message}"); yield break; } var desc = op.Desc; var opLocalDesc = pc.SetLocalDescription(ref desc); yield return(opLocalDesc); if (opLocalDesc.IsError) { Debug.LogError($"Network Error: {opLocalDesc.Error.message}"); yield break; } signaling.SendAnswer(connectionId, desc); }