MainPage.xaml.cs 3.36 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
MainPage.xaml.cs
Copyright (C) 2015  Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
15 16 17
*/

using Windows.UI.Xaml.Controls;
18
using BelledonneCommunications.Linphone.Native;
19
using Linphone.Model;
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace Linphone
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
        }
35 36 37 38

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
Ghislain MARY's avatar
Ghislain MARY committed
39
            Core.LogLevel = OutputTraceLevel.Message;
40
            LinphoneManager.Instance.Dispatcher = Dispatcher;
41
            LinphoneManager.Instance.Core.IsIterateEnabled = true;
42 43 44 45
        }

        private void CallButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
Ghislain MARY's avatar
Ghislain MARY committed
46 47
            Core core = LinphoneManager.Instance.Core;
            if (core.CallsNb == 0)
48
            {
Ghislain MARY's avatar
Ghislain MARY committed
49 50
                string contact = ContactTextBox.Text;
                if (contact.Length > 0)
51
                {
52
                    Address address = core.InterpretURL(contact);
Ghislain MARY's avatar
Ghislain MARY committed
53 54 55 56
                    if (address != null)
                    {
                        core.InviteAddress(address);
                    }
57
                }
Ghislain MARY's avatar
Ghislain MARY committed
58 59 60 61
            }
            else
            {
                foreach (Call c in core.Calls)
62
                {
Ghislain MARY's avatar
Ghislain MARY committed
63
                    core.TerminateCall(c);
64 65 66 67 68 69 70 71 72 73 74 75 76 77
                }
            }
        }

        private void RegisterButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            if ((UsernameTextBox.Text.Length > 0) && (ServerTextBox.Text.Length > 0))
            {
                Core core = LinphoneManager.Instance.Core;
                ProxyConfig proxy = core.CreateProxyConfig();
                AuthInfo authInfo = core.CreateAuthInfo(UsernameTextBox.Text, "", PasswordBox.Password, "", "", "");
                core.AddAuthInfo(authInfo);
                proxy.Identity = string.Format("sip:{0}@{1}", UsernameTextBox.Text, ServerTextBox.Text);
                proxy.ServerAddr = ServerTextBox.Text;
Ghislain MARY's avatar
Ghislain MARY committed
78 79 80 81
                Address addr = core.CreateAddress(proxy.ServerAddr);
                addr.Transport = Transport.TCP;
                proxy.ServerAddr = addr.AsString();
                proxy.Route = addr.AsString();
82
                proxy.IsRegisterEnabled = true;
83 84
                core.AddProxyConfig(proxy);
                core.DefaultProxyConfig = proxy;
Ghislain MARY's avatar
Ghislain MARY committed
85
                core.VideoPolicy = new VideoPolicy(false, false);
86 87
            }
        }
88 89
    }
}