Commit d9c7b859 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Stubs a bit improved to simulate real library for incoming/outgoing call

parent d94cfea3
......@@ -43,13 +43,10 @@ namespace Linphone.Agents
callerNumber = incomingCallPN.First().ToString();
Debug.WriteLine("[{0}] Incoming call from caller {1}, number {2}", "KeepAliveAgent", callerName, callerNumber);
LinphoneCall call = new LinphoneCall(callerName, callerNumber);
Globals.Instance.LinphoneCore.IncomingCall = call;
bool incomingCallProcessingStarted = Globals.Instance.CallController.OnIncomingCallReceived(callerName, callerNumber, this.OnIncomingCallViewDismissed);
if (!incomingCallProcessingStarted)
{
base.NotifyComplete();
}
base.NotifyComplete();
}
else
{
......@@ -68,16 +65,6 @@ namespace Linphone.Agents
}
}
/// <summary>
/// Called when the incoming call view is dismissed, either by accepting or denying the call
/// </summary>
private void OnIncomingCallViewDismissed()
{
Debug.WriteLine("[IncomingCallAgent] Incoming call processing is now complete.");
base.NotifyComplete();
}
protected override void OnCancel()
{
Debug.WriteLine("[{0}] Cancel requested.", this.isIncomingCallAgent ? "IncomingCallAgent" : "KeepAliveAgent");
......
#include "CallController.h"
#include "Server.h"
using namespace Linphone::Core;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Phone::Networking::Voip;
void CallController::SetCallControllerListener(CallControllerListener^ listener)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
this->callControllerListener = listener;
}
bool CallController::OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
VoipPhoneCall^ incomingCall = nullptr;
this->callerNumber = contactNumber;
try
{
TimeSpan ringingTimeout;
ringingTimeout.Duration = 90 * 10 * 1000 * 1000; // in 100ns units
this->onIncomingCallViewDismissed = incomingCallViewDismissedCallback;
// Ask the Phone Service to start a new incoming call
this->callCoordinator->RequestNewIncomingCall(
this->callInProgressPageUri + "?sip=" + contactNumber,
contactName,
contactNumber,
this->defaultContactImageUri,
this->voipServiceName,
this->linphoneImageUri,
"",
this->ringtoneUri,
VoipCallMedia::Audio,
ringingTimeout,
&incomingCall);
}
catch(...)
{
return false;
}
incomingCall->AnswerRequested += this->acceptCallRequestedHandler;
incomingCall->RejectRequested += this->rejectCallRequestedHandler;
return true;
}
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
incomingCall->NotifyCallActive();
if (this->onIncomingCallViewDismissed != nullptr)
this->onIncomingCallViewDismissed();
if (this->callControllerListener != nullptr)
this->callControllerListener->NewCallStarted(this->callerNumber);
}
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
incomingCall->NotifyCallEnded();
if (this->onIncomingCallViewDismissed != nullptr)
this->onIncomingCallViewDismissed();
this->callerNumber = nullptr;
}
void CallController::EndCall(VoipPhoneCall^ call)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
call->NotifyCallEnded();
if (this->callControllerListener != nullptr)
this->callControllerListener->CallEnded();
}
VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number, Platform::String^ name)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
VoipPhoneCall^ outgoingCall = nullptr;
this->callCoordinator->RequestNewOutgoingCall(
this->callInProgressPageUri + "?sip=" + number,
name,
this->voipServiceName,
VoipCallMedia::Audio,
&outgoingCall);
outgoingCall->NotifyCallActive();
this->callerNumber = number;
if (this->callControllerListener != nullptr)
this->callControllerListener->NewCallStarted(number);
return outgoingCall;
}
CallController::CallController() :
callInProgressPageUri(L"/Views/InCall.xaml"),
voipServiceName(nullptr),
defaultContactImageUri(nullptr),
linphoneImageUri(nullptr),
ringtoneUri(nullptr),
callerNumber(nullptr),
callControllerListener(nullptr)
{
this->callCoordinator = VoipCallCoordinator::GetDefault();
// URIs required for interactions with the VoipCallCoordinator
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\\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);
}
CallController::~CallController()
{
}
#pragma once
#include <windows.phone.networking.voip.h>
#include "CallControllerListener.h"
#include "ApiLock.h"
namespace Linphone
{
namespace Core
{
ref class Globals;
public delegate void IncomingCallViewDismissedCallback();
/// <summary>
/// Provides methods and properties related to Windows.Phone.Networking.Voip.VoipPhoneCall calls.
/// </summary>
public ref class CallController sealed
{
public:
bool OnIncomingCallReceived(Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback);
void EndCall(Windows::Phone::Networking::Voip::VoipPhoneCall^ call);
Windows::Phone::Networking::Voip::VoipPhoneCall^ NewOutgoingCall(Platform::String^ number, Platform::String^ name);
void SetCallControllerListener(CallControllerListener^ listener);
private:
friend ref class Linphone::Core::Globals;
CallControllerListener^ callControllerListener;
Platform::String^ voipServiceName;
Platform::String^ callerNumber;
Platform::String^ callInProgressPageUri;
// The URI to the contact image, jpg or png, 1mb max !
Windows::Foundation::Uri^ defaultContactImageUri;
// The URI to the linphone icon, 128kb max !
Windows::Foundation::Uri^ linphoneImageUri;
Windows::Foundation::Uri^ ringtoneUri;
Windows::Phone::Networking::Voip::VoipCallCoordinator^ callCoordinator;
IncomingCallViewDismissedCallback^ onIncomingCallViewDismissed;
void OnAcceptCallRequested(Windows::Phone::Networking::Voip::VoipPhoneCall^ sender, Windows::Phone::Networking::Voip::CallAnswerEventArgs^ args);
void OnRejectCallRequested(Windows::Phone::Networking::Voip::VoipPhoneCall^ sender, Windows::Phone::Networking::Voip::CallRejectEventArgs^ args);
Windows::Foundation::TypedEventHandler<Windows::Phone::Networking::Voip::VoipPhoneCall^, Windows::Phone::Networking::Voip::CallAnswerEventArgs^>^ acceptCallRequestedHandler;
Windows::Foundation::TypedEventHandler<Windows::Phone::Networking::Voip::VoipPhoneCall^, Windows::Phone::Networking::Voip::CallRejectEventArgs^>^ rejectCallRequestedHandler;
CallController();
~CallController();
};
}
}
#pragma once
namespace Linphone
{
namespace Core
{
public interface class CallControllerListener
{
/// <summary>
/// Called when a call is started (incoming or outgoing), after the creation of the VoipPhoneCall.
/// </summary>
void NewCallStarted(Platform::String^ callerNumber);
/// <summary>
/// Called when a call is terminated, after the VoipPhoneCall->NotifyCallEnded();
/// </summary>
void CallEnded();
};
}
}
\ No newline at end of file
#pragma once
namespace Linphone
{
namespace Core
{
public enum class CallDirection : int
{
Outgoing,
Incoming
};
}
}
\ No newline at end of file
......@@ -125,9 +125,6 @@ popd</Command>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ApiLock.h" />
<ClInclude Include="CallController.h" />
<ClInclude Include="CallControllerListener.h" />
<ClInclude Include="CallDirection.h" />
<ClInclude Include="Globals.h" />
<ClInclude Include="LinphoneAddress.h" />
<ClInclude Include="LinphoneCall.h" />
......@@ -140,13 +137,12 @@ popd</Command>
<ClInclude Include="LinphoneCoreListener.h" />
<ClInclude Include="LinphoneProxyConfig.h" />
<ClInclude Include="LpConfig.h" />
<ClInclude Include="OnlineStatus.h" />
<ClInclude Include="Enums.h" />
<ClInclude Include="PayloadType.h" />
<ClInclude Include="Server.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="ApiLock.cpp" />
<ClCompile Include="CallController.cpp" />
<ClCompile Include="Globals.cpp" />
<ClCompile Include="LinphoneAddress.cpp" />
<ClCompile Include="LinphoneAuthInfo.cpp" />
......
#pragma once
namespace Linphone
{
namespace Core
{
public enum class OnlineStatus : int
{
Offline = 0,
Online = 1,
Busy = 2,
BeRightBack = 3,
Away = 4,
OnThePhone = 5,
OutToLunch = 6,
DoNotDisturb = 7,
StatusMoved = 8,
StatusAltService = 9,
Pending = 10
};
public enum class CallDirection : int
{
Outgoing,
Incoming
};
/// <summary>
/// Linphone core states
/// </summary>
public enum class GlobalState : int
{
GlobalOff = 0,
GlobalStartup = 1,
GlobalOn = 2,
GlobalShutdown = 3
};
/// <summary>
/// Proxy registration states
/// </summary>
public enum class RegistrationState : int
{
RegistrationNone = 0,
RegistrationInProgress = 1,
RegistrationOk = 2,
RegistrationCleared = 3,
RegistrationFailed = 4
};
public enum class MediaEncryption : int
{
None = 0,
SRTP = 1,
ZRTP = 2
};
public enum class FirewallPolicy : int
{
NoFirewall = 0,
UseNatAddress = 1,
UseStun = 2,
UseIce = 3
};
public enum class EcCalibratorStatus : int
{
InProgress = 0,
Done = 1,
Failed = 2,
DoneNoEcho = 3
};
/// <summary>
/// Linphone call states
/// </summary>
public enum class LinphoneCallState : int
{
Idle = 0,
IncomingReceived = 1,
OutgoingInit = 2,
OutgoingProgress = 3,
OutgoingRinging = 4,
OutgoingEarlyMedia = 5,
Connected = 6,
StreamsRunning = 7,
Pausing = 8,
Paused = 9,
Resuming = 10,
Refered = 11,
Error = 12,
CallEnd = 13,
PausedByRemote = 14,
UpdatedByRemote = 15,
IncomingEarlyMedia = 16,
Udating = 17,
Released = 18
};
}
}
\ No newline at end of file
......@@ -5,7 +5,6 @@
#include <crtdbg.h>
#include "Globals.h"
#include "ApiLock.h"
#include "CallController.h"
#include "LinphoneCoreFactory.h"
#include "LinphoneCore.h"
......@@ -125,22 +124,6 @@ Globals^ Globals::Instance::get()
return Globals::singleton;
}
CallController^ Globals::CallController::get()
{
if (this->callController == nullptr)
{
// Make sure only one API call is in progress at a time
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
if (this->callController == nullptr)
{
this->callController = ref new Linphone::Core::CallController();
}
}
return this->callController;
}
LinphoneCoreFactory^ Globals::LinphoneCoreFactory::get()
{
if (this->linphoneCoreFactory == nullptr)
......@@ -165,7 +148,6 @@ LinphoneCore^ Globals::LinphoneCore::get()
Globals::Globals() :
started(false),
serverRegistrationCookie(NULL),
callController(nullptr),
linphoneCoreFactory(nullptr),
noOtherBackgroundProcessEvent(NULL),
backgroundReadyEvent(NULL)
......@@ -203,9 +185,6 @@ Globals::Globals() :
HRESULT hr = HRESULT_FROM_WIN32(dwErr);
throw ref new Platform::COMException(hr, L"An error occurred trying to reset the event that indicates if the background process exists or not");
}
// Initialize the call controller
this->callController = ref new Linphone::Core::CallController();
}
Globals::~Globals()
......
......@@ -33,11 +33,6 @@ namespace Linphone
Globals^ get();
}
property CallController^ CallController
{
Linphone::Core::CallController^ get();
}
property LinphoneCoreFactory^ LinphoneCoreFactory
{
Linphone::Core::LinphoneCoreFactory^ get();
......@@ -69,8 +64,6 @@ namespace Linphone
HANDLE backgroundReadyEvent;
Linphone::Core::CallController^ callController;
Linphone::Core::LinphoneCoreFactory^ linphoneCoreFactory;
};
}
......
......@@ -50,15 +50,20 @@ void LinphoneAddress::Clean()
Platform::String^ LinphoneAddress::AsString()
{
return nullptr;
return this->address;
}
Platform::String^ LinphoneAddress::AsStringUriOnly()
{
return nullptr;
return this->address;
}
Platform::String^ LinphoneAddress::ToString()
{
return nullptr;
return this->address;
}
LinphoneAddress::LinphoneAddress(Platform::String^ address)
{
this->address = address;
}
\ No newline at end of file
......@@ -65,6 +65,11 @@ namespace Linphone
/// Same as AsString.
/// </summary>
Platform::String^ ToString();
LinphoneAddress(Platform::String^ address);
private:
Platform::String^ address;
};
}
}
\ No newline at end of file
#include "LinphoneCall.h"
#include "CallDirection.h"
#include "LinphoneAddress.h"
#include "LinphoneCallStats.h"
#include "LinphoneCallLog.h"
#include "LinphoneCallParams.h"
#include "Server.h"
#include "ApiLock.h"
using namespace Linphone::Core;
......@@ -15,7 +15,7 @@ LinphoneCallState LinphoneCall::GetState()
LinphoneAddress^ LinphoneCall::GetRemoteAddress()
{
return nullptr;
return ref new LinphoneAddress(this->number);
}
CallDirection LinphoneCall::GetDirection()
......@@ -110,15 +110,25 @@ Platform::String^ LinphoneCall::GetRemoteUserAgent()
Platform::String^ LinphoneCall::GetRemoteContact()
{
return nullptr;
return this->contact;
}
void LinphoneCall::CallContext::set(Platform::Object^ cc)
void LinphoneCall::CallContext::set(Windows::Phone::Networking::Voip::VoipPhoneCall^ cc)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
this->callContext = cc;
}
Platform::Object^ LinphoneCall::CallContext::get()
Windows::Phone::Networking::Voip::VoipPhoneCall^ LinphoneCall::CallContext::get()
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
return this->callContext;
}
LinphoneCall::LinphoneCall(Platform::String^ contact, Platform::String^ number) :
contact(contact),
number(number)
{
}
\ No newline at end of file
#pragma once
#include "CallDirection.h"
#include "Enums.h"
namespace Linphone
{
......@@ -10,32 +10,7 @@ namespace Linphone
ref class LinphoneCallLog;
ref class LinphoneCallStats;
ref class LinphoneCallParams;
/// <summary>
/// Linphone call states
/// </summary>
public enum class LinphoneCallState : int
{
Idle = 0,
IncomingReceived = 1,
OutgoingInit = 2,
OutgoingProgress = 3,
OutgoingRinging = 4,
OutgoingEarlyMedia = 5,
Connected = 6,
StreamsRunning = 7,
Pausing = 8,
Paused = 9,
Resuming = 10,
Refered = 11,
Error = 12,
CallEnd = 13,
PausedByRemote = 14,
UpdatedByRemote = 15,
IncomingEarlyMedia = 16,
Udating = 17,
Released = 18
};
ref class LinphoneCore;
/// <summary>
/// Object representing a call.
......@@ -113,14 +88,21 @@ namespace Linphone
Platform::String^ GetRemoteUserAgent();
Platform::String^ GetRemoteContact();
property Platform::Object^ CallContext
property Windows::Phone::Networking::Voip::VoipPhoneCall^ CallContext
{
Platform::Object^ get();
void set(Platform::Object^ cc);
Windows::Phone::Networking::Voip::VoipPhoneCall^ get();
void set(Windows::Phone::Networking::Voip::VoipPhoneCall^ cc);
}
LinphoneCall(Platform::String^ contact, Platform::String^ number);
private:
Platform::Object^ callContext;
friend ref class Linphone::Core::LinphoneCore;
Windows::Phone::Networking::Voip::VoipPhoneCall^ callContext;
Platform::String^ contact;
Platform::String^ number;
};
}
}
\ No newline at end of file
#include "LinphoneCallLog.h"
#include "LinphoneAddress.h"
#include "CallDirection.h"
#include "Enums.h"
#include "Server.h"
using namespace Linphone::Core;
......
#pragma once
#include "CallDirection.h"
#include "Enums.h"
namespace Linphone
{
......
......@@ -4,11 +4,12 @@
#include "LinphoneCall.h"
#include "LinphoneCallParams.h"
#include "LinphoneProxyConfig.h"
#include "LinphoneCoreListener.h"
#include "LpConfig.h"
#include "OnlineStatus.h"
#include "PayloadType.h"
#include "Server.h"
#include "CallController.h"
#include "ApiLock.h"
#include <collection.h>
using namespace Linphone::Core;
using namespace Platform;
......@@ -88,7 +89,14 @@ void LinphoneCore::AddAuthInfo(LinphoneAuthInfo^ info)
void LinphoneCore::Iterate()
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
if (this->incomingcall != nullptr && this->listener != nullptr)
{
this->listener->CallState(this->incomingcall, LinphoneCallState::IncomingReceived);
this->call = incomingcall;
this->incomingcall = nullptr;
}
}
void LinphoneCore::Destroy()
......@@ -103,7 +111,9 @@ LinphoneAddress^ LinphoneCore::InterpretURL(Platform::String^ destination)
LinphoneCall^ LinphoneCore::Invite(Platform::String^ destination)
{
return nullptr;
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
return ref new LinphoneCall("", destination);
}
LinphoneCall^ LinphoneCore::InviteAddress(LinphoneAddress^ to)
......@@ -118,12 +128,13 @@ LinphoneCall^ LinphoneCore::InviteAddressWithParams(LinphoneAddress^ destination
void LinphoneCore::TerminateCall(LinphoneCall^ call)
{
call = nullptr;
this->call = nullptr;
}
LinphoneCall^ LinphoneCore::GetCurrentCall()
{
return nullptr;
return this->call;
}
LinphoneAddress^ LinphoneCore::GetRemoteAddress()
......@@ -438,7 +449,9 @@ void LinphoneCore::TerminateAllCalls()
Windows::Foundation::Collections::IVector<LinphoneCall^>^ LinphoneCore::GetCalls()
{
return nullptr;
auto calls = ref new Platform::Collections::Vector<LinphoneCall^>();
calls->Append(this->call);
return calls;
}
int LinphoneCore::GetCallsNb()
......@@ -601,7 +614,34 @@ LpConfig^ LinphoneCore::GetConfig()
return nullptr;
}
LinphoneCore::LinphoneCore()
LinphoneCall^ LinphoneCore::Call::get()
{
return this->call;
}
void LinphoneCore::Call::set(LinphoneCall^ call)
{
this->call = call;
}
LinphoneCall^ LinphoneCore::IncomingCall::get()
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
return this->incomingcall;
}
void LinphoneCore::IncomingCall::set(LinphoneCall^ call)
{
std::lock_guard<std::recursive_mutex> lock(g_apiLock);
this->incomingcall = call;
}
LinphoneCore::LinphoneCore(LinphoneCoreListener^ coreListener) :
call(nullptr),
incomingcall(nullptr),
listener(coreListener)
{
}
......
#pragma once
#include "OnlineStatus.h"
#include "Enums.h"