private async Task InitializeORTC()
        {
            var gatherOptions = new RTCIceGatherOptions()
            {
                IceServers = new List <RTCIceServer>()
                {
                    new RTCIceServer {
                        Urls = new string[] { "stun.l.google.com:19302" }
                    },
                    new RTCIceServer {
                        Username = "******", Credential = "redmond123", CredentialType = RTCIceGathererCredentialType.Password, Urls = new string[] { "turn:turn-testdrive.cloudapp.net:3478?transport=udp" }
                    }
                }
            };

            _gatherer = new RTCIceGatherer(gatherOptions);
            _gatherer.OnStateChange += IceGatherer_OnStateChange;

            _gatherer.OnLocalCandidate += async(candidate) =>
            {
                await _signaler.SendToPeer(RemotePeer.Id, candidate.Candidate.ToJsonString());
            };

            var cert = await RTCCertificate.GenerateCertificate();

            _ice = new RTCIceTransport(_gatherer);
            _ice.OnStateChange += IceTransport_OnStateChange;

            _dtls = new RTCDtlsTransport(_ice, new RTCCertificate[] { cert });
            _dtls.OnStateChange += Dtls_OnStateChange;

            _sctp = new RTCSctpTransport(_dtls);
        }
예제 #2
0
        protected virtual void Dispose(bool disposing)
        {
            // clean all unmanaged resources (if any)

            if (disposing)
            {
                // clean all managed resources
                if (_dataChannel != null)
                {
                    _dataChannel.Close();
                    _dataChannel = null;
                }
                if (_sctp != null)
                {
                    _sctp.Stop();
                    _sctp = null;
                }
                if (_dtls != null)
                {
                    _dtls.Stop();
                    _dtls = null;
                }
                if (_ice != null)
                {
                    _ice.Stop();
                    _ice = null;
                }
                if (_gatherer != null)
                {
                    _gatherer.Close();
                    _gatherer = null;
                }
            }
        }
예제 #3
0
        private async Task InitializeORTC()
        {
            var gatherOptions = new RTCIceGatherOptions()
            {
                IceServers = new List <RTCIceServer>()
                {
                    new RTCIceServer
                    {
                        Urls = new string[] { _stunUrl }
                    },
                    new RTCIceServer
                    {
                        Username       = _turnUsername,
                        Credential     = _turnCredential,
                        CredentialType = RTCIceCredentialType.Password,
                        Urls           = new string[] { _turnUrl }
                    }
                }
            };

            _gatherer = new RTCIceGatherer(gatherOptions);

            _gatherer.OnStateChange += IceGatherer_OnStateChange;

            _gatherer.OnLocalCandidate += (@event) =>
            {
                OnSignalMessageToPeer(@event.Candidate.ToJson().ToString());
            };
            _gatherer.OnLocalCandidateComplete += (@event) =>
            {
                OnSignalMessageToPeer(@event.Candidate.ToJson().ToString());
            };

            _ice = new RTCIceTransport(_gatherer);
            _ice.OnStateChange += IceTransport_OnStateChange;

            _dtls = new RTCDtlsTransport(_ice, new RTCCertificate[]
            {
                await RTCCertificate.GenerateCertificate()
            });
            _dtls.OnStateChange += Dtls_OnStateChange;

            _sctp = new RTCSctpTransport(_dtls);

            _gatherer.Gather(null);
        }
예제 #4
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RTCIceGatherOptions options = new RTCIceGatherOptions();
            RTCIceServer        server  = new RTCIceServer();

            server.UserName   = "******";
            server.Credential = "12345";
            server.Urls       = new List <String>();
            server.Urls.Add("stun:stun.vline.com");
            options.IceServers = new List <RTCIceServer>();
            options.IceServers.Add(server);

            _iceGatherer = new RTCIceGatherer(options);
            _iceGatherer.OnStateChange            += this.RTCIceGatherer_onICEGathererStateChanged;
            _iceGatherer.OnLocalCandidate         += this.RTCIceGatherer_onICEGathererLocalCandidate;
            _iceGatherer.OnLocalCandidateComplete += this.RTCIceGatherer_onICEGathererCandidateComplete;
            _iceGatherer.OnLocalCandidateGone     += this.RTCIceGatherer_onICEGathererLocalCandidateGone;
            _iceGatherer.OnError += this.RTCIceGatherer_onICEGathererError;


            _iceGatherer2 = new RTCIceGatherer(options);
            _iceGatherer2.OnStateChange            += this.RTCIceGatherer_onICEGathererStateChanged2;
            _iceGatherer2.OnLocalCandidate         += this.RTCIceGatherer_onICEGathererLocalCandidate2;
            _iceGatherer2.OnLocalCandidateComplete += this.RTCIceGatherer_onICEGathererCandidateComplete2;
            _iceGatherer2.OnLocalCandidateGone     += this.RTCIceGatherer_onICEGathererLocalCandidateGone2;
            _iceGatherer2.OnError += this.RTCIceGatherer_onICEGathererError;

            _iceTransport = new RTCIceTransport(_iceGatherer);
            _iceTransport.OnStateChange            += RTCIceTransport_onICETransportStateChanged;
            _iceTransport.OnCandidatePairAvailable += RTCIceTransport_onICETransportCandidatePairAvailable;
            _iceTransport.OnCandidatePairGone      += RTCIceTransport_onICETransportCandidatePairGone;
            _iceTransport.OnCandidatePairChange    += RTCIceTransport_onICETransportCandidatePairChanged;

            _iceTransport2 = new RTCIceTransport(_iceGatherer);
            _iceTransport2.OnStateChange            += RTCIceTransport_onICETransportStateChanged2;
            _iceTransport2.OnCandidatePairAvailable += RTCIceTransport_onICETransportCandidatePairAvailable2;
            _iceTransport2.OnCandidatePairGone      += RTCIceTransport_onICETransportCandidatePairGone2;
            _iceTransport2.OnCandidatePairChange    += RTCIceTransport_onICETransportCandidatePairChanged2;

            RTCCertificate.GenerateCertificate().AsTask <RTCCertificate>().ContinueWith((cert) =>
            {
                String str = cert.Result.Expires.ToString();
                List <RTCCertificate> certs = new List <RTCCertificate>();
                certs.Add(cert.Result);
                _dtlsTransport = new RTCDtlsTransport(_iceTransport, certs);
                MediaStreamConstraints constraints = new MediaStreamConstraints();

                constraints.Audio = new MediaTrackConstraints();
                constraints.Video = new MediaTrackConstraints();

                MediaDevices.GetUserMedia(constraints).AsTask().ContinueWith <IList <MediaStreamTrack> >((temp) =>
                {
                    if (temp.Result != null && temp.Result.Count() > 0)
                    {
                        List <MediaStreamTrack> ret = new List <MediaStreamTrack>(temp.Result);
                        List <RTCRtpSender> senders = new List <RTCRtpSender>();
                        foreach (MediaStreamTrack track in temp.Result)
                        {
                            RTCRtpSender rtpSender = new RTCRtpSender(track, _dtlsTransport);
                            senders.Add(rtpSender);
                        }

                        return(ret);
                    }

                    return(null);
                });
            });

            RTCCertificate.GenerateCertificate().AsTask <RTCCertificate>().ContinueWith((cert) =>
            {
                var certs = new List <RTCCertificate>();
                certs.Add(cert.Result);
                _dtlsTransport2 = new RTCDtlsTransport(_iceTransport2, certs);
            });

            MediaDevices.EnumerateDevices().AsTask().ContinueWith <MediaDeviceInfo>((temp) =>
            {
                foreach (MediaDeviceInfo info in temp.Result)
                {
                    if (info.DeviceId != null)
                    {
                        System.Diagnostics.Debug.WriteLine("DeviceID: {0}", info.DeviceId);
                    }
                }
                return(null);
            });
        }