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;
CallsViewModel::CallsViewModel()
{
CallsList_ = ref new Vector<Call^>();
callIdsList_ = ref new Vector<String^>();
/* connect to delegates. */
RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
String^ accountId, String^ callId, String^ from) {
auto call = addNewCall(accountId, callId, from);
if (call)
callRecieved(call);
callIdsList_->Append(callId); // TODO : check if the string is remove when the call ends.
});
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:
}
}
/* 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 */
property Vector<Call^>^ CallsList
property Vector<String^>^ _callIdList
{
Vector<Call^>^ get()
Vector<String^>^ get()
{
return CallsList_;
return callIdsList_;
}
}
......@@ -64,9 +58,8 @@ internal:
private:
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
OnsummonMessageTextPage();
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:
break;
}
......@@ -293,3 +285,4 @@ MainPage::Application_VisibilityChanged(Object^ sender, VisibilityChangedEventAr
WriteLine("->Invisible");
}
}
......@@ -60,6 +60,6 @@ private:
void OnsummonWelcomePage();
void OnsummonVideoPage();
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()
currentCmd = "";
historyLevel = historyCmds.Size;
if (cmdInput == "") {
if (cmdInput->IsEmpty()) {
return;
}
else if (cmdInput == "help") {
......
......@@ -114,14 +114,14 @@ RingD::createSIPAccount(String^ alias)
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)
......@@ -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");
return;
}
auto callId = Utils::toPlatformString(callId2);
_callIdsList->Append(callId);
//auto con = ContactsViewModel::instance->findContactByName(to);
auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = 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)
{
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)
{
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
RingClientUWP::RingD::startDaemon()
{
// TODO (during refactoring) : use namespace
/* clear the calls list and instantiate the singleton (required) */
RingClientUWP::ViewModel::CallsViewModel::instance->clearCallsList();
create_task([&]()
{
using SharedCallback = std::shared_ptr<DRing::CallbackWrapperBase>;
......@@ -228,7 +203,6 @@ RingClientUWP::RingD::startDaemon()
incomingCall(accountId2, callId2, from2);
stateChange(callId2, CallStatus::INCOMING_RINGING, 0);
auto contact = ContactsViewModel::instance->findContactByName(from2);
auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_callId = callId2;
......@@ -250,6 +224,9 @@ RingClientUWP::RingD::startDaemon()
auto state3 = getCallStatus(state2);
if (state3 == CallStatus::ENDED)
DRing::hangUp(callId); // solve a bug in the daemon API.
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
CoreDispatcherPriority::High, ref new DispatchedHandler([=]()
......@@ -293,12 +270,7 @@ RingClientUWP::RingD::startDaemon()
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";
static const unsigned int profileSize = PROFILE_VCF.size();
......@@ -314,7 +286,9 @@ RingClientUWP::RingD::startDaemon()
CoreApplication::MainView->CoreWindow->Dispatcher->RunAsync(
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()
}
while (true) {
DRing::pollEvents();
Sleep(1000);
dequeueTasks();
Sleep(1000);
}
DRing::fini();
}
......@@ -473,6 +447,7 @@ RingClientUWP::RingD::startDaemon()
RingD::RingD()
{
localFolder_ = Utils::toString(ApplicationData::Current->LocalFolder->Path);
callIdsList_ = ref new Vector<String^>();
}
void
......@@ -502,14 +477,14 @@ RingD::dequeueTasks()
break;
case Request::RefuseIncommingCall:
{
auto callId = task->_call->callId;
auto callId = task->_callId;
auto callId2 = Utils::toString(callId);
DRing::refuse(callId2);
}
break;
case Request::AcceptIncommingCall:
{
auto callId = task->_call->callId;
auto callId = task->_callId;
auto callId2 = Utils::toString(callId);
DRing::accept(callId2);
}
......@@ -517,15 +492,8 @@ RingD::dequeueTasks()
case Request::CancelOutGoingCall:
case Request::HangUpCall:
{
MSG_("1!--->> Request::CancelOutGoingCall");
auto id = task->_callId;
DRing::hangUp(Utils::toString(id));
return;
auto callId = task->_call->callId;
auto callId2 = Utils::toString(callId);
DRing::hangUp(callId2);
auto callId = task->_callId;
DRing::hangUp(Utils::toString(callId));
}
break;
default:
......@@ -535,7 +503,7 @@ RingD::dequeueTasks()
}
}
CallStatus RingClientUWP::RingD::getCallStatus(String^ state)
RingClientUWP::CallStatus RingClientUWP::RingD::getCallStatus(String^ state)
{
if (state == "INCOMING")
return CallStatus::INCOMING_RINGING;
......
......@@ -26,7 +26,7 @@ namespace RingClientUWP
delegate void IncomingCall(String^ accountId, String^ callId, String^ from);
delegate void StateChange(String^ callId, CallStatus state, int code);
delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload);
delegate void Calling(Call^ call);
delegate void CallPlaced(String^ callId);
public ref class RingD sealed
......@@ -54,6 +54,15 @@ public:
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:
/* functions */
......@@ -62,13 +71,12 @@ internal:
void sendAccountTextMessage(String^ message);
void createRINGAccount(String^ alias);
void createSIPAccount(String^ alias);
void refuseIncommingCall(Call^ call);
void acceptIncommingCall(Call^ call);
void refuseIncommingCall(String^ call);
void acceptIncommingCall(String^ call);
void placeCall(Contact^ contact);
void cancelOutGoingCall(Call^ call);
/*void cancelOutGoingCall2(String^ callId);*/ // marche pas
CallStatus getCallStatus(String^ state);
void hangUpCall(Call^ call);
void hangUpCall2(String^ callId);
/* TODO : move members */
......@@ -79,7 +87,7 @@ internal:
event IncomingCall^ incomingCall;
event StateChange^ stateChange;
event IncomingAccountMessage^ incomingAccountMessage;
event Calling^ calling;
event CallPlaced^ callPlaced;
private:
/* sub classes */
......@@ -92,30 +100,29 @@ private:
CancelOutGoingCall,
HangUpCall
};
Vector<String^>^ callIdsList_;
ref class Task
{
internal:
Task(Request r) {
request = r;
}
Task(Request r, Call^ c) {
request = r;
_call = c;
}
Task(Request r, String^ c, int i) {
Task(Request r, String^ c) {
request = r;
_callId = c;
}
public:
property Request request;
property Call^ _call;
property String^ _callId;
};
/* functions */
RingD(); // singleton
void dequeueTasks();
CallStatus getCallStatus(String^ state);
// CallStatus getCallStatus(String^ state);
/* members */
std::string localFolder_;
......
......@@ -203,65 +203,6 @@
Text="{x:Bind ringID_}"/>
</Grid>
</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_"
Click="_acceptIncomingCallBtn__Click"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Accept"/>
<Button x:Name="_rejectIncomingCallBtn_"
Click="_rejectIncomingCallBtn__Click"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Reject"/>
</StackPanel>
</Grid>
</DataTemplate>
<!-- template for outgoing calls. -->
<DataTemplate x:Key="OutGoingCallTemplate" 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="_cancelCallBtn_"
Click="_cancelCallBtn__Click"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Cancel"/>
</StackPanel>
</Grid>
</DataTemplate>
<!-- template for smartpanelitems. -->
<DataTemplate x:Key="SmartPanelItemsTemplate"
x:DataType="controls:SmartPanelItem">
......@@ -348,7 +289,7 @@
</Grid>
</Grid>
</Grid>
<!-- incomming call bar. -->
<!-- call bar. -->
<Grid Width="320"
Grid.Row="1"
HorizontalAlignment="Left"
......@@ -357,11 +298,11 @@
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="_incommingCallStatus_"
<TextBlock x:Name="_CallStatus_"
Grid.Row="0"
Foreground="White"
Text="{x:Bind _call.state, Mode=OneWay}"
Visibility="{x:Bind _call.state, Converter={StaticResource _HasAnActiveCall_}, Mode=OneWay}"
Text="{x:Bind _callStatus, Mode=OneWay}"
Visibility="{x:Bind _callStatus, Converter={StaticResource _HasAnActiveCall_}, Mode=OneWay}"
HorizontalAlignment="Center">
</TextBlock>
<StackPanel Orientation="Horizontal"
......@@ -370,19 +311,19 @@
HorizontalAlignment="Center">
<Button x:Name="_acceptIncomingCallBtn_"
Click="_acceptIncomingCallBtn__Click"
Visibility="{x:Bind _call.state, Converter={StaticResource _IncomingVisibility_}, Mode=OneWay}"
Visibility="{x:Bind _callStatus, Converter={StaticResource _IncomingVisibility_}, Mode=OneWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Accept"/>
<Button x:Name="_rejectIncomingCallBtn_"
Click="_rejectIncomingCallBtn__Click"
Visibility="{x:Bind _call.state, Converter={StaticResource _IncomingVisibility_}, Mode=OneWay}"
Visibility="{x:Bind _callStatus, Converter={StaticResource _IncomingVisibility_}, Mode=OneWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Reject"/>
<Button x:Name="_cancelCallBtn_"
Click="_cancelCallBtn__Click"
Visibility="{x:Bind _call.state, Converter={StaticResource _OutGoingVisibility_}, Mode=OneWay}"
Visibility="{x:Bind _callStatus, Converter={StaticResource _OutGoingVisibility_}, Mode=OneWay}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Content="Cancel"/>
......
......@@ -62,9 +62,9 @@ SmartPanel::SmartPanel()
_accountsListScrollView_->UpdateLayout();
_accountsListScrollView_->ScrollToVerticalOffset(_accountsListScrollView_->ScrollableHeight);
});
CallsViewModel::instance->callRecieved += ref new RingClientUWP::CallRecieved([&](
Call^ call) {
auto from = call->from;
RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&](
String^ accountId, String^ callId, String^ from) {
///auto from = call->from;
auto contact = ContactsViewModel::instance->findContactByName(from);
if (contact == nullptr)
......@@ -76,26 +76,36 @@ SmartPanel::SmartPanel()
}
auto item = SmartPanelItemsViewModel::instance->findItem(contact);
item->_call = call;
item->_callId = callId;
});
RingD::instance->stateChange += ref new StateChange([this](String^ callId, CallStatus state, int code) {
auto call = CallsViewModel::instance->findCall(callId);
if (call == nullptr)
return;
auto item = SmartPanelItemsViewModel::instance->findItem(call);
auto item = SmartPanelItemsViewModel::instance->findItem(callId);
if (!item) {
WNG_("item not found");
return;
}
call->state = state;
item->_callStatus = state;
if (state == CallStatus::IN_PROGRESS)
_smartList_->SelectedIndex = SmartPanelItemsViewModel::instance->getIndex(call);
switch (state) {
case CallStatus::NONE:
case CallStatus::ENDED:
{
item->_callId = "";
break;
}
case CallStatus::IN_PROGRESS:
{
_smartList_->SelectedItem = item;
summonVideoPage();
break;
}
default:
break;
}
});
......@@ -106,29 +116,7 @@ SmartPanel::SmartPanel()
SmartPanelItemsViewModel::instance->itemsList->Append(smartPanelItem);
});
RingD::instance->calling += ref new RingClientUWP::Calling([&](
Call^ call) {
MSG_("!--->> Calling lambda from smartpanel");
auto from = call->from;
auto contact = ContactsViewModel::instance->findContactByName(from);
if (contact == nullptr) {
WNG_("cannot call the peer, contact not found!");
return;
}
auto item = SmartPanelItemsViewModel::instance->findItem(contact);
if (item == nullptr) {
WNG_("cannot call the peer, smart panel item not found!");
return;
}
call->state = CallStatus::SEARCHING;
MSG_("!--->> should be Searching");
item->_call = call;
});
}
......@@ -256,13 +244,9 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::
return;
}
auto call = item->_call;
auto contact = item->_contact;
if (call) {
auto state = call->state;
if (state == CallStatus::IN_PROGRESS) {
if (item->_callStatus == CallStatus::IN_PROGRESS) {
if (contact) {
contact->_unreadMessages = 0;
ContactsViewModel::instance->saveContactsToFile();
......@@ -271,7 +255,6 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::
summonVideoPage();