summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/pjsua/winrt/gui/uwp/Voip/MainPage.xaml.cs
blob: a3d476e00f2e3da6d5bc9185f72cbdb3f1187d0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using VoipUI.Helpers;
using VoipTasks.BackgroundOperations;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Diagnostics;
using VoipBackEnd;
using System.Threading;
using Windows.ApplicationModel.AppService;
using Windows.UI.Xaml.Navigation;

namespace VoipUI
{
    public sealed partial class MainPage : Page
    {
        //App developer should include the logic to prevent the user from being
        //able to call the Start Call async method multiple times. This is out
        //of the scope of this sample.
        private int MethodCallUnexpectedTime = -2147483634;

        public static string callerName, callerNumber;
        public static MainPage Current;        

        public MainPage()
        {
            this.InitializeComponent();
            Current = this;
        }

        private async void GetAccountInfoAsync()
        {
            try
            {
                OperationResult result = await EndpointHelper.GetAccountInfo();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        private async void ModifyAccountAsync()
        {
            try
            {
                OperationResult result = await EndpointHelper.ModifyAccount(
                                           txt_UserId.Text, 
                                           txt_Registrar.Text, 
                                           txt_Proxy.Text, 
                                           txt_RegUserName.Text, 
                                           txt_Password.Text);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        private async void NewOutgoingCallAsync()
        {
            try
            {
                OperationResult result = await VoipCallHelper.NewOutgoingCallAsync(txt_CallerNumber.Text);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        private void EndCall()
        {
            try
            {
                OperationResult result = VoipCallHelper.EndCallAsync();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            txt_CallStatus.Text = "Disconnected";
        }

        public void UpdateAccountInfo(String id, String registrar, String proxy,
                                      String username, String password)
        {
            txt_UserId.Text = id;
            txt_Registrar.Text = registrar;
            txt_Proxy.Text = proxy;
            txt_RegUserName.Text = username;
            txt_Password.Text = password;
        }

        private void btn_NewOutgoingCall_Click(object sender, RoutedEventArgs e)
        {
            NewOutgoingCallAsync();
        }


        private void btn_EndCall_Click(object sender, RoutedEventArgs e)
        {
            EndCall();
        }

        public void UpdateCallState(String state)
        {
            txt_CallStatus.Text = state;            
        }

        public void UpdateRegState(String state)
        {
            txt_RegState.Text = "Reg:" + state;
        }

        private void btn_GetAccountInfo_Click(object sender, RoutedEventArgs e)
        {
            GetAccountInfoAsync();
        }

        private void btn_ModifyAccount_Click(object sender, RoutedEventArgs e)
        {
            ModifyAccountAsync();
        }
    }
}