Commit 3f93f6b5 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Added logs upload

parent 2c4b0652
This diff is collapsed.
using Linphone;
using System;
using System.Threading;
using System.Diagnostics;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#if ANDROID
using Android.Util;
using Android.Content;
#endif
[assembly: XamlCompilation (XamlCompilationOptions.Compile)]
......@@ -30,6 +32,8 @@ namespace Xamarin
#if ANDROID
// Giving app context in CreateCore is mandatory for Android to be able to load grammars (and other assets) from AAR
Core = Factory.Instance.CreateCore(listener, ConfigFilePath, null, IntPtr.Zero, LinphoneAndroid.AndroidContext);
// Required to be able to store logs as file
Core.SetLogCollectionPath(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData));
#else
Core = Factory.Instance.CreateCore(listener, ConfigFilePath, null);
#endif
......@@ -83,35 +87,57 @@ namespace Xamarin
break;
}
log += "] (" + domain + ") " + message;
Console.WriteLine(log);
#if WINDOWS_UWP
Debug.WriteLine(log);
#endif
}
private void OnGlobal(Core lc, GlobalState gstate, string message)
{
#if WINDOWS_UWP
Debug.WriteLine("Global state changed: " + gstate);
#else
Console.WriteLine("Global state changed: " + gstate);
#endif
}
#if WINDOWS_UWP
private void LinphoneCoreIterate(ThreadPoolTimer timer) {
#else
private void LinphoneCoreIterate()
{
#endif
while (true)
{
#if WINDOWS_UWP
CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High,
() => {
LinphoneCore.Iterate();
});
#else
Device.BeginInvokeOnMainThread(() =>
{
Core.Iterate();
});
Thread.Sleep(50);
#endif
}
}
protected override void OnStart ()
{
// Handle when your app starts
#if WINDOWS_UWP
TimeSpan period = TimeSpan.FromSeconds(1);
ThreadPoolTimer PeriodicTimer = ThreadPoolTimer.CreatePeriodicTimer(LinphoneCoreIterate , period);
#else
Thread iterate = new Thread(LinphoneCoreIterate);
iterate.IsBackground = false;
iterate.Start();
#endif
}
protected override void OnSleep ()
protected override void OnSleep ()
{
// Handle when your app sleeps
}
......
......@@ -21,6 +21,10 @@
<Label x:Name="call_stats" HorizontalOptions="Center" />
<Button x:Name="video" Text="Start Video" Clicked="OnVideoClicked" HorizontalOptions="Center" />
<StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Button x:Name="logs" Text="Upload Logs" Clicked="onUploadLogsCliked" HorizontalOptions="Center" />
<Label x:Name="logsUrl" Text="" HorizontalOptions="Center" />
</StackLayout>
</StackLayout>
</ContentPage>
......@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using Xamarin.Forms;
namespace Xamarin
......@@ -21,7 +22,11 @@ namespace Xamarin
private void OnRegistration(Core lc, ProxyConfig config, RegistrationState state, string message)
{
#if WINDOWS_UWP
Debug.WriteLine("Registration state changed: " + state);
#else
Console.WriteLine("Registration state changed: " + state);
#endif
registration_status.Text = "Registration state changed: " + state;
......@@ -34,7 +39,11 @@ namespace Xamarin
private void OnCall(Core lc, Call lcall, CallState state, string message)
{
#if WINDOWS_UWP
Debug.WriteLine("Call state changed: " + state);
#else
Console.WriteLine("Call state changed: " + state);
#endif
call_status.Text = "Call state changed: " + state;
......@@ -66,11 +75,30 @@ namespace Xamarin
private void OnStats(Core lc, Call call, CallStats stats)
{
#if WINDOWS_UWP
Debug.WriteLine("Call stats: " + stats.DownloadBandwidth + " kbits/s / " + stats.UploadBandwidth + " kbits/s");
#else
Console.WriteLine("Call stats: " + stats.DownloadBandwidth + " kbits/s / " + stats.UploadBandwidth + " kbits/s");
#endif
call_stats.Text = "Call stats: " + stats.DownloadBandwidth + " kbits/s / " + stats.UploadBandwidth + " kbits/s";
}
private void OnLogCollectionUpload(Core lc, CoreLogCollectionUploadState state, string info)
{
#if WINDOWS_UWP
Debug.WriteLine("Logs upload state changed: " + state + ", url is " + info);
#else
Console.WriteLine("Logs upload state changed: " + state + ", url is " + info);
#endif
logsUrl.Text = info;
var tapGestureRecognizer = new TapGestureRecognizer();
tapGestureRecognizer.Tapped += (s, e) => {
Device.OpenUri(new Uri(((Label)s).Text));
};
logsUrl.GestureRecognizers.Add(tapGestureRecognizer);
}
public MainPage()
{
InitializeComponent();
......@@ -81,6 +109,7 @@ namespace Xamarin
Listener.OnRegistrationStateChanged = OnRegistration;
Listener.OnCallStateChanged = OnCall;
Listener.OnCallStatsUpdated = OnStats;
Listener.OnLogCollectionUploadStateChanged = OnLogCollectionUpload;
Core.AddListener(Listener);
}
......@@ -141,5 +170,11 @@ namespace Xamarin
}
}
}
private void onUploadLogsCliked(object sender, EventArgs e)
{
Core.LogCollectionUploadServerUrl = "https://www.linphone.org:444/lft.php";
Core.UploadLogCollection();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment