Example #1
0
        private void ToxAv_OnCallStateChanged(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            var state = CallState.InProgress;

            if ((e.State & ToxAvFriendCallState.Finished) != 0 || (e.State & ToxAvFriendCallState.Error) != 0)
            {
                if (_callInfo != null)
                {
                    _callInfo.Dispose();
                    _callInfo = null;
                }

                state = CallState.None;
            }
            else if ((e.State & ToxAvFriendCallState.ReceivingAudio) != 0 ||
                     (e.State & ToxAvFriendCallState.ReceivingVideo) != 0 ||
                     (e.State & ToxAvFriendCallState.SendingAudio) != 0 ||
                     (e.State & ToxAvFriendCallState.SendingVideo) != 0)
            {
                //start sending whatever from here
                if (_callInfo.AudioEngine != null)
                {
                    if (!_callInfo.AudioEngine.IsRecording)
                    {
                        _callInfo.AudioEngine.StartRecording();
                    }
                }

                if (_callInfo.VideoEngine != null)
                {
                    if (!_callInfo.VideoEngine.IsRecording)
                    {
                        _callInfo.VideoEngine.StartRecording();
                    }
                }

                if (e.State.HasFlag(ToxAvFriendCallState.SendingVideo))
                {
                    state |= CallState.SendingVideo;
                }

                if (_callInfo.VideoEngine != null)
                {
                    state |= CallState.ReceivingVideo;
                }
            }

            MainWindow.Instance.UInvoke(() =>
            {
                var friend = MainWindow.Instance.ViewModel.CurrentFriendListView.FindFriend(e.FriendNumber);
                if (friend == null)
                {
                    Debugging.Write("Received a call state change from a friend we don't know about!");
                    return;
                }

                friend.CallState = state;
            });
        }
Example #2
0
        private void CallStateChangedHandler(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            if ((e.FriendNumber == _friendInCall) &&
                (e.State.HasFlag(ToxAvFriendCallState.Finished) || e.State.HasFlag(ToxAvFriendCallState.Error)))
            {
                _friendInCall = -1;
            }

            CallStateChanged?.Invoke(this, e);
        }
Example #3
0
        private void CallStateChangedHandler(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            if (e.FriendNumber != _friendNumber)
            {
                return;
            }

            if (e.State.HasFlag(ToxAvFriendCallState.ReceivingAudio) ||
                e.State.HasFlag(ToxAvFriendCallState.SendingAudio))
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() => { State = CallState.DuringCall; });
            }

            _friendIsReceivingAudio = e.State.HasFlag(ToxAvFriendCallState.ReceivingAudio);

            if (e.State.HasFlag(ToxAvFriendCallState.Finished) || e.State.HasFlag(ToxAvFriendCallState.Error))
            {
                StopAudioGraph();
                DispatcherHelper.CheckBeginInvokeOnUI(() => { State = CallState.Default; });
            }
        }
Example #4
0
        private void OnToxAvCallStateChanged(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            Logger.Log(LogLevel.Verbose, "state: " + e.State);

            CallState friendCallState = CallState.CallInProgress;

            if ((e.State & ToxAvFriendCallState.Finished) != 0 ||
                (e.State & ToxAvFriendCallState.Error) != 0)
            {
                bool enableRecording = true;
                bool enablePlayback  = true;
                bool enableVideo     = true;

                if (this.callInfo != null)
                {
                    enableRecording = this.callInfo.RecordingDevice.IsEnabled;
                    enablePlayback  = this.callInfo.PlaybackDevice.IsEnabled;
                    enableVideo     = this.callInfo.VideoDevice.IsEnabled;

                    this.callInfo.FriendCallState = e.State;
                    this.callInfo.Dispose();
                    this.callInfo = null;
                }

                friendCallState = CallState.None;

                // enable local audio/video monitors
                this.RestartRecordingMonitor(enableRecording);
                this.RestartPlaybackMonitor(enablePlayback);
                this.RestartVideoMonitor(enableVideo);

                // stop ringing
                this.StopRingingSound();
            }
            else if ((e.State & ToxAvFriendCallState.ReceivingAudio) != 0 ||
                     (e.State & ToxAvFriendCallState.ReceivingVideo) != 0 ||
                     (e.State & ToxAvFriendCallState.SendingAudio) != 0 ||
                     (e.State & ToxAvFriendCallState.SendingVideo) != 0)
            {
                // disable local audio/video monitors
                this.RestartRecordingMonitor(false);
                this.RestartPlaybackMonitor(false);
                this.RestartVideoMonitor(false);

                this.callInfo.FriendCallState = e.State;

                if (this.callInfo.AudioBitrate <= 0)
                {
                    var  audioBitrateError = ToxAvErrorSetBitrate.Ok;
                    bool audioBitrateSet   = this.toxAv.SetAudioBitrate(e.FriendNumber, DefaultAudioBitrate, out audioBitrateError);
                    if (!audioBitrateSet)
                    {
                        Logger.Log(LogLevel.Error, string.Format("Could not set audio bitrate to {0}, error: {1}", DefaultAudioBitrate, audioBitrateError));
                    }
                    else
                    {
                        this.callInfo.AudioBitrate = DefaultAudioBitrate;
                    }
                }

                if (this.callInfo.VideoBitrate <= 0)
                {
                    var  videoBitrateError = ToxAvErrorSetBitrate.Ok;
                    bool videoBitrateSet   = this.toxAv.SetVideoBitrate(e.FriendNumber, DefaultVideoBitrate, out videoBitrateError);
                    if (!videoBitrateSet)
                    {
                        Logger.Log(LogLevel.Error, string.Format("Could not set video bitrate to {0}, error: {1}", DefaultVideoBitrate, videoBitrateError));
                    }
                    else
                    {
                        this.callInfo.VideoBitrate = DefaultVideoBitrate;
                    }
                }

                // start sending whatever from here
                if (!this.callInfo.RecordingDevice.IsRecording)
                {
                    this.callInfo.RecordingDevice.StartRecording();
                }

                if (!this.callInfo.VideoDevice.IsRecording)
                {
                    this.callInfo.VideoDevice.StartRecording();
                }

                if ((e.State & ToxAvFriendCallState.SendingVideo) != 0)
                {
                    friendCallState |= CallState.IncomingVideo;
                }

                friendCallState |= CallState.OutgoingVideo;

                // stop ringing
                this.StopRingingSound();
            }

            try
            {
                MainForm.Instance.NotifyToxAvCallStateChanged(new CallStateInfo(e.FriendNumber, friendCallState));
            }
            catch (Exception ex)
            {
                Logger.Log(LogLevel.Error, ex.Message);
            }
        }