示例#1
0
文件: App.cs 项目: filiperamon/Beet
        /// <summary>
        /// Creates the local audio and video devices, from Icelink demo
        /// </summary>
        /// <param name="callType"></param>
        /// <param name="callback"></param>
        public void StartConference(string callType, Action <string> callback)
        {
            // Create a WebRTC audio stream description (requires a
            // reference to the local audio feed).
            AudioStream = new AudioStream(LocalMedia.LocalMediaStream);

            // Create a WebRTC video stream description (requires a
            // reference to the local video feed). Whenever a P2P link
            // initializes using this description, position and display
            // the remote video control on-screen by passing it to the
            // layout manager created above. Whenever a P2P link goes
            // down, remove it.
            VideoStream             = new VideoStream(LocalMedia.LocalMediaStream);
            VideoStream.OnLinkInit += AddRemoteVideoControl;
            VideoStream.OnLinkDown += RemoveRemoteVideoControl;

            // Create a conference using our stream descriptions.

            Conference = new FM.IceLink.Conference(StunServerAddress, new Stream[] { AudioStream, VideoStream });
            Conference.CandidateMode = CandidateMode.Early;
            // Use our pre-generated DTLS certificate.
            Conference.DtlsCertificate = Certificate;

            // Supply TURN relay credentials in case we are behind a
            // highly restrictive firewall. These credentials will be
            // verified by the TURN server.
            Conference.RelayUsername = "******";
            Conference.RelayPassword = "******";

            // Add a few event handlers to the conference so we can see
            // when a new P2P link is created or changes state.
            Conference.OnLinkInit += LogLinkInit;
            Conference.OnLinkUp   += LogLinkUp;
            Conference.OnLinkDown += LogLinkDown;


            // Start echo canceller.
            if (EnableSoftwareEchoCancellation)
            {
                OpusEchoCanceller = new OpusEchoCanceller(OpusClockRate, OpusChannels, true);
                OpusEchoCanceller.Start();
            }

            if (callType == "outgoing")
            {
                // Outgoing call
                Signalling.Call(Conference, Jid, callback);
            }
            else if (callType == "incoming")
            {
                // Incoming call
                Signalling.Answer(Conference, Jid, Sdp, callback);
            }
        }
示例#2
0
        private void StartConference()
        {
            ConferenceStarted = true;

            // Create a WebRTC audio stream description (requires a
            // reference to the local audio feed).
            AudioStream = new AudioStream(LocalMedia.LocalMediaStream);

            // Create a WebRTC video stream description (requires a
            // reference to the local video feed). Whenever a P2P link
            // initializes using this description, position and display
            // the remote video control on-screen by passing it to the
            // layout manager created above. Whenever a P2P link goes
            // down, remove it.
            VideoStream             = new VideoStream(LocalMedia.LocalMediaStream);
            VideoStream.OnLinkInit += AddRemoteVideoControl;
            VideoStream.OnLinkDown += RemoveRemoteVideoControl;

            // Create a conference using our stream descriptions.
            Conference = new FM.IceLink.Conference(IceLinkServerAddress, new Stream[] { AudioStream, VideoStream });

            // Use our pre-generated DTLS certificate.
            Conference.DtlsCertificate = Certificate;

            // Supply TURN relay credentials in case we are behind a
            // highly restrictive firewall. These credentials will be
            // verified by the TURN server.
            Conference.RelayUsername = "******";
            Conference.RelayPassword = "******";

            // Add a few event handlers to the conference so we can see
            // when a new P2P link is created or changes state.
            Conference.OnLinkInit += LogLinkInit;
            Conference.OnLinkUp   += LogLinkUp;
            Conference.OnLinkDown += LogLinkDown;

                        #if __ANDROID__
            // Start echo canceller.
            OpusEchoCanceller = new OpusEchoCanceller(OpusClockRate, OpusChannels);
            OpusEchoCanceller.Start();
                        #endif

            Signalling.Attach(Conference, SessionId, (error) =>
            {
                if (error != null)
                {
                    Alert(error);
                }
            });
        }
        public ConferenceWrapper(string sessionId,
                                 LocalMedia localMedia)
        {
            this.LocalMedia = localMedia;
            InitAudioAndVideoStreams();

            // Create a conference using our stream descriptions.
            conference = new FM.IceLink.Conference(this.IceServers, new Stream[] { audioStream, videoStream });

            // Use our pre-generated DTLS certificate.
            conference.DtlsCertificate = Certificate;

            // Supply TURN relay credentials in case we are behind a
            // highly restrictive firewall. These credentials will be
            // verified by the TURN server.
            conference.RelayUsername = "******";
            conference.RelayPassword = "******";
            conference.ServerPort    = 3478;

            // Add a few event handlers to the conference so we can see
            // when a new P2P link is created or changes state.
            conference.OnLinkInit += LogLinkInit;
            conference.OnLinkUp   += LogLinkUp;
            conference.OnLinkDown += LogLinkDown;

            conference.OnLinkOfferAnswer += OnLinkSendOfferAnswer;
            conference.OnLinkCandidate   += OnLinkSendCandidate;
            conference.Timeout            = ConferenceTimeout;

#if __ANDROID__
            // Start echo canceller.
            OpusEchoCanceller = new OpusEchoCanceller(OpusClockRate, OpusChannels);
            OpusEchoCanceller.Start();
#endif

            this.sessionId = sessionId;
        }
        public void GetUserMedia(Context context, ViewGroup videoContainer)
        {
            DefaultProviders.AndroidContext = context;

            UserMedia.GetMedia(new GetMediaArgs(true, true)
            {
                DefaultVideoPreviewScale = LayoutScale.Contain,
                DefaultVideoScale        = LayoutScale.Contain,
                VideoWidth     = 640,
                VideoHeight    = 480,
                VideoFrameRate = 15,
                OnSuccess      = (result) =>
                {
                    _localMedia                    = result.LocalStream;
                    _layoutManager                 = new AndroidLayoutManager(videoContainer);
                    _senderLocalVideoControl       = (View)result.LocalVideoControl;
                    var localVideoStream           = new VideoStream(result.LocalStream);
                    _conference                    = new Conference(STUN_TURN_URL, new Stream[] { new AudioStream(result.LocalStream), localVideoStream });
                    _conference.RelayUsername      = "******";
                    _conference.RelayPassword      = "******";
                    _conference.DtlsCertificate    = Certificate.GenerateCertificate();
                    _conference.OnLinkCandidate   += Conference_OnLinkCandidate;
                    _conference.OnLinkOfferAnswer += Conference_OnLinkOfferAnswer;

                    localVideoStream.OnLinkInit += LocalVideoStream_OnLinkInit;
                    localVideoStream.OnLinkDown += LocalVideoStream_OnLinkDown;
                    _layoutManager.SetLocalVideoControl(_senderLocalVideoControl);
                    _opusEchoCanceller = new OpusEchoCanceller(4800, 2);
                    _opusEchoCanceller.Start();
                },
                OnFailure = (error) =>
                {
                    Console.WriteLine(error);
                }
            });
        }