Пример #1
0
        public CallHandler(ICall statefulCall, PeerConnection peerConnection)
            : base(TimeSpan.FromMinutes(10), statefulCall?.GraphLogger)
        {
            this.Call = statefulCall;

            this.callHandlerVideo = new CallHandlerVideo(this.Call);
            this.callHandlerAudio = new CallHandlerAudio(this.Call);

            this.peerConnection = peerConnection;

            this.peerConnection.VideoTrackAdded   += this.callHandlerVideo.OnClientVideoTrackAdded;
            this.peerConnection.VideoTrackRemoved += this.callHandlerVideo.OnClientVideoTrackRemoved;

            this.peerConnection.AudioTrackAdded   += this.callHandlerAudio.OnClientAudioTrackAdded;
            this.peerConnection.AudioTrackRemoved += this.callHandlerAudio.OnClientAudioTrackRemoved;

            TransceiverInitSettings transceiverInitSettings = new TransceiverInitSettings();

            transceiverInitSettings.InitialDesiredDirection = Transceiver.Direction.Inactive;

            if (this.peerConnection.AssociatedTransceivers.ToList().Count != 0)
            {
                this.teamsAudioTransceiver             = this.peerConnection.AssociatedTransceivers.ToList()[0];
                this.callHandlerAudio.clientAudioTrack = this.peerConnection.AssociatedTransceivers.ToList()[0].RemoteAudioTrack;
                this.callHandlerAudio.clientAudioTrack.AudioFrameReady += this.callHandlerAudio.OnClientAudioReceived;

                this.teamsVideoTransceiver             = this.peerConnection.AssociatedTransceivers.ToList()[1];
                this.callHandlerVideo.clientVideoTrack = this.peerConnection.AssociatedTransceivers.ToList()[1].RemoteVideoTrack;
                this.callHandlerVideo.clientVideoTrack.I420AVideoFrameReady += this.callHandlerVideo.OnClientVideoReceived;
            }
            else
            {
                this.teamsAudioTransceiver = this.peerConnection.AddTransceiver(MediaKind.Audio, transceiverInitSettings);
                this.teamsVideoTransceiver = this.peerConnection.AddTransceiver(MediaKind.Video, transceiverInitSettings);
            }

            LocalVideoTrack teamsVideoTrack = LocalVideoTrack.CreateFromExternalSource("TeamsVideoTrack",
                                                                                       ExternalVideoTrackSource.CreateFromI420ACallback(this.callHandlerVideo.CustomI420AFrameCallback));

            this.teamsVideoTransceiver.LocalVideoTrack = teamsVideoTrack;

            this.teamsVideoTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;

            LocalAudioTrack teamsAudioTrack = LocalAudioTrack.CreateFromExternalSource("TeamsAudioTrack",
                                                                                       ExternalAudioTrackSource.CreateFromCallback(this.callHandlerAudio.CustomAudioFrameCallback));

            this.teamsAudioTransceiver.LocalAudioTrack = teamsAudioTrack;

            this.teamsAudioTransceiver.DesiredDirection = Transceiver.Direction.SendReceive;

            this.Call.OnUpdated += this.OnCallUpdated;
            if (this.Call.GetLocalMediaSession() != null)
            {
                this.Call.GetLocalMediaSession().AudioSocket.DominantSpeakerChanged += this.OnDominantSpeakerChanged;
                this.Call.GetLocalMediaSession().VideoSocket.VideoMediaReceived     += this.callHandlerVideo.OnTeamsVideoReceived;
                this.Call.GetLocalMediaSession().AudioSocket.AudioMediaReceived     += this.callHandlerAudio.OnTeamsAudioReceived;
            }

            this.Call.Participants.OnUpdated += this.OnParticipantsUpdated;
            this.endCallTimer           = new Timer(CallHandler.WaitForMs);
            this.endCallTimer.Enabled   = false;
            this.endCallTimer.AutoReset = false;
            this.endCallTimer.Elapsed  += this.OnTimerElapsed;
        }