Commit 2f04c06d authored by Ghislain MARY's avatar Ghislain MARY
Browse files

First compiling Linphone project with Core C++/CX wrapper (some WP8 specific...

First compiling Linphone project with Core C++/CX wrapper (some WP8 specific parts are commented out so that it builds).
parent f837f396
/*
CallController.cpp
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "CallController.h"
#include "LinphoneCall.h"
#include "LinphoneCallParams.h"
#include "LinphoneCore.h"
#include "Server.h"
#include "VideoPolicy.h"
using namespace Linphone::Core;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Phone::Networking::Voip;
//#define ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCall^ call, Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
VoipPhoneCall^ incomingCall = nullptr;
this->call = call;
VoipCallMedia media = VoipCallMedia::Audio;
#ifdef ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
if (Globals::Instance->LinphoneCore->IsVideoSupported() && Globals::Instance->LinphoneCore->IsVideoEnabled()) {
bool automatically_accept = false;
LinphoneCallParams^ remoteParams = call->GetRemoteParams();
VideoPolicy^ policy = Globals::Instance->LinphoneCore->GetVideoPolicy();
if (policy != nullptr) {
automatically_accept = policy->AutomaticallyAccept;
}
if ((remoteParams != nullptr) && remoteParams->IsVideoEnabled() && automatically_accept) {
media = VoipCallMedia::Audio | VoipCallMedia::Video;
}
}
#endif
if (!this->customIncomingCallView) {
TimeSpan ringingTimeout;
ringingTimeout.Duration = 90 * 10 * 1000 * 1000; // in 100ns units
try {
if (incomingCallViewDismissedCallback != nullptr)
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,
media,
ringingTimeout,
&incomingCall);
}
catch(...) {
return nullptr;
}
incomingCall->AnswerRequested += this->acceptCallRequestedHandler;
incomingCall->RejectRequested += this->rejectCallRequestedHandler;
} else {
// When using the custom incoming call view, the VoipPhoneCall will be created when getting in the
// StreamsRunning state by calling NewIncomingCallForCustomIncomingCallView()
}
return incomingCall;
}
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
incomingCall->NotifyCallActive();
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
this->onIncomingCallViewDismissed = nullptr;
}
if (this->call != nullptr) {
#ifdef ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
LinphoneCallParams^ params = call->GetCurrentParamsCopy();
if ((args->AcceptedMedia & VoipCallMedia::Video) == VoipCallMedia::Video) {
params->EnableVideo(true);
} else {
params->EnableVideo(false);
}
Globals::Instance->LinphoneCore->AcceptCallWithParams(this->call, params);
#else
Globals::Instance->LinphoneCore->AcceptCall(this->call);
#endif
}
}
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
this->onIncomingCallViewDismissed = nullptr;
}
//This will call notifyCallEnded on the call state changed callback
if (this->call != nullptr)
Globals::Instance->LinphoneCore->DeclineCall(this->call, this->declineReason);
}
VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number)
{
VoipPhoneCall^ outgoingCall = nullptr;
this->call = call;
VoipCallMedia media = VoipCallMedia::Audio;
if (Globals::Instance->LinphoneCore->VideoSupported && Globals::Instance->LinphoneCore->VideoEnabled) {
VideoPolicy^ policy = Globals::Instance->LinphoneCore->VideoPolicy;
if ((policy != nullptr) && policy->AutomaticallyInitiate) {
media = VoipCallMedia::Audio | VoipCallMedia::Video;
}
}
this->callCoordinator->RequestNewOutgoingCall(
this->callInProgressPageUri + "?sip=" + number,
number,
this->voipServiceName,
media,
&outgoingCall);
outgoingCall->NotifyCallActive();
return outgoingCall;
}
VoipPhoneCall^ CallController::NewIncomingCallForCustomIncomingCallView(Platform::String^ contactNumber)
{
VoipPhoneCall^ incomingCall = nullptr;
VoipCallMedia media = VoipCallMedia::Audio;
this->callCoordinator->RequestNewOutgoingCall(
this->callInProgressPageUri + "?sip=" + contactNumber,
contactNumber,
this->voipServiceName,
media,
&incomingCall);
return incomingCall;
}
void CallController::NotifyMute(bool isMuted)
{
if (isMuted)
this->callCoordinator->NotifyMuted();
else
this->callCoordinator->NotifyUnmuted();
}
IncomingCallViewDismissedCallback^ CallController::IncomingCallViewDismissed::get()
{
return this->onIncomingCallViewDismissed;
}
void CallController::IncomingCallViewDismissed::set(IncomingCallViewDismissedCallback^ cb)
{
API_LOCK;
this->onIncomingCallViewDismissed = cb;
}
Platform::Boolean CallController::CustomIncomingCallView::get()
{
return this->customIncomingCallView;
}
void CallController::CustomIncomingCallView::set(Platform::Boolean value)
{
API_LOCK;
this->customIncomingCallView = value;
}
Reason CallController::DeclineReason::get()
{
return this->declineReason;
}
void CallController::DeclineReason::set(Linphone::Core::Reason value)
{
API_LOCK;
this->declineReason = value;
}
CallController::CallController() :
callInProgressPageUri(L"/Views/InCall.xaml"),
voipServiceName(nullptr),
defaultContactImageUri(nullptr),
linphoneImageUri(nullptr),
ringtoneUri(nullptr),
declineReason(Linphone::Core::Reason::LinphoneReasonDeclined),
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\\oldphone.wma");
this->acceptCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallAnswerEventArgs^>(this, &CallController::OnAcceptCallRequested);
this->rejectCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallRejectEventArgs^>(this, &CallController::OnRejectCallRequested);
}
CallController::~CallController()
{
}
/*
CallController.cpp
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "CallController.h"
#include "LinphoneCall.h"
#include "LinphoneCallParams.h"
#include "LinphoneCore.h"
#include "Server.h"
#include "VideoPolicy.h"
using namespace Linphone::Core;
using namespace Platform;
using namespace Windows::Foundation;
//using namespace Windows::Phone::Networking::Voip;
//#define ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
#if 0
VoipPhoneCall^ CallController::OnIncomingCallReceived(Linphone::Core::LinphoneCall^ call, Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback)
{
VoipPhoneCall^ incomingCall = nullptr;
this->call = call;
VoipCallMedia media = VoipCallMedia::Audio;
#ifdef ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
if (Globals::Instance->LinphoneCore->IsVideoSupported() && Globals::Instance->LinphoneCore->IsVideoEnabled()) {
bool automatically_accept = false;
LinphoneCallParams^ remoteParams = call->GetRemoteParams();
VideoPolicy^ policy = Globals::Instance->LinphoneCore->GetVideoPolicy();
if (policy != nullptr) {
automatically_accept = policy->AutomaticallyAccept;
}
if ((remoteParams != nullptr) && remoteParams->IsVideoEnabled() && automatically_accept) {
media = VoipCallMedia::Audio | VoipCallMedia::Video;
}
}
#endif
if (!this->customIncomingCallView) {
TimeSpan ringingTimeout;
ringingTimeout.Duration = 90 * 10 * 1000 * 1000; // in 100ns units
try {
if (incomingCallViewDismissedCallback != nullptr)
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,
media,
ringingTimeout,
&incomingCall);
}
catch(...) {
return nullptr;
}
incomingCall->AnswerRequested += this->acceptCallRequestedHandler;
incomingCall->RejectRequested += this->rejectCallRequestedHandler;
} else {
// When using the custom incoming call view, the VoipPhoneCall will be created when getting in the
// StreamsRunning state by calling NewIncomingCallForCustomIncomingCallView()
}
return incomingCall;
}
void CallController::OnAcceptCallRequested(VoipPhoneCall^ incomingCall, CallAnswerEventArgs^ args)
{
incomingCall->NotifyCallActive();
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
this->onIncomingCallViewDismissed = nullptr;
}
if (this->call != nullptr) {
#ifdef ACCEPT_WITH_VIDEO_OR_WITH_AUDIO_ONLY
LinphoneCallParams^ params = call->GetCurrentParamsCopy();
if ((args->AcceptedMedia & VoipCallMedia::Video) == VoipCallMedia::Video) {
params->EnableVideo(true);
} else {
params->EnableVideo(false);
}
Globals::Instance->LinphoneCore->AcceptCallWithParams(this->call, params);
#else
Globals::Instance->LinphoneCore->AcceptCall(this->call);
#endif
}
}
void CallController::OnRejectCallRequested(VoipPhoneCall^ incomingCall, CallRejectEventArgs^ args)
{
if (this->onIncomingCallViewDismissed != nullptr) {
this->onIncomingCallViewDismissed();
this->onIncomingCallViewDismissed = nullptr;
}
//This will call notifyCallEnded on the call state changed callback
if (this->call != nullptr)
Globals::Instance->LinphoneCore->DeclineCall(this->call, this->declineReason);
}
VoipPhoneCall^ CallController::NewOutgoingCall(Platform::String^ number)
{
VoipPhoneCall^ outgoingCall = nullptr;
this->call = call;
VoipCallMedia media = VoipCallMedia::Audio;
if (Globals::Instance->LinphoneCore->VideoSupported && Globals::Instance->LinphoneCore->VideoEnabled) {
VideoPolicy^ policy = Globals::Instance->LinphoneCore->VideoPolicy;
if ((policy != nullptr) && policy->AutomaticallyInitiate) {
media = VoipCallMedia::Audio | VoipCallMedia::Video;
}
}
this->callCoordinator->RequestNewOutgoingCall(
this->callInProgressPageUri + "?sip=" + number,
number,
this->voipServiceName,
media,
&outgoingCall);
outgoingCall->NotifyCallActive();
return outgoingCall;
}
VoipPhoneCall^ CallController::NewIncomingCallForCustomIncomingCallView(Platform::String^ contactNumber)
{
VoipPhoneCall^ incomingCall = nullptr;
VoipCallMedia media = VoipCallMedia::Audio;
this->callCoordinator->RequestNewOutgoingCall(
this->callInProgressPageUri + "?sip=" + contactNumber,
contactNumber,
this->voipServiceName,
media,
&incomingCall);
return incomingCall;
}
#endif
void CallController::NotifyMute(bool isMuted)
{
#if 0
if (isMuted)
this->callCoordinator->NotifyMuted();
else
this->callCoordinator->NotifyUnmuted();
#endif
}
IncomingCallViewDismissedCallback^ CallController::IncomingCallViewDismissed::get()
{
return this->onIncomingCallViewDismissed;
}
void CallController::IncomingCallViewDismissed::set(IncomingCallViewDismissedCallback^ cb)
{
API_LOCK;
this->onIncomingCallViewDismissed = cb;
}
Platform::Boolean CallController::CustomIncomingCallView::get()
{
return this->customIncomingCallView;
}
void CallController::CustomIncomingCallView::set(Platform::Boolean value)
{
API_LOCK;
this->customIncomingCallView = value;
}
Reason CallController::DeclineReason::get()
{
return this->declineReason;
}
void CallController::DeclineReason::set(Linphone::Core::Reason value)
{
API_LOCK;
this->declineReason = value;
}
CallController::CallController() :
callInProgressPageUri(L"/Views/InCall.xaml"),
voipServiceName(nullptr),
defaultContactImageUri(nullptr),
linphoneImageUri(nullptr),
ringtoneUri(nullptr),
declineReason(Linphone::Core::Reason::LinphoneReasonDeclined) //,
//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\\oldphone.wma");
//this->acceptCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallAnswerEventArgs^>(this, &CallController::OnAcceptCallRequested);
//this->rejectCallRequestedHandler = ref new TypedEventHandler<VoipPhoneCall^, CallRejectEventArgs^>(this, &CallController::OnRejectCallRequested);
}
CallController::~CallController()
{
}
/*
CallController.h
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#pragma once
#include <windows.phone.networking.voip.h>
#include "Enums.h"
#include "ApiLock.h"
namespace Linphone
{
namespace Core
{
ref class Globals;
ref class LinphoneCall;
/// <summary>
/// Callback to be called when the PushNotification Agent has to be dismissed, i.e. after a call has been accepted, denied or stopped by the caller.
/// </summary>
public delegate void IncomingCallViewDismissedCallback();
/// <summary>
/// Provides methods and properties related to Windows.Phone.Networking.Voip.VoipPhoneCall calls.
/// </summary>
public ref class CallController sealed
{
public:
/// <summary>
/// Starts the system incoming call view.
/// </summary>
/// <param name="call">The incoming LinphoneCall to notify</param>
/// <param name="contactName">The display name of the caller</param>
/// <param name="contactNumber">The number or SIP URI of the caller</param>
/// <param name="incomingCallViewDismissedCallback">The callback to be called if the notified incoming call is dismissed by the user</param>
/// <returns>The system VoipPhoneCall that has been notified</returns>
Windows::Phone::Networking::Voip::VoipPhoneCall^ OnIncomingCallReceived(LinphoneCall^ call, Platform::String^ contactName, Platform::String^ contactNumber, IncomingCallViewDismissedCallback^ incomingCallViewDismissedCallback);
/// <summary>
/// Starts an outgoing call using native VoipPhoneCall.
/// </summary>
/// <param name="number">The number of SIP URI to call</param>
/// <returns>The system VoipPhoneCall that has been initiated</returns>
Windows::Phone::Networking::Voip::VoipPhoneCall^ NewOutgoingCall(Platform::String^ number);
/// <summary>
/// Starts an incoming call for custom incoming call view.
/// </summary>
/// <param name="contactNumber">The number or SIP URI of the caller</param>
/// <returns>The system VoipPhoneCall that has been created</returns>
Windows::Phone::Networking::Voip::VoipPhoneCall^ NewIncomingCallForCustomIncomingCallView(Platform::String^ contactNumber);
/// <summary>
/// Notifies the system that the call needs to be muted/unmuted.
/// </summary>
/// <param name="isMuted">The new mute state</param>
void NotifyMute(bool isMuted);
/// <summary>
/// Changes the reason used when declining an incoming call.
/// </summary>
property Linphone::Core::Reason DeclineReason
{
Linphone::Core::Reason get();
void set(Linphone::Core::Reason cb);
}
/// <summary>
/// Callback to be called when the PushNotification Agent has to be dismissed, i.e. after a call has been accepted, denied or stopped by the caller.
/// </summary>
property IncomingCallViewDismissedCallback^ IncomingCallViewDismissed
{
IncomingCallViewDismissedCallback^ get();
void set(IncomingCallViewDismissedCallback^ cb);
}
/// <summary>
/// Property to tell that we will use our custom incoming call view instead of the one provided by the OS.
/// </summary>
property Platform::Boolean CustomIncomingCallView
{
Platform::Boolean get();
void set(Platform::Boolean value);
}
private:
friend ref class Linphone::Core::Globals;
Platform::String^ voipServiceName;
Platform::String^ callInProgressPageUri;
Linphone::Core::Reason declineReason;
// 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;
Linphone::Core::LinphoneCall^ call;
IncomingCallViewDismissedCallback^ onIncomingCallViewDismissed;
Platform::Boolean customIncomingCallView;
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();
};
}
}
/*
CallController.h
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
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/