From 5750df0dafa3f12279dbe112502d54ee92143c0f Mon Sep 17 00:00:00 2001 From: Nicolas Jager Date: Tue, 13 Sep 2016 11:20:33 -0400 Subject: [PATCH] call : make a call - adds a button in the contact list box item to call it. - adds button and logic to cancel an outgoing call. Change-Id: I74da49acedca9f7ac0c1b62c859823e02ee960cf Tuleap: #1028 --- Call.cpp | 9 ++++ Call.h | 2 + CallsViewModel.cpp | 8 +++- RingD.cpp | 50 ++++++++++++++++++++- RingD.h | 7 ++- SmartPanel.xaml | 72 +++++++++++++++++++++++++------ SmartPanel.xaml.cpp | 103 ++++++++++++++++++++++++++++++++++++++------ SmartPanel.xaml.h | 5 +++ SmartPanelItem.cpp | 3 +- SmartPanelItem.h | 27 +++++++++++- 10 files changed, 252 insertions(+), 34 deletions(-) diff --git a/Call.cpp b/Call.cpp index 6b02ec7..b756033 100644 --- a/Call.cpp +++ b/Call.cpp @@ -25,12 +25,16 @@ using namespace Windows::UI::Core; using namespace RingClientUWP; +// REFACTORING : for the whole Call class, change "from" to "peer" + Call::Call(String^ accountIdz, String^ callIdz, String^ fromz) { this->accountId = accountIdz; this->callId = callIdz; this->from = fromz; + isOutGoing = false; // by default, we consider the call incomming, REFACTO : add this to the constructor params... + this->state = "incoming call"; this->code = -1; } @@ -64,3 +68,8 @@ void RingClientUWP::Call::accept() { RingD::instance->acceptIncommingCall(this); } + +void RingClientUWP::Call::cancel() +{ + RingD::instance->cancelOutGoingCall(this); +} diff --git a/Call.h b/Call.h index c0d4fa1..fb5be0b 100644 --- a/Call.h +++ b/Call.h @@ -35,6 +35,7 @@ public: property String^ callId; property String^ from; property String^ state; + property bool isOutGoing; property int code; /* events */ @@ -46,6 +47,7 @@ protected: internal: void refuse(); void accept(); + void cancel(); }; } diff --git a/CallsViewModel.cpp b/CallsViewModel.cpp index f5dd3d2..41dd4af 100644 --- a/CallsViewModel.cpp +++ b/CallsViewModel.cpp @@ -33,6 +33,7 @@ CallsViewModel::CallsViewModel() RingD::instance->incomingCall += ref new RingClientUWP::IncomingCall([&]( String^ accountId, String^ callId, String^ from) { auto call = addNewCall(accountId, callId, from); + // REFACTO : add if call == nullptr callRecieved(call); }); @@ -56,9 +57,12 @@ CallsViewModel::CallsViewModel() } Call^ -RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ from) +RingClientUWP::ViewModel::CallsViewModel::addNewCall(String^ accountId, String^ callId, String^ peer) { - auto call = ref new Call(accountId, callId, from); + if (accountId == "" | callId == "" | peer == "") { + WNG_("call can't be created"); + } + auto call = ref new Call(accountId, callId, peer); CallsList_->Append(call); return call; } diff --git a/RingD.cpp b/RingD.cpp index b52c2e2..fdf7347 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -125,6 +125,41 @@ void RingClientUWP::RingD::acceptIncommingCall(Call^ call) tasksList_.push(ref new RingD::Task(Request::AcceptIncommingCall, call)); } +void RingClientUWP::RingD::placeCall(Contact^ contact) +{ + auto to = contact->ringID_; + auto accountId = AccountsViewModel::instance->selectedAccount->accountID_; + + auto to2 = Utils::toString(to); + auto accountId2 = Utils::toString(accountId); + + auto callId2 = DRing::placeCall(accountId2, to2); + + if (callId2 == "") { + WNG_("call not created, the daemon didn't return a call Id"); + return; + } + + auto callId = Utils::toPlatformString(callId2); + + 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) +{ + tasksList_.push(ref new RingD::Task(Request::CancelOutGoingCall, call)); +} + void RingClientUWP::RingD::startDaemon() { @@ -221,7 +256,13 @@ RingClientUWP::RingD::startDaemon() ref new DispatchedHandler([=]() { reloadAccountList(); })); - }) + }), + /* to remove from daemon API, this callback is never used */ + //DRing::exportable_callback([&]( + // const std::string& accountId, + // const std::string& callId, + // const std::string& to) + //{ /*...*/ }) }; registerCallHandlers(callHandlers); @@ -313,6 +354,13 @@ RingD::dequeueTasks() DRing::accept(callId2); } break; + case Request::CancelOutGoingCall: + { + auto callId = task->_call->callId; + auto callId2 = Utils::toString(callId); + DRing::hangUp(callId2); + } + break; default: break; } diff --git a/RingD.h b/RingD.h index ceff044..6305151 100644 --- a/RingD.h +++ b/RingD.h @@ -26,6 +26,7 @@ namespace RingClientUWP delegate void IncomingCall(String^ accountId, String^ callId, String^ from); delegate void StateChange(String^ callId, String^ state, int code); delegate void IncomingAccountMessage(String^ accountId, String^ from, String^ payload); +delegate void Calling(Call^ call); public ref class RingD sealed @@ -60,6 +61,8 @@ internal: void createSIPAccount(String^ alias); void refuseIncommingCall(Call^ call); void acceptIncommingCall(Call^ call); + void placeCall(Contact^ contact); + void cancelOutGoingCall(Call^ call); /* TODO : move members */ bool hasConfig; @@ -69,6 +72,7 @@ internal: event IncomingCall^ incomingCall; event StateChange^ stateChange; event IncomingAccountMessage^ incomingAccountMessage; + event Calling^ calling; private: /* sub classes */ @@ -77,7 +81,8 @@ private: AddRingAccount, AddSIPAccount, RefuseIncommingCall, - AcceptIncommingCall + AcceptIncommingCall, + CancelOutGoingCall }; ref class Task { diff --git a/SmartPanel.xaml b/SmartPanel.xaml index 307c9c1..b291d37 100644 --- a/SmartPanel.xaml +++ b/SmartPanel.xaml @@ -77,8 +77,8 @@ Grid.Row="0" Text="{x:Bind name_}"> - - + + - @@ -111,7 +112,7 @@ HorizontalAlignment="Center" Content="Reject"/> - + --> @@ -149,11 +150,10 @@ Text="{x:Bind ringID_}"/> - - + + @@ -182,10 +182,37 @@ + + + + + + + + + + + + diff --git a/SmartPanel.xaml.cpp b/SmartPanel.xaml.cpp index 201a638..0557bd6 100644 --- a/SmartPanel.xaml.cpp +++ b/SmartPanel.xaml.cpp @@ -93,13 +93,17 @@ SmartPanel::SmartPanel() } if (call->state == "incoming call") - item->_callBar = Windows::UI::Xaml::Visibility::Visible; + item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Visible; - if (call->state == "CURRENT") - item->_callBar = Windows::UI::Xaml::Visibility::Collapsed; + if (call->state == "CURRENT") { + item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Collapsed; + item->_OutGoingCallBar = Windows::UI::Xaml::Visibility::Collapsed; + } - if (call->state == "") - item->_callBar = Windows::UI::Xaml::Visibility::Collapsed; + if (call->state == "") { + item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Collapsed; + item->_OutGoingCallBar = Windows::UI::Xaml::Visibility::Collapsed; + } }); @@ -109,6 +113,30 @@ SmartPanel::SmartPanel() smartPanelItemsList_->Append(smartPanelItem); }); + RingD::instance->calling += ref new RingClientUWP::Calling([&]( + Call^ call) { + auto from = call->from; + auto contact = ContactsViewModel::instance->findContactByName(from); + + if (contact == nullptr) { + WNG_("cannot call the peer, contact not found!"); + return; + } + + auto item = findItem(contact); + + if (item == nullptr) { + WNG_("cannot call the peer, smart panel item not found!"); + return; + } + + /* use underscore to differentiate states from UI, we need to think more about states management */ + call->state = "_calling_"; + + item->_OutGoingCallBar = Windows::UI::Xaml::Visibility::Visible; + item->_call = call; + }); + } void @@ -228,13 +256,10 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI:: { auto listbox = safe_cast(sender); auto item = safe_cast(listbox->SelectedItem); - if (item != nullptr) { - auto contact = safe_cast(item->_contact); - ContactsViewModel::instance->selectedContact = contact; - } - else { - ContactsViewModel::instance->selectedContact = nullptr; - } + + Contact^ contact = (item) ? safe_cast(item->_contact) : nullptr; + + ContactsViewModel::instance->selectedContact = contact; } void @@ -269,7 +294,7 @@ void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sen } } - +// REFACTO : change the name IncomingCall if used with OutGoingCall too. void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) { auto button = dynamic_cast(e->OriginalSource); @@ -306,4 +331,56 @@ SmartPanel::findItem(Call^ call) return item; return nullptr; +} + +void +SmartPanel::_callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast(e->OriginalSource); + auto item = dynamic_cast(button->DataContext); + auto contact = item->_contact; + + RingD::instance->placeCall(contact); +} + + +void RingClientUWP::Views::SmartPanel::_cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast(e->OriginalSource); + auto call = dynamic_cast(button->DataContext); + + call->cancel(); +} + + +void RingClientUWP::Views::SmartPanel::Grid_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + auto grid = dynamic_cast(sender); + auto listBoxItem = dynamic_cast(sender); + auto item = dynamic_cast(grid->DataContext); + + item->_callBar = Windows::UI::Xaml::Visibility::Visible; +} + + +void RingClientUWP::Views::SmartPanel::Grid_PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + auto listBoxItem = dynamic_cast(sender); + auto grid = dynamic_cast(sender); + auto item = dynamic_cast(grid->DataContext); + + item->_callBar = Windows::UI::Xaml::Visibility::Collapsed; +} + + +void RingClientUWP::Views::SmartPanel::_contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) +{ + auto listBoxItem = dynamic_cast(sender); + auto smartPanelItem = dynamic_cast(listBoxItem->DataContext); + + if (_smartList_->SelectedItem != smartPanelItem) + _smartList_->SelectedItem = smartPanelItem; + else + _smartList_->SelectedItem = nullptr; + } \ No newline at end of file diff --git a/SmartPanel.xaml.h b/SmartPanel.xaml.h index 9128fe3..2d71204 100644 --- a/SmartPanel.xaml.h +++ b/SmartPanel.xaml.h @@ -58,6 +58,11 @@ private: void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void _rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _acceptIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _cancelCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void Grid_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); + void Grid_PointerExited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); + void _contactItem__PointerReleased(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); /* members */ Vector^ smartPanelItemsList_; diff --git a/SmartPanelItem.cpp b/SmartPanelItem.cpp index 7d91b2a..ab986a6 100644 --- a/SmartPanelItem.cpp +++ b/SmartPanelItem.cpp @@ -42,5 +42,4 @@ SmartPanelItem::NotifyPropertyChanged(String^ propertyName) { PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName)); })); -} - +} \ No newline at end of file diff --git a/SmartPanelItem.h b/SmartPanelItem.h index a651d15..aa5484b 100644 --- a/SmartPanelItem.h +++ b/SmartPanelItem.h @@ -31,8 +31,31 @@ public: SmartPanelItem(); virtual event PropertyChangedEventHandler^ PropertyChanged; - property Contact^ _contact; + property Visibility _IncomingCallBar + { + Visibility get() + { + return incomingCallBar_; + } + void set(Visibility value) + { + incomingCallBar_ = value; + PropertyChanged(this, ref new PropertyChangedEventArgs("_IncomingCallBar")); + } + } + property Visibility _OutGoingCallBar + { + Visibility get() + { + return outGoingCallBar_; + } + void set(Visibility value) + { + outGoingCallBar_ = value; + PropertyChanged(this, ref new PropertyChangedEventArgs("_OutGoingCallBar")); + } + } property Visibility _callBar { Visibility get() @@ -62,6 +85,8 @@ protected: void NotifyPropertyChanged(String^ propertyName); private: + Visibility incomingCallBar_ = Visibility::Collapsed; + Visibility outGoingCallBar_ = Visibility::Collapsed; Visibility callBar_ = Visibility::Collapsed; Call^ call_; }; -- GitLab