From 61e6f0eeaa6d044a1142f2958b2a926bd78082a3 Mon Sep 17 00:00:00 2001 From: Nicolas Jager <nicolas.jager@savoirfairelinux.com> Date: Fri, 4 Nov 2016 15:12:08 -0400 Subject: [PATCH] video : add mute button and logic Change-Id: Ibb60353cabc33cf0e92a662272d9f96ef33e27b8 --- MessageTextPage.xaml | 44 +++++++++++++++++++++++++++------------- MessageTextPage.xaml.cpp | 28 +++++++++++++++++++++++++ MessageTextPage.xaml.h | 2 ++ RingD.cpp | 21 +++++++++++++++++++ RingD.h | 5 +++++ SmartPanelItem.cpp | 7 +++++++ SmartPanelItem.h | 9 ++++++++ VideoPage.xaml | 13 +++++++++++- VideoPage.xaml.cpp | 22 ++++++++++++++++++++ VideoPage.xaml.h | 2 ++ 10 files changed, 138 insertions(+), 15 deletions(-) diff --git a/MessageTextPage.xaml b/MessageTextPage.xaml index dfe3606..7c5562c 100644 --- a/MessageTextPage.xaml +++ b/MessageTextPage.xaml @@ -128,28 +128,44 @@ Padding="10,10"> <Image Source="ms-appx:///contact-avatar-test.png" /> <StackPanel> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*" /> + <ColumnDefinition Width="auto" /> + <ColumnDefinition Width="auto" /> + </Grid.ColumnDefinitions> <TextBlock x:Name="_title_" + Grid.Column="0" Text="[TEXT MISSING]" TextWrapping="NoWrap" VerticalAlignment="Center" FontSize="20" Margin="20,0" /> + <Button x:Name="_audioCall_" + Grid.Column="1" + Click="_audioCall__Click" + Content="audio call"/> + <Button x:Name="_videoCall_" + Click="_videoCall__Click" + Grid.Column="2" + Content="video call"/> + </Grid> <StackPanel Orientation="Horizontal"> - <ComboBox x:Name="_associableAccountsList_"> - <ComboBox.ItemTemplate> - <DataTemplate x:DataType="local:Account"> - <StackPanel Orientation="Horizontal"> - <TextBlock Text="{x:Bind name_, Mode=OneWay}" /> - </StackPanel> - </DataTemplate> - </ComboBox.ItemTemplate> - </ComboBox> - <Button x:Name="_deleteContact_" - Content="delete" - Click="_deleteContact__Click"/> + <ComboBox x:Name="_associableAccountsList_"> + <ComboBox.ItemTemplate> + <DataTemplate x:DataType="local:Account"> + <StackPanel Orientation="Horizontal"> + <TextBlock Text="{x:Bind name_, Mode=OneWay}" /> + </StackPanel> + </DataTemplate> + </ComboBox.ItemTemplate> + </ComboBox> + <Button x:Name="_deleteContact_" + Content="delete" + Click="_deleteContact__Click"/> <Button x:Name="_clearConversation_" - Content="clear conversation" - Click="_clearConversation__Click"/> + Content="clear conversation" + Click="_clearConversation__Click"/> </StackPanel> </StackPanel> diff --git a/MessageTextPage.xaml.cpp b/MessageTextPage.xaml.cpp index 76f57f1..b3f2ebf 100644 --- a/MessageTextPage.xaml.cpp +++ b/MessageTextPage.xaml.cpp @@ -199,3 +199,31 @@ void RingClientUWP::Views::MessageTextPage::_clearConversation__Click(Platform:: contact->_conversation->_messages->Clear(); contact->saveConversationToFile(); } + + +void RingClientUWP::Views::MessageTextPage::_audioCall__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast<Button^>(e->OriginalSource); + if (button) { + auto item = SmartPanelItemsViewModel::instance->_selectedItem; + if (item) { + auto contact = item->_contact; + if (contact) + RingD::instance->placeCall(contact); + } + } +} + + +void RingClientUWP::Views::MessageTextPage::_videoCall__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto button = dynamic_cast<Button^>(e->OriginalSource); + if (button) { + auto item = SmartPanelItemsViewModel::instance->_selectedItem; + if (item) { + auto contact = item->_contact; + if (contact) + RingD::instance->placeCall(contact); + } + } +} diff --git a/MessageTextPage.xaml.h b/MessageTextPage.xaml.h index e8fbf92..8dd8d7d 100644 --- a/MessageTextPage.xaml.h +++ b/MessageTextPage.xaml.h @@ -59,6 +59,8 @@ private: void _deleteContact__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); void _clearConversation__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _audioCall__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void _videoCall__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); }; } } diff --git a/RingD.cpp b/RingD.cpp index 788e6ca..8495a12 100644 --- a/RingD.cpp +++ b/RingD.cpp @@ -29,6 +29,7 @@ #include "account_const.h" #include "string_utils.h" // used to get some const expr like TRUE_STR #include "gnutls\gnutls.h" +#include "media_const.h" // used to get some const expr like MEDIA_TYPE_VIDEO #include "SmartPanel.xaml.h" @@ -582,6 +583,8 @@ RingClientUWP::RingD::startDaemon() Utils::toPlatformString(id), width, height); + auto callId2 = Utils::toPlatformString(id); + incomingVideoMuted(callId2, false); })); }), DRing::exportable_callback<DRing::VideoSignal::DecodingStopped> @@ -589,6 +592,8 @@ RingClientUWP::RingD::startDaemon() dispatcher->RunAsync(CoreDispatcherPriority::High, ref new DispatchedHandler([=]() { Video::VideoManager::instance->rendererManager()->removeRenderer(Utils::toPlatformString(id)); + auto callId2 = Utils::toPlatformString(id); + incomingVideoMuted(callId2, true); })); }) }; @@ -879,6 +884,12 @@ RingD::dequeueTasks() debugModeOn_ = !debugModeOn_; break; } + case Request::MuteVideo: + { + auto callId = Utils::toString(task->_callId); + bool muted = task->_muted; + DRing::muteLocalMedia(callId, DRing::Media::Details::MEDIA_TYPE_VIDEO, muted); + } default: break; } @@ -922,6 +933,16 @@ void RingClientUWP::RingD::switchDebug() tasksList_.push(task); } +void RingClientUWP::RingD::muteVideo(String ^ callId, bool muted) +{ + auto task = ref new RingD::Task(Request::MuteVideo); + + task->_callId = callId; + task->_muted = muted; + + tasksList_.push(task); +} + RingClientUWP::CallStatus RingClientUWP::RingD::translateCallStatus(String^ state) { if (state == "INCOMING") diff --git a/RingD.h b/RingD.h index d46fcbc..f3f52ac 100644 --- a/RingD.h +++ b/RingD.h @@ -36,6 +36,7 @@ delegate void DevicesListRefreshed(Vector<String^>^ devicesList); delegate void ExportOnRingEnded(String^ accountId, String^ pin); delegate void SummonWizard(); delegate void AccountUpdated(Account^ account); +delegate void IncomingVideoMuted(String^ callId, bool state); public ref class RingD sealed @@ -102,6 +103,7 @@ internal: void getCallsList(); void killCall(String^ callId); void switchDebug(); + void muteVideo(String^ callId, bool muted); /* TODO : move members */ String ^ currentCallId; // to save ongoing call id during visibility change @@ -116,6 +118,7 @@ internal: event ExportOnRingEnded^ exportOnRingEnded; event SummonWizard^ summonWizard; event AccountUpdated^ accountUpdated; + event IncomingVideoMuted^ incomingVideoMuted; private: /* sub classes */ @@ -137,6 +140,7 @@ private: GetCallsList, KillCall, switchDebug, + MuteVideo }; @@ -168,6 +172,7 @@ private: property String^ _sipPassword; property String^ _sipHostname; property String^ _sipUsername; + property bool _muted; }; /* functions */ diff --git a/SmartPanelItem.cpp b/SmartPanelItem.cpp index ebf3eee..be4254b 100644 --- a/SmartPanelItem.cpp +++ b/SmartPanelItem.cpp @@ -32,10 +32,17 @@ using namespace ViewModel; SmartPanelItem::SmartPanelItem() { _callId = ""; + videoMuted_ = false; RingD::instance->callPlaced += ref new RingClientUWP::CallPlaced(this, &RingClientUWP::Controls::SmartPanelItem::OncallPlaced); } +void RingClientUWP::Controls::SmartPanelItem::muteVideo(bool state) +{ + videoMuted_ = state; + RingD::instance->muteVideo(_callId, state); +} + void SmartPanelItem::NotifyPropertyChanged(String^ propertyName) { diff --git a/SmartPanelItem.h b/SmartPanelItem.h index ded98ea..a952378 100644 --- a/SmartPanelItem.h +++ b/SmartPanelItem.h @@ -29,6 +29,7 @@ public ref class SmartPanelItem sealed : public INotifyPropertyChanged { public: SmartPanelItem(); + void muteVideo(bool state); virtual event PropertyChangedEventHandler^ PropertyChanged; property Contact^ _contact; @@ -74,6 +75,13 @@ public: NotifyPropertyChanged("_callStatus"); } } + property bool _videoMuted + { + bool get() + { + return videoMuted_; + } + } protected: void NotifyPropertyChanged(String^ propertyName); @@ -82,6 +90,7 @@ private: Visibility hovered_ = Visibility::Collapsed; CallStatus callStatus_; String^ callId_; + bool videoMuted_; void OncallPlaced(Platform::String ^callId); }; diff --git a/VideoPage.xaml b/VideoPage.xaml index ce28b48..79fdecc 100644 --- a/VideoPage.xaml +++ b/VideoPage.xaml @@ -155,6 +155,16 @@ <Image Name="IncomingVideoImage" Grid.Column="0" Canvas.ZIndex="-1"/> + <TextBlock Name="_MutedVideoIcon_" + Grid.Column="0" + Text="" + Foreground="White" + FontSize="200" + VerticalAlignment="Center" + HorizontalAlignment="Center" + FontFamily="Segoe MDL2 Assets" + Visibility="Collapsed" + Canvas.ZIndex="-1"/> <!--camera preview--> <CaptureElement Name="PreviewImage" @@ -300,7 +310,8 @@ <Button x:Name="_btnVideo_" PointerEntered="btnAny_entered" PointerExited="btnAny_exited" - Tapped="_btnVideo__Tapped" Visibility="Collapsed"> + Click="_btnVideo__Click" + Tapped="_btnVideo__Tapped"> <SymbolIcon Symbol="Video"/> </Button> <Button x:Name="_btnMemo_" diff --git a/VideoPage.xaml.cpp b/VideoPage.xaml.cpp index ab004b8..d4be80c 100644 --- a/VideoPage.xaml.cpp +++ b/VideoPage.xaml.cpp @@ -41,6 +41,7 @@ using namespace Windows::UI::Xaml::Navigation; using namespace Windows::Media::Capture; using namespace Windows::ApplicationModel::Core; using namespace Windows::UI::Core; +using namespace Windows::UI; using namespace Windows::Graphics::Display; using namespace Windows::Graphics::Imaging; @@ -130,6 +131,7 @@ VideoPage::VideoPage() }); RingD::instance->incomingMessage += ref new RingClientUWP::IncomingMessage(this, &RingClientUWP::Views::VideoPage::OnincomingMessage); + RingD::instance->incomingVideoMuted += ref new RingClientUWP::IncomingVideoMuted(this, &RingClientUWP::Views::VideoPage::OnincomingVideoMuted); } void @@ -346,3 +348,23 @@ void RingClientUWP::Views::VideoPage::OnincomingMessage(Platform::String ^callId { scrollDown(); } + + +void RingClientUWP::Views::VideoPage::_btnVideo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e) +{ + auto item = SmartPanelItemsViewModel::instance->_selectedItem; + + item->muteVideo(!item->_videoMuted); +} + + +void RingClientUWP::Views::VideoPage::OnincomingVideoMuted(Platform::String ^callId, bool state) +{ + /*_MutedVideoIcon_->Visibility = (state) + ? Windows::UI::Xaml::Visibility::Visible + : Windows::UI::Xaml::Visibility::Collapsed;*/ + + IncomingVideoImage->Visibility = (state) + ? Windows::UI::Xaml::Visibility::Collapsed + : Windows::UI::Xaml::Visibility::Visible; +} diff --git a/VideoPage.xaml.h b/VideoPage.xaml.h index e92e97a..48c82d7 100644 --- a/VideoPage.xaml.h +++ b/VideoPage.xaml.h @@ -116,6 +116,8 @@ private: void btnAny_entered(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); void btnAny_exited(Platform::Object^ sender, Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); void OnincomingMessage(Platform::String ^callId, Platform::String ^payload); + void _btnVideo__Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void OnincomingVideoMuted(Platform::String ^callId, bool state); }; } } \ No newline at end of file -- GitLab