BackgroundManager.cs 2.75 KB
Newer Older
Sylvain Berfini's avatar
Sylvain Berfini committed
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
using Microsoft.Phone.Networking.Voip;
using Linphone.Core;
using Linphone.Core.OutOfProcess;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Windows.Phone.Networking.Voip;
using System.Windows.Media.Imaging;
using Windows.Phone.Media.Devices;
using System.Reflection;
using Microsoft.Phone.Net.NetworkInformation;
using Windows.Storage;
using Linphone.Agents;

namespace Linphone.Agents
{
    public class BackgroundManager
    {
        private static BackgroundManager singleton;
        /// <summary>
        /// Static instance of the class.
        /// </summary>
        public static BackgroundManager Instance
        {
            get
            {
                if (BackgroundManager.singleton == null)
                    BackgroundManager.singleton = new BackgroundManager();

                return BackgroundManager.singleton;
            }
        }

41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
        private Server oopServer;
        /// <summary>
        /// A proxy to the server object in the background agent host process 
        /// </summary>
        public Server OopServer
        {
            get {
               if (oopServer == null)
                    oopServer = (Server)WindowsRuntimeMarshal.GetActivationFactory(typeof(Server)).ActivateInstance();
               return oopServer;
            }

            set {
                oopServer = value;
            }
        }
Sylvain Berfini's avatar
Sylvain Berfini committed
57 58 59 60 61 62 63

        /// <summary>
        /// Creates a new LinphoneCore (if not created yet) using a LinphoneCoreFactory.
        /// </summary>
        public void InitLinphoneCore()
        {
            // Initiate incoming call processing by creating the Linphone Core
64
            LpConfig config = OopServer.LinphoneCoreFactory.CreateLpConfig(ApplicationData.Current.LocalFolder.Path + "\\linphonerc", "Assets/linphonerc-factory");
65
            OopServer.LinphoneCoreFactory.CreateLinphoneCore(null, config);
Sylvain Berfini's avatar
Sylvain Berfini committed
66
            OopServer.LinphoneCore.SetRootCA("Assets/rootca.pem");
67
            OopServer.LinphoneCore.SetChatDatabasePath(ApplicationData.Current.LocalFolder.Path + "\\chat.db");
Sylvain Berfini's avatar
Sylvain Berfini committed
68
            OopServer.LinphoneCore.SetUserAgent("LinphoneWP8PushNotification", "");
Sylvain Berfini's avatar
Sylvain Berfini committed
69 70 71 72 73

            //Globals.Instance.BackgroundModeLogger.Configure(true, OutputTraceDest.TCPRemote, "192.168.0.217:38954");
            //Globals.Instance.LinphoneCoreFactory.OutputTraceListener = Globals.Instance.BackgroundModeLogger;

            OopServer.LinphoneCore.SetNetworkReachable(true);
74
            OopServer.LinphoneCore.IterateEnabled = true;
Sylvain Berfini's avatar
Sylvain Berfini committed
75 76 77
        }
    }
}