Commit 12fde540 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Few changes/fixes + button in settings to fake incoming call

parent dd215e31
......@@ -9,12 +9,13 @@ namespace Linphone.Agents
{
public LinphoneCallInProgressAgent() : base()
{
Globals.Instance.StartServer(RegistrationHelper.OutOfProcServerClassNames);
}
protected override void OnFirstCallStarting()
{
Debug.WriteLine("[LinphoneCallInProgressAgent] The first call has started.");
Debug.WriteLine("[LinphoneCallInProgressAgent] The first call has started.");
Globals.Instance.StartServer(RegistrationHelper.OutOfProcServerClassNames);
}
protected override void OnCancel()
......
......@@ -36,15 +36,11 @@ namespace Linphone.Agents
String callerName = "", callerNumber = "";
Debug.WriteLine("[{0}] Incoming call from caller {1}, number {2}", "KeepAliveAgent", callerName, callerNumber);
// Initiate incoming call processing
// If you want to pass in additional information such as pushNotification.Number, you can
bool incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(callerName, callerNumber, this.OnIncomingCallDialogDismissed);
bool incomingCallProcessingStarted = BackEnd.Globals.Instance.CallController.OnIncomingCallReceived(callerName, "+33609668573", this.OnIncomingCallViewDismissed);
if (!incomingCallProcessingStarted)
{
// For some reasons, the incoming call processing was not started.
base.NotifyComplete();
return;
}
}
else
......@@ -64,7 +60,7 @@ namespace Linphone.Agents
}
}
private void OnIncomingCallDialogDismissed()
private void OnIncomingCallViewDismissed()
{
Debug.WriteLine("[IncomingCallAgent] Incoming call processing is now complete.");
......
......@@ -6,7 +6,7 @@ using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Phone::Networking::Voip;
bool CallController::OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallDialogDismissedCallback^ incomingCallDialogDismissedCallback)
bool CallController::OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
......@@ -16,44 +16,65 @@ bool CallController::OnIncomingCallReceived(Platform::String^ contactName, Platf
TimeSpan ringingTimeout;
ringingTimeout.Duration = 90 * 10 * 1000 * 1000; // in 100ns units
::OutputDebugString(L"[CallController::OnIncomingCallReceived] => Will time out in 90 seconds\n");
this->onIncomingCallViewDismissed = incomingCallViewDismissedCallback;
// Ask the Phone Service to start a new incoming call
this->callCoordinator->RequestNewIncomingCall(
this->callInProgressPageUri,
this->callCoordinator->RequestNewIncomingCall(
this->callInProgressPageUri + "?sip=" + contactNumber,
contactName,
contactNumber,
this->defaultContactImageUri,
this->voipServiceName,
this->linphoneImageUri,
"",
this->ringtoneUri,
this->ringtoneUri,
VoipCallMedia::Audio,
ringingTimeout,
&incomingCall);
&incomingCall);
}
catch(...)
{
return false;
}
// Register for events about this incoming call.
incomingCall->AnswerRequested += this->acceptCallRequestedHandler;
incomingCall->RejectRequested += this->rejectCallRequestedHandler;
return true;
}
void CallController::OnAcceptCallRequested(VoipPhoneCall^ sender, CallAnswerEventArgs^ args)
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
incomingCall->NotifyCallActive();
this->currentCall = incomingCall;
if (this->onIncomingCallViewDismissed != nullptr)
this->onIncomingCallViewDismissed();
}
void CallController::OnRejectCallRequested(VoipPhoneCall^ sender, CallRejectEventArgs^ args)
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
incomingCall->NotifyCallEnded();
if (this->onIncomingCallViewDismissed != nullptr)
this->onIncomingCallViewDismissed();
}
void CallController::EndCurrentCall()
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
if (this->currentCall == nullptr)
return;
this->currentCall->NotifyCallEnded();
this->currentCall = nullptr;
}
CallController::CallController() :
callInProgressPageUri(L"/Views/InCall.xaml"),
voipServiceName(nullptr),
......@@ -67,8 +88,8 @@ CallController::CallController() :
String^ installFolder = String::Concat(Windows::ApplicationModel::Package::Current->InstalledLocation->Path, "\\");
this->defaultContactImageUri = ref new Uri(installFolder, "Assets\\unknown.png");
this->voipServiceName = ref new String(L"Linphone");
this->linphoneImageUri = ref new Uri(installFolder, "Assets\\AppIcon.png");
this->ringtoneUri = ref new Uri(installFolder, "Assets\\Sounds\\Ringtone.wma");
this->linphoneImageUri = ref new Uri(installFolder, "Assets\\pnicon.png");
this->ringtoneUri = ref new Uri(installFolder, "Assets\\Sounds\\Ringtone.wma");
this->acceptCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallAnswerEventArgs^>(this, &CallController::OnAcceptCallRequested);
this->rejectCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallRejectEventArgs^>(this, &CallController::OnRejectCallRequested);
......
......@@ -11,7 +11,7 @@ namespace Linphone
// A method that is called back when the incoming call dialog has been dismissed.
// This callback is used to complete the incoming call agent.
public delegate void IncomingCallDialogDismissedCallback();
public delegate void IncomingCallViewDismissedCallback();
// A class that provides methods and properties related to VoIP calls.
// It wraps Windows.Phone.Networking.Voip.VoipCallCoordinator, and provides app-specific call functionality.
......@@ -20,8 +20,9 @@ namespace Linphone
public:
// Start processing an incoming call. Called by managed code in this process (the VoIP agent host process).
// Returns true if the incoming call processing was started, false otherwise.
bool OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallDialogDismissedCallback^ incomingCallDialogDismissedCallback);
bool OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback);
void EndCurrentCall();
private:
friend ref class Linphone::BackEnd::Globals;
......@@ -36,11 +37,14 @@ namespace Linphone
// The URI to the linphone icon, 128kb max !
Windows::Foundation::Uri^ linphoneImageUri;
// The URI to the ringtone file, mp3 or wma, 1mb max !
Windows::Foundation::Uri^ ringtoneUri;
Windows::Phone::Networking::Voip::VoipCallCoordinator^ callCoordinator;
IncomingCallViewDismissedCallback^ onIncomingCallViewDismissed;
Windows::Phone::Networking::Voip::VoipPhoneCall^ currentCall;
// Called by the VoipCallCoordinator when the user accepts an incoming call.
void OnAcceptCallRequested(Windows::Phone::Networking::Voip::VoipPhoneCall^ sender, Windows::Phone::Networking::Voip::CallAnswerEventArgs^ args);
......
......@@ -8,6 +8,7 @@
#include "OnlineStatus.h"
#include "PayloadType.h"
#include "Server.h"
#include "CallController.h"
using namespace Linphone::BackEnd;
using namespace Platform;
......@@ -112,7 +113,7 @@ LinphoneCall^ LinphoneCore::InviteAddressWithParams(LinphoneAddress^ destination
void LinphoneCore::TerminateCall(LinphoneCall^ call)
{
Globals::Instance->CallController->EndCurrentCall();
}
LinphoneCall^ LinphoneCore::GetCurrentCall()
......
......@@ -21,14 +21,6 @@ namespace Linphone
{
}
property CallController^ CallController
{
Linphone::BackEnd::CallController^ get()
{
return Globals::Instance->CallController;
};
}
property LinphoneCoreFactory^ LinphoneCoreFactory
{
Linphone::BackEnd::LinphoneCoreFactory^ get()
......
No preview for this file type
......@@ -220,6 +220,7 @@
<Content Include="Assets\call_status_missed.png" />
<Content Include="Assets\call_status_outgoing.png" />
<Content Include="Assets\dialer_address_background.png" />
<Content Include="Assets\pnicon.png" />
<Content Include="Assets\Numpad\numpad_eight_default.png" />
<Content Include="Assets\Numpad\numpad_eight_over.png" />
<Content Include="Assets\Numpad\numpad_five_default.png" />
......
......@@ -36,7 +36,7 @@ namespace Linphone.Model
}
}
private List<CallLogs> _history;
#region Background Process
private bool BackgroundProcessConnected;
// An event that indicates that the UI process is no longer connected to the background process
......@@ -132,9 +132,10 @@ namespace Linphone.Model
uiDisconnectedEvent.Dispose();
uiDisconnectedEvent = null;
}
#endregion
/// <summary>
/// Creates a new LinphoneCore using a LinphoneCoreFactory
/// Creates a new LinphoneCore (if not created yet) using a LinphoneCoreFactory
/// </summary>
public void InitLinphoneCore()
{
......@@ -153,6 +154,9 @@ namespace Linphone.Model
server.LinphoneCoreFactory.SetDebugMode(enable, AppResources.ApplicationTitle);
}
#region CallLogs
private List<CallLogs> _history;
/// <summary>
/// Get the calls' history
/// </summary>
......@@ -238,7 +242,7 @@ namespace Linphone.Model
if (LinphoneCore.GetCallsNb() > 0)
{
LinphoneCall call = LinphoneCore.GetCalls().First();
LinphoneCore.TerminateCall(call);
LinphoneCore.TerminateCall(null);
}
}
......@@ -262,6 +266,7 @@ namespace Linphone.Model
LinphoneCore.ResumeCall(call);
}
}
#endregion
#region LinphoneCoreListener Callbacks
public void GlobalState(GlobalState state, string message)
......
......@@ -47,7 +47,7 @@
<ActivatableClasses>
<InProcessServer>
<Path>Linphone.BackEnd.DLL</Path>
<ActivatableClass ActivatableClassId="Linphone.BackEnd.IncomingCallDialogDismissedCallback" ThreadingModel="MTA" />
<ActivatableClass ActivatableClassId="Linphone.BackEnd.IncomingCallViewDismissedCallback" ThreadingModel="MTA" />
<ActivatableClass ActivatableClassId="Linphone.BackEnd.CallController" ThreadingModel="MTA" />
<ActivatableClass ActivatableClassId="Linphone.BackEnd.Globals" ThreadingModel="MTA" />
<ActivatableClass ActivatableClassId="Linphone.BackEnd.Transports" ThreadingModel="MTA" />
......
......@@ -32,6 +32,7 @@ namespace Linphone
protected override void OnNavigatedTo(NavigationEventArgs e)
{
LinphoneManager.Instance.EnableDebug(SettingsManager.isDebugEnabled);
// Create LinphoneCore if not created yet, otherwise do nothing
LinphoneManager.Instance.InitLinphoneCore();
// Check for the navigation direction to avoid going to incall view when coming back from incall view
......
......@@ -24,6 +24,10 @@ namespace Linphone.Views
protected override void OnNavigatedTo(NavigationEventArgs e)
{
LinphoneManager.Instance.EnableDebug(SettingsManager.isDebugEnabled);
// Create LinphoneCore if not created yet, otherwise do nothing
LinphoneManager.Instance.InitLinphoneCore();
if (NavigationContext.QueryString.ContainsKey("sip"))
{
String calledNumber = NavigationContext.QueryString["sip"];
......@@ -56,7 +60,9 @@ namespace Linphone.Views
private void hangUp_Click(object sender, RoutedEventArgs e)
{
LinphoneManager.Instance.EndCurrentCall();
NavigationService.GoBack();
if (NavigationService.CanGoBack)
NavigationService.GoBack();
}
private void speaker_Click_1(object sender, RoutedEventArgs e)
......
......@@ -36,6 +36,7 @@
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<toolkit:ToggleSwitch
......@@ -71,6 +72,13 @@
x:Name="LockScreenSettings"
Margin="0,30,0,0"
Content="{Binding Path=LocalizedResources.LockScreenSettings, Source={StaticResource LocalizedStrings}}" />
<Button
Grid.Row="5"
Click="Simulate_Click_1"
x:Name="Simulate"
Margin="0,30,0,0"
Content="Simulate incoming call" />
</Grid>
</ScrollViewer>
</Grid>
......
......@@ -11,6 +11,8 @@ using Linphone.Model;
using Linphone.Resources;
using System.Globalization;
using System.Resources;
using System.IO;
using System.Text;
namespace Linphone.Views
{
......@@ -71,5 +73,62 @@ namespace Linphone.Views
{
var op = await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-lock:"));
}
private void Simulate_Click_1(object sender, RoutedEventArgs e)
{
try
{
// Create an HTTPWebRequest that posts the raw notification to the Microsoft Push Notification Service.
// HTTP POST is the only method allowed to send the notification.
HttpWebRequest sendNotificationRequest = (HttpWebRequest)WebRequest.Create(((App)App.Current).PushChannelUri);
sendNotificationRequest.Method = "POST";
// Create the raw message.
string rawMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<root>" +
"<Value1>" + "Sylvain Berfini" + "<Value1>" +
"<Value2>" + "+33952636505" + "<Value2>" +
"</root>";
byte[] notificationMessage = Encoding.UTF8.GetBytes(rawMessage);
// Set the required web request headers
sendNotificationRequest.ContentLength = notificationMessage.Length;
sendNotificationRequest.ContentType = "text/xml";
sendNotificationRequest.Headers["X-NotificationClass"] = "4";
// Write the request body
sendNotificationRequest.BeginGetRequestStream((IAsyncResult arRequest) =>
{
try
{
using (Stream requestStream = sendNotificationRequest.EndGetRequestStream(arRequest))
{
requestStream.Write(notificationMessage, 0, notificationMessage.Length);
}
// Get the response.
sendNotificationRequest.BeginGetResponse((IAsyncResult arResponse) =>
{
try
{
HttpWebResponse response = (HttpWebResponse)sendNotificationRequest.EndGetResponse(arResponse);
string notificationStatus = response.Headers["X-NotificationStatus"];
string subscriptionStatus = response.Headers["X-SubscriptionStatus"];
string deviceConnectionStatus = response.Headers["X-DeviceConnectionStatus"];
}
catch (Exception ex)
{
}
}, null);
}
catch (Exception ex)
{
}
}, null);
}
catch (Exception ex)
{
}
}
}
}
\ No newline at end of file
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