Commit 083b3ae6 authored by Nicolas Jager's avatar Nicolas Jager

patch pour amelioration des etats

Change-Id: I5fd57088cc6a687edbaf80d556d275b7ea1040a7
Tuleap: #1205
parent 9edbea38
...@@ -27,58 +27,12 @@ using namespace Windows::ApplicationModel::Core; ...@@ -27,58 +27,12 @@ using namespace Windows::ApplicationModel::Core;
CallsViewModel::CallsViewModel() CallsViewModel::CallsViewModel()
{ {
CallsList_ = ref new Vector<Call^>(); callIdsList_ = ref new Vector<String^>();
/* connect to delegates. */ /* connect to delegates. */
RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&]( RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
String^ accountId, String^ callId, String^ from) { String^ accountId, String^ callId, String^ from) {
auto call = addNewCall(accountId, callId, from); callIdsList_->Append(callId); // TODO : check if the string is remove when the call ends.
if (call)
callRecieved(call);
}); });
RingD::instance->stateChange += ref new RingClientUWP::StateChange(this, &RingClientUWP::ViewModel::CallsViewModel::OnstateChange);
}
Call^
RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ peer)
{
if (accountId == "" | callId == "" | peer == "") {
WNG_("call can't be created");
}
auto call = ref new Call(accountId, callId, peer);
CallsList_->Append(call);
return call;
}
void RingClientUWP::ViewModel::CallsViewModel::clearCallsList()
{
CallsList_->Clear();
}
Call^
CallsViewModel::findCall(String^ callId)
{
for each (Call^ call in CallsList_)
if (call->callId == callId)
return call;
return nullptr;
}
void RingClientUWP::ViewModel::CallsViewModel::OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code)
{
auto call = findCall(callId);
if (!call)
return;
switch (state)
{
case CallStatus::ENDED:
RingD::instance->hangUpCall(call);
default:
break;
}
} }
...@@ -41,18 +41,12 @@ internal: ...@@ -41,18 +41,12 @@ internal:
} }
} }
/* functions */
Call^ addNewCall(String^ accountId, String^ callId, String^ from);
void clearCallsList();
//void setState(String^ callId, String^ state, int code); // used ?
Call^ findCall(String^ callId);
/* properties */ /* properties */
property Vector<Call^>^ CallsList property Vector<String^>^ _callIdList
{ {
Vector<Call^>^ get() Vector<String^>^ get()
{ {
return CallsList_; return callIdsList_;
} }
} }
...@@ -64,9 +58,8 @@ internal: ...@@ -64,9 +58,8 @@ internal:
private: private:
CallsViewModel(); // singleton CallsViewModel(); // singleton
Vector<Call^>^ CallsList_; // refacto : change C to c Vector<String^>^ callIdsList_;
void OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code);
}; };
} }
} }
namespace RingClientUWP
{
/* public enumerations. */
public enum class CallStatus { NONE, INCOMING_RINGING, OUTGOING_RINGING, SEARCHING, IN_PROGRESS, ENDED, TERMINATING };
}
\ No newline at end of file
...@@ -246,14 +246,6 @@ void RingClientUWP::MainPage::OnstateChange(Platform::String ^callId, RingClient ...@@ -246,14 +246,6 @@ void RingClientUWP::MainPage::OnstateChange(Platform::String ^callId, RingClient
OnsummonMessageTextPage(); OnsummonMessageTextPage();
break; break;
} }
/* if the state changes to IN_PROGRESS for any peer, show the video page.
nb : the peer is currently selected from the SmartPannel. */
case CallStatus::IN_PROGRESS:
{
if (item)
OnsummonVideoPage();
break;
}
default: default:
break; break;
} }
...@@ -265,14 +257,14 @@ MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingE ...@@ -265,14 +257,14 @@ MainPage::Application_Suspending(Object^, Windows::ApplicationModel::SuspendingE
{ {
WriteLine("Application_Suspending"); WriteLine("Application_Suspending");
if (Frame->CurrentSourcePageType.Name == if (Frame->CurrentSourcePageType.Name ==
Interop::TypeName(MainPage::typeid).Name) Interop::TypeName(MainPage::typeid).Name)
{ {
if (Video::VideoManager::instance->captureManager()->captureTaskTokenSource) if (Video::VideoManager::instance->captureManager()->captureTaskTokenSource)
Video::VideoManager::instance->captureManager()->captureTaskTokenSource->cancel(); Video::VideoManager::instance->captureManager()->captureTaskTokenSource->cancel();
//displayInformation->OrientationChanged -= displayInformationEventToken; //displayInformation->OrientationChanged -= displayInformationEventToken;
auto deferral = e->SuspendingOperation->GetDeferral(); auto deferral = e->SuspendingOperation->GetDeferral();
Video::VideoManager::instance->captureManager()->CleanupCameraAsync() Video::VideoManager::instance->captureManager()->CleanupCameraAsync()
.then([this, deferral]() { .then([this, deferral]() {
deferral->Complete(); deferral->Complete();
}); });
} }
...@@ -292,4 +284,5 @@ MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventAr ...@@ -292,4 +284,5 @@ MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventAr
{ {
WriteLine("->Invisible"); WriteLine("->Invisible");
} }
} }
...@@ -60,6 +60,6 @@ private: ...@@ -60,6 +60,6 @@ private:
void OnsummonWelcomePage(); void OnsummonWelcomePage();
void OnsummonVideoPage(); void OnsummonVideoPage();
void OnpressHangUpCall(); void OnpressHangUpCall();
void OnstateChange(Platform::String ^callId, RingClientUWP::CallStatus state, int code); void OnstateChange(Platform::String ^callId, CallStatus state, int code);
}; };
} }
...@@ -95,7 +95,7 @@ void RingConsolePanel::sendCommand() ...@@ -95,7 +95,7 @@ void RingConsolePanel::sendCommand()
currentCmd = ""; currentCmd = "";
historyLevel = historyCmds.Size; historyLevel = historyCmds.Size;
if (cmdInput == "") { if (cmdInput->IsEmpty()) {
return; return;
} }
else if (cmdInput == "help") { else if (cmdInput == "help") {
......
...@@ -114,14 +114,14 @@ RingD::createSIPAccount(String^ alias) ...@@ -114,14 +114,14 @@ RingD::createSIPAccount(String^ alias)
tasksList_.push(ref new RingD::Task(Request::AddSIPAccount)); tasksList_.push(ref new RingD::Task(Request::AddSIPAccount));
} }
void RingClientUWP::RingD::refuseIncommingCall(Call^ call) void RingClientUWP::RingD::refuseIncommingCall(String^ callId)
{ {
tasksList_.push(ref new RingD::Task(Request::RefuseIncommingCall, call)); tasksList_.push(ref new RingD::Task(Request::RefuseIncommingCall, callId));
} }
void RingClientUWP::RingD::acceptIncommingCall(Call^ call) void RingClientUWP::RingD::acceptIncommingCall(String^ callId)
{ {
tasksList_.push(ref new RingD::Task(Request::AcceptIncommingCall, call)); tasksList_.push(ref new RingD::Task(Request::AcceptIncommingCall, callId));
} }
void RingClientUWP::RingD::placeCall(Contact^ contact) void RingClientUWP::RingD::placeCall(Contact^ contact)
...@@ -137,65 +137,40 @@ void RingClientUWP::RingD::placeCall(Contact^ contact) ...@@ -137,65 +137,40 @@ void RingClientUWP::RingD::placeCall(Contact^ contact)
if (callId2 == "") { if (callId2.empty()) {
WNG_("call not created, the daemon didn't return a call Id"); WNG_("call not created, the daemon didn't return a call Id");
return; return;
} }
auto callId = Utils::toPlatformString(callId2); auto callId = Utils::toPlatformString(callId2);
_callIdsList->Append(callId);
//auto con = ContactsViewModel::instance->findContactByName(to); //auto con = ContactsViewModel::instance->findContactByName(to);
auto item = SmartPanelItemsViewModel::instance->findItem(contact); auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = callId; item->_callId = callId;
MSG_("$1 place call with id : " + Utils::toString(item->_callId)); MSG_("$1 place call with id : " + Utils::toString(item->_callId));
callPlaced(callId);
auto call = CallsViewModel::instance->addNewCall(accountId, callId, to);
call->isOutGoing = true;
if (call == nullptr) {
WNG_("call not created, nullptr reason");
return;
}
calling(call);
}
void
RingClientUWP::RingD::cancelOutGoingCall(Call^ call)
{
MSG_("1!--->> cancelOutGoingCall");
if (call)
tasksList_.push(ref new RingD::Task(Request::CancelOutGoingCall, call));
} }
void RingClientUWP::RingD::cancelOutGoingCall2(String ^ callId) void RingClientUWP::RingD::cancelOutGoingCall2(String ^ callId)
{ {
MSG_("$1 cancelOutGoingCall2 : " + Utils::toString(callId)); MSG_("$1 cancelOutGoingCall2 : " + Utils::toString(callId));
tasksList_.push(ref new RingD::Task(Request::HangUpCall, callId, 0)); tasksList_.push(ref new RingD::Task(Request::HangUpCall, callId));
} }
void
RingClientUWP::RingD::hangUpCall(Call^ call)
{
tasksList_.push(ref new RingD::Task(Request::HangUpCall, call));
}
void RingClientUWP::RingD::hangUpCall2(String ^ callId) void RingClientUWP::RingD::hangUpCall2(String ^ callId)
{ {
MSG_("$1 hangUpCall2 : "+Utils::toString(callId)); MSG_("$1 hangUpCall2 : "+Utils::toString(callId));
tasksList_.push(ref new RingD::Task(Request::HangUpCall, callId, 0)); tasksList_.push(ref new RingD::Task(Request::HangUpCall, callId));
} }
void void
RingClientUWP::RingD::startDaemon() RingClientUWP::RingD::startDaemon()
{ {
// TODO (during refactoring) : use namespace
/* clear the calls list and instantiate the singleton (required) */
RingClientUWP::ViewModel::CallsViewModel::instance->clearCallsList();
create_task([&]() create_task([&]()
{ {
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>; using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
...@@ -228,7 +203,6 @@ RingClientUWP::RingD::startDaemon() ...@@ -228,7 +203,6 @@ RingClientUWP::RingD::startDaemon()
incomingCall(accountId2, callId2, from2); incomingCall(accountId2, callId2, from2);
stateChange(callId2, CallStatus::INCOMING_RINGING, 0); stateChange(callId2, CallStatus::INCOMING_RINGING, 0);
auto contact = ContactsViewModel::instance->findContactByName(from2); auto contact = ContactsViewModel::instance->findContactByName(from2);
auto item = SmartPanelItemsViewModel::instance->findItem(contact); auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = callId2; item->_callId = callId2;
...@@ -250,6 +224,9 @@ RingClientUWP::RingD::startDaemon() ...@@ -250,6 +224,9 @@ RingClientUWP::RingD::startDaemon()
auto state3 = getCallStatus(state2); auto state3 = getCallStatus(state2);
if (state3 == CallStatus::ENDED)
DRing::hangUp(callId); // solve a bug in the daemon API.
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High, ref new DispatchedHandler([=]() CoreDispatcherPriority::High, ref new DispatchedHandler([=]()
...@@ -293,12 +270,7 @@ RingClientUWP::RingD::startDaemon() ...@@ -293,12 +270,7 @@ RingClientUWP::RingD::startDaemon()
from2 = Utils::TrimRingId2(from2); from2 = Utils::TrimRingId2(from2);
Call^ call = CallsViewModel::instance->findCall(callId2);
if (!call)
return;
String^ accountId2 = call->accountId;
const std::string PROFILE_VCF = "x-ring/ring.profile.vcard"; const std::string PROFILE_VCF = "x-ring/ring.profile.vcard";
static const unsigned int profileSize = PROFILE_VCF.size(); static const unsigned int profileSize = PROFILE_VCF.size();
...@@ -314,7 +286,9 @@ RingClientUWP::RingD::startDaemon() ...@@ -314,7 +286,9 @@ RingClientUWP::RingD::startDaemon()
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync( CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High, ref new DispatchedHandler([=]() CoreDispatcherPriority::High, ref new DispatchedHandler([=]()
{ {
incomingAccountMessage(accountId2, from2, payload); // DOIT ETRE DIFFEREND.... NE PAS UTILISE accoutId2
//incomingAccountMessage(accountId2, from2, payload);
MSG_("message recu :" + i.second);
})); }));
} }
}), }),
...@@ -462,8 +436,8 @@ RingClientUWP::RingD::startDaemon() ...@@ -462,8 +436,8 @@ RingClientUWP::RingD::startDaemon()
} }
while (true) { while (true) {
DRing::pollEvents(); DRing::pollEvents();
Sleep(1000);
dequeueTasks(); dequeueTasks();
Sleep(1000);
} }
DRing::fini(); DRing::fini();
} }
...@@ -473,6 +447,7 @@ RingClientUWP::RingD::startDaemon() ...@@ -473,6 +447,7 @@ RingClientUWP::RingD::startDaemon()
RingD::RingD() RingD::RingD()
{ {
localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path); localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path);
callIdsList_ = ref new Vector<String^>();
} }
void void
...@@ -502,14 +477,14 @@ RingD::dequeueTasks() ...@@ -502,14 +477,14 @@ RingD::dequeueTasks()
break; break;
case Request::RefuseIncommingCall: case Request::RefuseIncommingCall:
{ {
auto callId = task->_call->callId; auto callId = task->_callId;
auto callId2 = Utils::toString(callId); auto callId2 = Utils::toString(callId);
DRing::refuse(callId2); DRing::refuse(callId2);
} }
break; break;
case Request::AcceptIncommingCall: case Request::AcceptIncommingCall:
{ {
auto callId = task->_call->callId; auto callId = task->_callId;
auto callId2 = Utils::toString(callId); auto callId2 = Utils::toString(callId);
DRing::accept(callId2); DRing::accept(callId2);
} }
...@@ -517,15 +492,8 @@ RingD::dequeueTasks() ...@@ -517,15 +492,8 @@ RingD::dequeueTasks()
case Request::CancelOutGoingCall: case Request::CancelOutGoingCall:
case Request::HangUpCall: case Request::HangUpCall:
{ {
auto callId = task->_callId;
MSG_("1!--->> Request::CancelOutGoingCall"); DRing::hangUp(Utils::toString(callId));
auto id = task->_callId;
DRing::hangUp(Utils::toString(id));
return;
auto callId = task->_call->callId;
auto callId2 = Utils::toString(callId);
DRing::hangUp(callId2);
} }
break; break;
default: default:
...@@ -535,7 +503,7 @@ RingD::dequeueTasks() ...@@ -535,7 +503,7 @@ RingD::dequeueTasks()
} }
} }
CallStatus RingClientUWP::RingD::getCallStatus(String^ state) RingClientUWP::CallStatus RingClientUWP::RingD::getCallStatus(String^ state)
{ {
if (state == "INCOMING") if (state == "INCOMING")
return CallStatus::INCOMING_RINGING; return CallStatus::INCOMING_RINGING;
......
...@@ -26,7 +26,7 @@ namespace RingClientUWP ...@@ -26,7 +26,7 @@ namespace RingClientUWP
delegate void IncomingCall(String^ accountId, String^ callId, String^ from); delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
delegate void StateChange(String^ callId, CallStatus state, int code); delegate void StateChange(String^ callId, CallStatus state, int code);
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload); delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
delegate void Calling(Call^ call); delegate void CallPlaced(String^ callId);
public ref class RingD sealed public ref class RingD sealed
...@@ -54,6 +54,15 @@ public: ...@@ -54,6 +54,15 @@ public:
void cancelOutGoingCall2(String^ callId); // marche void cancelOutGoingCall2(String^ callId); // marche
internal: // why this property has to be internal and not public ?
property Vector<String^>^ _callIdsList
{
Vector<String^>^ get()
{
return callIdsList_;
}
}
internal: internal:
/* functions */ /* functions */
...@@ -62,13 +71,12 @@ internal: ...@@ -62,13 +71,12 @@ internal:
void sendAccountTextMessage(String^ message); void sendAccountTextMessage(String^ message);
void createRINGAccount(String^ alias); void createRINGAccount(String^ alias);
void createSIPAccount(String^ alias); void createSIPAccount(String^ alias);
void refuseIncommingCall(Call^ call); void refuseIncommingCall(String^ call);
void acceptIncommingCall(Call^ call); void acceptIncommingCall(String^ call);
void placeCall(Contact^ contact); void placeCall(Contact^ contact);
void cancelOutGoingCall(Call^ call);
/*void cancelOutGoingCall2(String^ callId);*/ // marche pas /*void cancelOutGoingCall2(String^ callId);*/ // marche pas
CallStatus getCallStatus(String^ state);
void hangUpCall(Call^ call);
void hangUpCall2(String^ callId); void hangUpCall2(String^ callId);
/* TODO : move members */ /* TODO : move members */
...@@ -79,7 +87,7 @@ internal: ...@@ -79,7 +87,7 @@ internal:
event IncomingCall^ incomingCall; event IncomingCall^ incomingCall;
event StateChange^ stateChange; event StateChange^ stateChange;
event IncomingAccountMessage^ incomingAccountMessage; event IncomingAccountMessage^ incomingAccountMessage;
event Calling^ calling; event CallPlaced^ callPlaced;
private: private:
/* sub classes */ /* sub classes */
...@@ -92,30 +100,29 @@ private: ...@@ -92,30 +100,29 @@ private:
CancelOutGoingCall, CancelOutGoingCall,
HangUpCall HangUpCall
}; };
Vector<String^>^ callIdsList_;
ref class Task ref class Task
{ {
internal: internal:
Task(Request r) { Task(Request r) {
request = r; request = r;
} }
Task(Request r, Call^ c) { Task(Request r, String^ c) {
request = r;
_call = c;
}
Task(Request r, String^ c, int i) {
request = r; request = r;
_callId = c; _callId = c;
} }
public: public:
property Request request; property Request request;
property Call^ _call;
property String^ _callId; property String^ _callId;
}; };
/* functions */ /* functions */
RingD(); // singleton RingD(); // singleton
void dequeueTasks(); void dequeueTasks();
CallStatus getCallStatus(String^ state); // CallStatus getCallStatus(String^ state);
/* members */ /* members */
std::string localFolder_; std::string localFolder_;
......
...@@ -203,65 +203,6 @@ ...@@ -203,65 +203,6 @@
Text="{x:Bind ringID_}"/> Text="{x:Bind ringID_}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
<!-- template for incoming calls. -->
<DataTemplate x:Key="IncomingCallTemplate" x:DataType="local:Call">
<Grid Width="320"
HorizontalAlignment="Left"
Background="DarkGray">
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock x:Name="_contactCallStatus_"
Grid.Row="0"
Foreground="White"
Text="{x:Bind state, Mode=OneWay}"
Visibility="Visible"
HorizontalAlignment="Center">
</TextBlock>
<StackPanel Orientation="Horizontal"
Grid.Row="1"
HorizontalAlignment="Center">
<Button x:Name="_acceptIncomingCallBtn_"