public void Dispose() { foreach (var sender in pc1Senders) { peer1.RemoveTrack(sender); } foreach (var sender in pc2Senders) { peer2.RemoveTrack(sender); } pc1Senders.Clear(); peer1.Close(); peer2.Close(); }
private void RemoveTracks() { foreach (var sender in pc1Senders) { _pc1.RemoveTrack(sender); } pc1Senders.Clear(); MediaStreamTrack[] tracks = receiveStream.GetTracks().ToArray(); foreach (var track in tracks) { receiveStream.RemoveTrack(track); track.Dispose(); } }
private void RemoveTracks() { foreach (var sender in pc1Senders) { _pc1.RemoveTrack(sender); } foreach (var sender in pc2Senders) { _pc2.RemoveTrack(sender); } pc1Senders.Clear(); pc2Senders.Clear(); addTracksButton.interactable = true; removeTracksButton.interactable = false; trackInfos.Clear(); infoText.text = ""; }
private void RemoveTracks() { foreach (var sender in pc1Senders) { _pc1.RemoveTrack(sender); } foreach (var transceiver in _pc1.GetTransceivers()) { transceiver.Stop(); } pc1Senders.Clear(); addTracksButton.interactable = true; removeTracksButton.interactable = false; trackInfos.Clear(); infoText.text = ""; }
private void RemoveTracks() { var transceivers = _pc1.GetTransceivers(); foreach (var transceiver in transceivers) { if (transceiver.Sender != null) { transceiver.Stop(); _pc1.RemoveTrack(transceiver.Sender); } } pc1Senders.Clear(); addTracksButton.interactable = true; removeTracksButton.interactable = false; }
public void GetTransceiversReturnsNotEmptyAfterCallingRemoveTrack() { // Also, `RTCPeerConnection.AddTrack` and `RTCPeerConnection.RemoveTrack` method is not intuitive. var peer = new RTCPeerConnection(); var width = 256; var height = 256; var format = WebRTC.GetSupportedRenderTextureFormat(UnityEngine.SystemInfo.graphicsDeviceType); var rt = new UnityEngine.RenderTexture(width, height, 0, format); rt.Create(); var track = new VideoStreamTrack(rt); var sender = peer.AddTrack(track); Assert.That(peer.GetTransceivers(), Has.Count.EqualTo(1)); Assert.That(peer.RemoveTrack(sender), Is.EqualTo(RTCErrorType.None)); Assert.That(peer.GetTransceivers(), Has.Count.EqualTo(1)); peer.Dispose(); }
public IEnumerator SetRemoteDescriptionFailed() { var config = GetDefaultConfiguration(); var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); var stream = new MediaStream(); var obj = new GameObject("audio"); var source = obj.AddComponent <AudioSource>(); source.clip = AudioClip.Create("test", 480, 2, 48000, false); var track = new AudioStreamTrack(source); var sender = peer1.AddTrack(track, stream); var op1 = peer1.CreateOffer(); yield return(op1); var desc = op1.Desc; var op2 = peer1.SetLocalDescription(ref desc); yield return(op2); // change sdp to cannot parse desc.sdp = desc.sdp.Replace("a=mid:0", "a=mid:10"); var op3 = peer2.SetRemoteDescription(ref desc); yield return(op3); Assert.True(op3.IsDone); Assert.True(op3.IsError); Assert.IsNotEmpty(op3.Error.message); peer1.RemoveTrack(sender); track.Dispose(); stream.Dispose(); peer1.Close(); peer2.Close(); peer1.Dispose(); peer2.Dispose(); Object.DestroyImmediate(source.clip); Object.DestroyImmediate(obj); }
public IEnumerator SetRemoteDescriptionFailed() { var config = GetConfiguration(); var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); var stream = new MediaStream(); var track = new AudioStreamTrack("audio"); var sender = peer1.AddTrack(track, stream); RTCOfferOptions options1 = default; var op1 = peer1.CreateOffer(ref options1); yield return(op1); var desc = op1.Desc; var op2 = peer1.SetLocalDescription(ref desc); yield return(op2); // change sdp to cannot parse desc.sdp = desc.sdp.Replace("m=audio", "m=audiable"); var op3 = peer2.SetRemoteDescription(ref desc); yield return(op3); Assert.True(op3.IsDone); Assert.True(op3.IsError); Assert.IsNotEmpty(op3.Error.message); peer1.RemoveTrack(sender); track.Dispose(); stream.Dispose(); peer1.Close(); peer2.Close(); peer1.Dispose(); peer2.Dispose(); }
public IEnumerator SetLocalDescriptionFailed() { var peer = new RTCPeerConnection(); var stream = new MediaStream(); var obj = new GameObject("audio"); var source = obj.AddComponent <AudioSource>(); source.clip = AudioClip.Create("test", 480, 2, 48000, false); var track = new AudioStreamTrack(source); var sender = peer.AddTrack(track, stream); var op = peer.CreateOffer(); yield return(op); Assert.True(op.IsDone); Assert.False(op.IsError); var desc = op.Desc; // change sdp to cannot parse desc.sdp = desc.sdp.Replace("a=mid:0", "a=mid:10"); var op2 = peer.SetLocalDescription(ref desc); yield return(op2); Assert.True(op2.IsDone); Assert.True(op2.IsError); Assert.IsNotEmpty(op2.Error.message); Assert.That(peer.RemoveTrack(sender), Is.EqualTo(RTCErrorType.None)); track.Dispose(); stream.Dispose(); peer.Close(); peer.Dispose(); Object.DestroyImmediate(source.clip); Object.DestroyImmediate(obj); }
public void RemoveTrack() { offerPc.RemoveTrack(sender); }
public IEnumerator RemoteOnRemoveTrack() { RTCConfiguration config = default; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); peer1.OnIceCandidate = candidate => { peer2.AddIceCandidate(candidate); }; peer2.OnIceCandidate = candidate => { peer1.AddIceCandidate(candidate); }; var stream = new MediaStream(); MediaStream receiveStream = null; var obj = new GameObject("audio"); var source = obj.AddComponent <AudioSource>(); source.clip = AudioClip.Create("test", 480, 2, 48000, false); var track = new AudioStreamTrack(source); stream.AddTrack(track); RTCRtpSender sender = peer1.AddTrack(track, stream); bool isInvokeNegotiationNeeded1 = false; peer1.OnNegotiationNeeded = () => isInvokeNegotiationNeeded1 = true; bool isInvokeOnRemoveTrack = false; peer2.OnTrack = e => { Assert.That(e.Streams, Has.Count.EqualTo(1)); receiveStream = e.Streams.First(); receiveStream.OnRemoveTrack = ev => isInvokeOnRemoveTrack = true; }; yield return(SignalingOffer(peer1, peer2)); peer1.RemoveTrack(sender); var op9 = new WaitUntilWithTimeout(() => isInvokeNegotiationNeeded1, 5000); yield return(op9); Assert.That(op9.IsCompleted, Is.True); yield return(SignalingOffer(peer1, peer2)); var op10 = new WaitUntilWithTimeout(() => isInvokeOnRemoveTrack, 5000); yield return(op10); Assert.That(op10.IsCompleted, Is.True); stream.Dispose(); receiveStream.Dispose(); track.Dispose(); peer1.Dispose(); peer2.Dispose(); Object.DestroyImmediate(source.clip); Object.DestroyImmediate(obj); }
IEnumerator Start() { RTCConfiguration config = default; config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } }; var pc1Senders = new List <RTCRtpSender>(); var pc2Senders = new List <RTCRtpSender>(); var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); peer1.OnIceCandidate = candidate => { peer2.AddIceCandidate(ref candidate); }; peer2.OnIceCandidate = candidate => { peer1.AddIceCandidate(ref candidate); }; peer2.OnTrack = e => { pc2Senders.Add(peer2.AddTrack(e.Track)); }; foreach (var track in _stream.GetTracks()) { pc1Senders.Add(peer1.AddTrack(track)); } RTCOfferOptions options1 = default; RTCAnswerOptions options2 = default; var op1 = peer1.CreateOffer(ref options1); yield return(op1); var op2 = peer1.SetLocalDescription(ref op1.desc); yield return(op2); var op3 = peer2.SetRemoteDescription(ref op1.desc); yield return(op3); var op4 = peer2.CreateAnswer(ref options2); yield return(op4); var op5 = peer2.SetLocalDescription(ref op4.desc); yield return(op5); var op6 = peer1.SetRemoteDescription(ref op4.desc); yield return(op6); var op7 = new WaitUntilWithTimeout(() => peer1.IceConnectionState == RTCIceConnectionState.Connected || peer1.IceConnectionState == RTCIceConnectionState.Completed, 5000); yield return(op7); Assert.True(op7.IsCompleted); var op8 = new WaitUntilWithTimeout(() => peer2.IceConnectionState == RTCIceConnectionState.Connected || peer2.IceConnectionState == RTCIceConnectionState.Completed, 5000); yield return(op8); Assert.True(op7.IsCompleted); var op9 = new WaitUntilWithTimeout(() => pc2Senders.Count > 0, 5000); yield return(op9); Assert.True(op9.IsCompleted); foreach (var sender in pc1Senders) { peer1.RemoveTrack(sender); } foreach (var sender in pc2Senders) { peer2.RemoveTrack(sender); } pc1Senders.Clear(); peer1.Close(); peer2.Close(); _isFinished = true; }
public IEnumerator MediaStreamTest_AddAndRemoveMediaStream() { var camObj = new GameObject("Camera"); var cam = camObj.AddComponent <Camera>(); RTCConfiguration config = default; config.iceServers = new RTCIceServer[] { new RTCIceServer { urls = new string[] { "stun:stun.l.google.com:19302" } } }; if (!WebRTC.HWEncoderSupport) { Assert.Pass("Test environment does not support HW encoding"); } var pc1Senders = new List <RTCRtpSender>(); var pc2Senders = new List <RTCRtpSender>(); var peer1 = new RTCPeerConnection(ref config); var peer2 = new RTCPeerConnection(ref config); peer1.OnIceCandidate = new DelegateOnIceCandidate(candidate => { peer2.AddIceCandidate(ref candidate); }); peer2.OnIceCandidate = new DelegateOnIceCandidate(candidate => { peer1.AddIceCandidate(ref candidate); }); peer2.OnTrack = new DelegateOnTrack(e => { pc2Senders.Add(peer2.AddTrack(e.Track)); }); foreach (var track in cam.CaptureStream(1280, 720).GetTracks()) { pc1Senders.Add(peer1.AddTrack(track)); } var conf = new RTCDataChannelInit(true); RTCOfferOptions options1 = default; RTCAnswerOptions options2 = default; var op1 = peer1.CreateOffer(ref options1); yield return(op1); var op2 = peer1.SetLocalDescription(ref op1.desc); yield return(op2); var op3 = peer2.SetRemoteDescription(ref op1.desc); yield return(op3); var op4 = peer2.CreateAnswer(ref options2); yield return(op4); var op5 = peer2.SetLocalDescription(ref op4.desc); yield return(op5); var op6 = peer1.SetRemoteDescription(ref op4.desc); yield return(op6); yield return(new WaitUntil(() => peer1.IceConnectionState == RTCIceConnectionState.Connected || peer1.IceConnectionState == RTCIceConnectionState.Completed)); yield return(new WaitUntil(() => peer2.IceConnectionState == RTCIceConnectionState.Connected || peer2.IceConnectionState == RTCIceConnectionState.Completed)); yield return(new WaitUntil(() => pc2Senders.Count > 0)); foreach (var sender in pc1Senders) { peer1.RemoveTrack(sender); } foreach (var sender in pc2Senders) { peer2.RemoveTrack(sender); } pc1Senders.Clear(); GameObject.DestroyImmediate(camObj); peer1.Close(); peer2.Close(); }