Commit 5750df0d authored by Nicolas Jager's avatar Nicolas Jager

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
parent 652ff7c3
...@@ -25,12 +25,16 @@ using namespace Windows::UI::Core; ...@@ -25,12 +25,16 @@ using namespace Windows::UI::Core;
using namespace RingClientUWP; using namespace RingClientUWP;
// REFACTORING : for the whole Call class, change "from" to "peer"
Call::Call(String^ accountIdz, String^ callIdz, String^ fromz) Call::Call(String^ accountIdz, String^ callIdz, String^ fromz)
{ {
this->accountId = accountIdz; this->accountId = accountIdz;
this->callId = callIdz; this->callId = callIdz;
this->from = fromz; this->from = fromz;
isOutGoing = false; // by default, we consider the call incomming, REFACTO : add this to the constructor params...
this->state = "incoming call"; this->state = "incoming call";
this->code = -1; this->code = -1;
} }
...@@ -64,3 +68,8 @@ void RingClientUWP::Call::accept() ...@@ -64,3 +68,8 @@ void RingClientUWP::Call::accept()
{ {
RingD::instance->acceptIncommingCall(this); RingD::instance->acceptIncommingCall(this);
} }
void RingClientUWP::Call::cancel()
{
RingD::instance->cancelOutGoingCall(this);
}
...@@ -35,6 +35,7 @@ public: ...@@ -35,6 +35,7 @@ public:
property String^ callId; property String^ callId;
property String^ from; property String^ from;
property String^ state; property String^ state;
property bool isOutGoing;
property int code; property int code;
/* events */ /* events */
...@@ -46,6 +47,7 @@ protected: ...@@ -46,6 +47,7 @@ protected:
internal: internal:
void refuse(); void refuse();
void accept(); void accept();
void cancel();
}; };
} }
......
...@@ -33,6 +33,7 @@ CallsViewModel::CallsViewModel() ...@@ -33,6 +33,7 @@ CallsViewModel::CallsViewModel()
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); auto call = addNewCall(accountId, callId, from);
// REFACTO : add if call == nullptr
callRecieved(call); callRecieved(call);
}); });
...@@ -56,9 +57,12 @@ CallsViewModel::CallsViewModel() ...@@ -56,9 +57,12 @@ CallsViewModel::CallsViewModel()
} }
Call^ 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); CallsList_->Append(call);
return call; return call;
} }
......
...@@ -125,6 +125,41 @@ void RingClientUWP::RingD::acceptIncommingCall(Call^ call) ...@@ -125,6 +125,41 @@ void RingClientUWP::RingD::acceptIncommingCall(Call^ call)
tasksList_.push(ref new RingD::Task(Request::AcceptIncommingCall, 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 void
RingClientUWP::RingD::startDaemon() RingClientUWP::RingD::startDaemon()
{ {
...@@ -221,7 +256,13 @@ RingClientUWP::RingD::startDaemon() ...@@ -221,7 +256,13 @@ RingClientUWP::RingD::startDaemon()
ref new DispatchedHandler([=]() { ref new DispatchedHandler([=]() {
reloadAccountList(); reloadAccountList();
})); }));
}) }),
/* to remove from daemon API, this callback is never used */
//DRing::exportable_callback<DRing::CallSignal::NewCallCreated>([&](
// const std::string& accountId,
// const std::string& callId,
// const std::string& to)
//{ /*...*/ })
}; };
registerCallHandlers(callHandlers); registerCallHandlers(callHandlers);
...@@ -313,6 +354,13 @@ RingD::dequeueTasks() ...@@ -313,6 +354,13 @@ RingD::dequeueTasks()
DRing::accept(callId2); DRing::accept(callId2);
} }
break; break;
case Request::CancelOutGoingCall:
{
auto callId = task->_call->callId;
auto callId2 = Utils::toString(callId);
DRing::hangUp(callId2);
}
break;
default: default:
break; break;
} }
......
...@@ -26,6 +26,7 @@ namespace RingClientUWP ...@@ -26,6 +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, String^ state, int code); delegate void StateChange(String^ callId, String^ 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);
public ref class RingD sealed public ref class RingD sealed
...@@ -60,6 +61,8 @@ internal: ...@@ -60,6 +61,8 @@ internal:
void createSIPAccount(String^ alias); void createSIPAccount(String^ alias);
void refuseIncommingCall(Call^ call); void refuseIncommingCall(Call^ call);
void acceptIncommingCall(Call^ call); void acceptIncommingCall(Call^ call);
void placeCall(Contact^ contact);
void cancelOutGoingCall(Call^ call);
/* TODO : move members */ /* TODO : move members */
bool hasConfig; bool hasConfig;
...@@ -69,6 +72,7 @@ internal: ...@@ -69,6 +72,7 @@ internal:
event IncomingCall^ incomingCall; event IncomingCall^ incomingCall;
event StateChange^ stateChange; event StateChange^ stateChange;
event IncomingAccountMessage^ incomingAccountMessage; event IncomingAccountMessage^ incomingAccountMessage;
event Calling^ calling;
private: private:
/* sub classes */ /* sub classes */
...@@ -77,7 +81,8 @@ private: ...@@ -77,7 +81,8 @@ private:
AddRingAccount, AddRingAccount,
AddSIPAccount, AddSIPAccount,
RefuseIncommingCall, RefuseIncommingCall,
AcceptIncommingCall AcceptIncommingCall,
CancelOutGoingCall
}; };
ref class Task ref class Task
{ {
......
...@@ -77,8 +77,8 @@ ...@@ -77,8 +77,8 @@
Grid.Row="0" Grid.Row="0"
Text="{x:Bind name_}"> Text="{x:Bind name_}">
</TextBlock> </TextBlock>
<!-- call status. --> <!-- call status. REFACTO : REMOVE CODE BELOW -->
<StackPanel MaxWidth="240" <!--<StackPanel MaxWidth="240"
MinWidth="240" MinWidth="240"
Grid.Row="1" Grid.Row="1"
HorizontalAlignment="Left"> HorizontalAlignment="Left">
...@@ -88,12 +88,13 @@ ...@@ -88,12 +88,13 @@
Visibility="Visible" Visibility="Visible"
HorizontalAlignment="Center"> HorizontalAlignment="Center">
</TextBlock> </TextBlock>
</StackPanel> </StackPanel>-->
</Grid> </Grid>
</Grid> </Grid>
<!-- REFACTO : REMOVE CODE BELOW -->
<!-- button bar for accept/reject or cancel call. --> <!-- button bar for accept/reject or cancel call. -->
<!-- nb : dont use Visibility with the grid, use the height of the hosting row (_contactBar_). --> <!-- nb : dont use Visibility with the grid, use the height of the hosting row (_contactBar_). -->
<Grid Width="320" <!--<Grid Width="320"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Grid.Row="2" Grid.Row="2"
Background="DarkGray"> Background="DarkGray">
...@@ -111,7 +112,7 @@ ...@@ -111,7 +112,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
Content="Reject"/> Content="Reject"/>
</StackPanel> </StackPanel>
</Grid> </Grid>-->
</Grid> </Grid>
</DataTemplate> </DataTemplate>
<!-- template for accounts. --> <!-- template for accounts. -->
...@@ -149,11 +150,10 @@ ...@@ -149,11 +150,10 @@
Text="{x:Bind ringID_}"/> Text="{x:Bind ringID_}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
<!-- template for calls. --> <!-- template for incoming calls. -->
<DataTemplate x:Key="CallTemplate" x:DataType="local:Call"> <DataTemplate x:Key="IncomingCallTemplate" x:DataType="local:Call">
<Grid Width="320" <Grid Width="320"
HorizontalAlignment="Left" HorizontalAlignment="Left"
Background="DarkGray"> Background="DarkGray">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="30"/> <RowDefinition Height="30"/>
...@@ -182,10 +182,37 @@ ...@@ -182,10 +182,37 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
</DataTemplate> </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. --> <!-- template for smartpanelitems. -->
<DataTemplate x:Key="SmartPanelItemsTemplate" <DataTemplate x:Key="SmartPanelItemsTemplate"
x:DataType="controls:SmartPanelItem"> x:DataType="controls:SmartPanelItem">
<Grid> <Grid PointerEntered="Grid_PointerEntered" PointerExited="Grid_PointerExited">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
<RowDefinition Height="auto"/> <RowDefinition Height="auto"/>
...@@ -193,16 +220,33 @@ ...@@ -193,16 +220,33 @@
<ListBoxItem x:Name="_contactItem_" <ListBoxItem x:Name="_contactItem_"
Padding="0" Padding="0"
Margin="0" Margin="0"
IsHitTestVisible="False"
Grid.Row="0" Grid.Row="0"
PointerReleased="_contactItem__PointerReleased"
ContentTemplate="{StaticResource ContactTemplate}" ContentTemplate="{StaticResource ContactTemplate}"
Content="{x:Bind _contact, Mode=OneWay}"/> Content="{x:Bind _contact, Mode=OneWay}"/>
<ListBoxItem x:Name="_callItem_" <ListBoxItem Grid.Row="1"
Grid.Row="1" Visibility="{x:Bind _IncomingCallBar, Mode=OneWay}"
Visibility="{x:Bind _callBar, Mode=OneWay}" Padding="0"
Margin="0"
ContentTemplate="{StaticResource IncomingCallTemplate}"
Content="{x:Bind _call, Mode=OneWay}"/>
<Button Grid.Row="0"
HorizontalAlignment="Left"
Visibility="{x:Bind _callBar, Mode=OneWay}"
Content="call"
Padding="0"
Click="_callContact__Click"
VerticalAlignment="Bottom"
Margin="10">
<Button.RenderTransform>
<TranslateTransform X="160"/>
</Button.RenderTransform>
</Button>
<ListBoxItem Grid.Row="1"
Visibility="{x:Bind _OutGoingCallBar, Mode=OneWay}"
Padding="0" Padding="0"
Margin="0" Margin="0"
ContentTemplate="{StaticResource CallTemplate}" ContentTemplate="{StaticResource OutGoingCallTemplate}"
Content="{x:Bind _call, Mode=OneWay}"/> Content="{x:Bind _call, Mode=OneWay}"/>
</Grid> </Grid>
</DataTemplate> </DataTemplate>
......
...@@ -93,13 +93,17 @@ SmartPanel::SmartPanel() ...@@ -93,13 +93,17 @@ SmartPanel::SmartPanel()
} }
if (call->state == "incoming call") if (call->state == "incoming call")
item->_callBar = Windows::UI::Xaml::Visibility::Visible; item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Visible;
if (call->state == "CURRENT") if (call->state == "CURRENT") {
item->_callBar = Windows::UI::Xaml::Visibility::Collapsed; item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Collapsed;
item->_OutGoingCallBar = Windows::UI::Xaml::Visibility::Collapsed;
}
if (call->state == "") if (call->state == "") {
item->_callBar = Windows::UI::Xaml::Visibility::Collapsed; item->_IncomingCallBar = Windows::UI::Xaml::Visibility::Collapsed;
item->_OutGoingCallBar = Windows::UI::Xaml::Visibility::Collapsed;
}
}); });
...@@ -109,6 +113,30 @@ SmartPanel::SmartPanel() ...@@ -109,6 +113,30 @@ SmartPanel::SmartPanel()
smartPanelItemsList_->Append(smartPanelItem); 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 void
...@@ -228,13 +256,10 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI:: ...@@ -228,13 +256,10 @@ SmartPanel::_smartList__SelectionChanged(Platform::Object^ sender, Windows::UI::
{ {
auto listbox = safe_cast<ListBox^>(sender); auto listbox = safe_cast<ListBox^>(sender);
auto item = safe_cast<SmartPanelItem^>(listbox->SelectedItem); auto item = safe_cast<SmartPanelItem^>(listbox->SelectedItem);
if (item != nullptr) {
auto contact = safe_cast<Contact^>(item->_contact); Contact^ contact = (item) ? safe_cast<Contact^>(item->_contact) : nullptr;
ContactsViewModel::instance->selectedContact = contact;
} ContactsViewModel::instance->selectedContact = contact;
else {
ContactsViewModel::instance->selectedContact = nullptr;
}
} }
void void
...@@ -269,7 +294,7 @@ void RingClientUWP::Views::SmartPanel::_ringTxtBx__KeyDown(Platform::Object^ sen ...@@ -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) void RingClientUWP::Views::SmartPanel::_rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{ {
auto button = dynamic_cast<Button^>(e->OriginalSource); auto button = dynamic_cast<Button^>(e->OriginalSource);
...@@ -306,4 +331,56 @@ SmartPanel::findItem(Call^ call) ...@@ -306,4 +331,56 @@ SmartPanel::findItem(Call^ call)
return item; return item;
return nullptr; return nullptr;
}
void
SmartPanel::_callContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
auto button = dynamic_cast<Button^>(e->OriginalSource);
auto item = dynamic_cast<SmartPanelItem^>(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<Button^>(e->OriginalSource);
auto call = dynamic_cast<Call^>(button->DataContext);
call->cancel();
}
void RingClientUWP::Views::SmartPanel::Grid_PointerEntered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e)
{
auto grid = dynamic_cast<Grid^>(sender);
auto listBoxItem = dynamic_cast<ListBoxItem^>(sender);
auto item = dynamic_cast<SmartPanelItem^>(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<ListBoxItem^>(sender);
auto grid = dynamic_cast<Grid^>(sender);
auto item = dynamic_cast<SmartPanelItem^>(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<ListBoxItem^>(sender);
auto smartPanelItem = dynamic_cast<SmartPanelItem^>(listBoxItem->DataContext);
if (_smartList_->SelectedItem != smartPanelItem)
_smartList_->SelectedItem = smartPanelItem;
else
_smartList_->SelectedItem = nullptr;
} }
\ No newline at end of file
...@@ -58,6 +58,11 @@ private: ...@@ -58,6 +58,11 @@ private:
void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e); void _ringTxtBx__KeyDown(Platform::Object^ sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
void _rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _rejectIncomingCallBtn__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void _acceptIncomingCallBtn__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 */ /* members */
Vector<Controls::SmartPanelItem^>^ smartPanelItemsList_; Vector<Controls::SmartPanelItem^>^ smartPanelItemsList_;
......
...@@ -42,5 +42,4 @@ SmartPanelItem::NotifyPropertyChanged(String^ propertyName) ...@@ -42,5 +42,4 @@ SmartPanelItem::NotifyPropertyChanged(String^ propertyName)
{ {
PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, ref new PropertyChangedEventArgs(propertyName));
})); }));
} }
\ No newline at end of file
...@@ -31,8 +31,31 @@ public: ...@@ -31,8 +31,31 @@ public:
SmartPanelItem(); SmartPanelItem();
virtual event PropertyChangedEventHandler^ PropertyChanged; virtual event PropertyChangedEventHandler^ PropertyChanged;
property Contact^ _contact; 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 property Visibility _callBar
{ {
Visibility get() Visibility get()
...@@ -62,6 +85,8 @@ protected: ...@@ -62,6 +85,8 @@ protected:
void NotifyPropertyChanged(String^ propertyName); void NotifyPropertyChanged(String^ propertyName);
private: private:
Visibility incomingCallBar_ = Visibility::Collapsed;
Visibility outGoingCallBar_ = Visibility::Collapsed;
Visibility callBar_ = Visibility::Collapsed; Visibility callBar_ = Visibility::Collapsed;
Call^ call_; Call^ call_;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment