private async void CallStateChangedHandler(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            if (e.FriendNumber != _friendNumber)
                return;

            if (e.State.HasFlag(ToxAvFriendCallState.ReceivingAudio) ||
                e.State.HasFlag(ToxAvFriendCallState.SendingAudio))
            {
                await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () => { State = CallState.DuringCall; });
            }

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

            if (e.State.HasFlag(ToxAvFriendCallState.Finished) || e.State.HasFlag(ToxAvFriendCallState.Error))
            {
                StopAudioGraph();
                await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                    () => { State = CallState.Default; });
            }
        }
Exemple #2
0
        private void toxav_OnInvite(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            //TODO: notify the user of another incoming call
            if (call != null)
                return;

            Dispatcher.BeginInvoke(((Action)(() =>
            {
                var friend = ViewModel.GetFriendObjectByNumber(toxav.GetPeerID(e.CallIndex, 0));
                if (friend != null)
                {
                    friend.CallIndex = e.CallIndex;
                    friend.IsCalling = true;
                }
            })));
        }
Exemple #3
0
        private void toxav_OnStart(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            var settings = toxav.GetPeerCodecSettings(e.CallIndex, 0);

            if (call != null)
                call.Start(config.InputDevice, config.OutputDevice, settings, config.VideoDevice);

            Dispatcher.BeginInvoke(((Action)(() =>
            {
                if (settings.CallType == ToxAvCallType.Video)
                {
                    VideoImageRow.Height = new GridLength(300);
                    VideoGridSplitter.IsEnabled = true;
                }

                int friendnumber = toxav.GetPeerID(e.CallIndex, 0);
                var callingFriend = ViewModel.GetFriendObjectByNumber(friendnumber);
                if (callingFriend != null)
                {
                    callingFriend.IsCalling = false;
                    callingFriend.IsCallingToFriend = false;
                    CallButton.Visibility = Visibility.Collapsed;
                    if (callingFriend.Selected)
                    {
                        HangupButton.Visibility = Visibility.Visible;
                        VideoButton.Visibility = Visibility.Visible;
                    }
                    ViewModel.CallingFriend = callingFriend;
                }
            })));

            call.SetTimerCallback(timerCallback);
        }
Exemple #4
0
        private void toxav_OnEnd(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            Dispatcher.BeginInvoke(((Action)(() =>
            {
                EndCall();

                CallButton.Visibility = Visibility.Visible;
                HangupButton.Visibility = Visibility.Collapsed;
                VideoButton.Visibility = Visibility.Collapsed;
                VideoButton.IsChecked = false;
            })));
        }
Exemple #5
0
        private void toxav_OnReceivedAudio(object sender, ToxAvEventArgs.AudioDataEventArgs e)
        {
            if (call == null)
                return;

            call.ProcessAudioFrame(e.Data);
        }
Exemple #6
0
        private void toxav_OnReceivedGroupAudio(object sender, ToxAvEventArgs.GroupAudioDataEventArgs e)
        {
            var group = Dispatcher.Invoke(() => ViewModel.GetGroupObjectByNumber(e.GroupNumber));
            if (group == null)
                return;

            var peer = group.PeerList.GetPeerByPublicKey(tox.GetGroupPeerPublicKey(e.GroupNumber, e.PeerNumber));
            if (peer == null || peer.Ignored || peer.Muted)
                return;

            if (call != null && call.GetType() == typeof(ToxGroupCall))
                ((ToxGroupCall)call).ProcessAudioFrame(e.Data, e.Channels);
        }
Exemple #7
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);
        }
 private async void CallRequestReceivedHandler(object sender, ToxAvEventArgs.CallRequestEventArgs e)
 {
     await _dispatcher.RunAsync(CoreDispatcherPriority.Normal,
         () => { State = CallState.IncomingCall; });
 }
Exemple #9
0
 private void VideoFrameReceivedHandler(object sender, ToxAvEventArgs.VideoFrameEventArgs e)
 {
     if (VideoFrameReceived != null)
         VideoFrameReceived(this, e);
 }
Exemple #10
0
 private void AudioFrameReceivedHandler(object sender, ToxAvEventArgs.AudioFrameEventArgs e)
 {
     if (AudioFrameReceived != null)
         AudioFrameReceived(this, e);
 }
Exemple #11
0
 private void VideoBitrateChangedHandler(object sender, ToxAvEventArgs.BitrateStatusEventArgs e)
 {
     if (VideoBitrateChanged != null)
         VideoBitrateChanged(this, e);
 }
Exemple #12
0
 private void CallStateChangedHandler(object sender, ToxAvEventArgs.CallStateEventArgs e)
 {
     if (CallStateChanged != null)
         CallStateChanged(this, e);
 }
Exemple #13
0
 private void CallRequestReceivedHandler(object sender, ToxAvEventArgs.CallRequestEventArgs e)
 {
     if (CallRequestReceived != null)
         CallRequestReceived(this, e);
 }
Exemple #14
0
 private void VideoFrameReceivedHandler(object sender, ToxAvEventArgs.VideoFrameEventArgs e)
 {
     VideoFrameReceived?.Invoke(this, e);
 }
Exemple #15
0
 private void VideoBitrateChangedHandler(object sender, ToxAvEventArgs.BitrateStatusEventArgs e)
 {
     VideoBitrateChanged?.Invoke(this, e);
 }
        private void AudioFrameReceivedHandler(object sender, ToxAvEventArgs.AudioFrameEventArgs e)
        {
            if (e.FriendNumber != _friendNumber)
                return;

            _receiveBuffer.Post(e.Frame.Data);
        }
Exemple #17
0
        private void toxav_OnReceivedVideo(object sender, ToxAvEventArgs.VideoDataEventArgs e)
        {
            if (Dispatcher.Invoke(() => (call == null || call.GetType() == typeof(ToxGroupCall) || call.Ended || ViewModel.IsGroupSelected || call.FriendNumber != ViewModel.SelectedChatNumber)))
                return;

            ProcessVideoFrame(e.Frame);
        }
Exemple #18
0
        private void toxav_OnPeerCodecSettingsChanged(object sender, ToxAvEventArgs.CallStateEventArgs e)
        {
            Dispatcher.BeginInvoke(((Action)(() =>
            {
                if (call == null || call.GetType() == typeof(ToxGroupCall) || e.CallIndex != call.CallIndex)
                    return;

                if (toxav.GetPeerCodecSettings(e.CallIndex, 0).CallType != ToxAvCallType.Video)
                {
                    VideoImageRow.Height = new GridLength(0);
                    VideoGridSplitter.IsEnabled = false;
                    VideoChatImage.Source = null;
                }
                else if (ViewModel.IsFriendSelected && toxav.GetPeerID(e.CallIndex, 0) == ViewModel.SelectedChatNumber)
                {
                    VideoImageRow.Height = new GridLength(300);
                    VideoGridSplitter.IsEnabled = true;
                }
            })));
        }
        private void AudioFrameReceivedHandler(object sender, ToxAvEventArgs.AudioFrameEventArgs e)
        {
            if (_player == null || _waveProvider == null)
                return;

            var bytes = new byte[e.Frame.Data.Length*2];
            Buffer.BlockCopy(e.Frame.Data, 0, bytes, 0, e.Frame.Data.Length);

            _waveProvider.AddSamples(bytes, 0, bytes.Length);
        }
Exemple #20
0
        private void CallRequestReceivedHandler(object sender, ToxAvEventArgs.CallRequestEventArgs e)
        {
            // Automatically decline call request if we have an ongoing call.
            // TODO: Instead of this, tell the user about the situation and let him/her decide if he/she want to hang up the current call and answer the new one!
            if (_friendInCall != -1)
            {
                _toxAv.SendControl(e.FriendNumber, ToxAvCallControl.Cancel);
                return;
            }

            _friendInCall = e.FriendNumber;

            CallRequestReceived?.Invoke(this, e);
        }