Exemplo n.º 1
0
        async void HandleInitialOffer(string sdp, OfferConfig offerConf)
        {
            Logger.Debug("MediaChannel", "Handle Initial Offer");

            if (peer != null)
            {
                Logger.Debug("MediaChannel", "peer not found");
                return;
            }

            var rtcConf = NetworkConfiguration.Create(offerConf, mediaOption);

            peer = new PeerChannel(rtcConf, mediaOption, dispatcher);

            peer.OnConnect            += Peer_OnConnect;
            peer.OnClose              += Peer_OnClose;
            peer.OnError              += Peer_OnError;
            peer.OnIceCandidate       += Peer_OnIceCandidate;
            peer.OnAddLocalAudioTrack += Peer_OnAddLocalAudioTrack;
            peer.OnAddLocalVideoTrack += Peer_OnAddLocalVideoTrack;
            peer.OnAddRemoteTrack     += Peer_OnAddRemoteTrack;
            peer.OnRemoveRemoteTrack  += Peer_OnRemoveRemoteTrack;

            streamIdChecker.PickMsidFromSdp(sdp);

            if (!peer.Initialize())
            {
                Logger.Debug("MediaChannel", "failed to initialize peer");
                RunOnUiThread(() => {
                    OnError?.Invoke(ErrorType.PeerCantBuild);
                });
                Disconnect();
            }

            var answer = await peer.HandleInitialRemoteOffer(sdp);

            if (string.IsNullOrEmpty(answer))
            {
                Logger.Debug("MediaChannel", "failed to create answer for remote offer");

                RunOnUiThread(() => {
                    OnError?.Invoke(ErrorType.PeerSdpFailure);
                });

                Disconnect();

                return;
            }

            await signaling.SendAnswerMessage(answer);
        }
Exemplo n.º 2
0
        void StartPeerWithClientOffer()
        {
            Logger.Debug("MediaChannel", "StartPeerWithClientOffer");

            Task.Run(async() => {
                var dummyConf = new OfferConfig();

                var rtcConf = NetworkConfiguration.Create(dummyConf, mediaOption);

                var tempMediaOption = new MediaOption()
                {
                    SpeakerDevice          = mediaOption.SpeakerDevice,
                    VideoDownstreamEnabled = true,
                };

                tempPeer = new PeerChannel(rtcConf, tempMediaOption, dispatcher);

                tempPeer.OnError += TempPeer_OnError;
                tempPeer.OnClose += TempPeer_OnClose;

                if (!tempPeer.Initialize())
                {
                    Logger.Debug("MediaChannel", "failed to initialize peer");
                    RunOnUiThread(() => {
                        OnError?.Invoke(ErrorType.PeerCantBuild);
                    });
                    Disconnect();
                }

                var sdp = await tempPeer.GenerateClientOffer();

                CloseTempPeer();

                if (string.IsNullOrEmpty(sdp))
                {
                    Logger.Debug("MediaChannel", "failed to create capabilities");

                    RunOnUiThread(() => {
                        OnError?.Invoke(ErrorType.PeerSdpFailure);
                    });

                    Disconnect();
                }
                else
                {
                    ConnectSignalingChannel(sdp);
                }
            });
        }