From aca479888a8a4a8f4eea3065e3fdf380f8a31582 Mon Sep 17 00:00:00 2001 From: Thibault Lemaire Date: Thu, 23 Dec 2021 16:49:01 +0100 Subject: [PATCH] Give the UWP Tutorial a little refresher In order to write an equivalent tutorial for Xamarin, I am first following the UWP tutorial. Fixed many little spelling mistakes and rephrased some sentences. Fixed a crash when video is requested but the device has no camera. Fixed a crash when opening an audio recording. (Linphone.Content.FilePath returns a path with mixed '/' and '\'. I don't know why and I'm not sure I understand why the file was auto-downloaded either) --- uwp/cs/.editorconfig | 13 ++++ uwp/cs/00_HelloWorld/00_HelloWorld.csproj | 7 +- uwp/cs/00_HelloWorld/MainPage.xaml.cs | 10 +-- uwp/cs/00_HelloWorld/Readme.md | 12 ++-- uwp/cs/01_AccountLogin/01_AccountLogin.csproj | 4 +- uwp/cs/01_AccountLogin/MainPage.xaml.cs | 19 ++++-- uwp/cs/01_AccountLogin/Readme.md | 12 ++-- uwp/cs/02_IncomingCall/02_IncomingCall.csproj | 4 +- uwp/cs/02_IncomingCall/Readme.md | 22 +++---- uwp/cs/02_IncomingCall/Service/CoreService.cs | 8 +-- uwp/cs/02_IncomingCall/Views/CallsPage.xaml | 4 +- .../02_IncomingCall/Views/CallsPage.xaml.cs | 40 ++++++------ .../Views/NavigationRoot.xaml.cs | 13 ++-- uwp/cs/03_OutgoingCall/03_OutgoingCall.csproj | 4 +- uwp/cs/03_OutgoingCall/Readme.md | 8 ++- uwp/cs/03_OutgoingCall/Service/CoreService.cs | 41 ++++++------ .../03_OutgoingCall/Service/VideoService.cs | 2 +- uwp/cs/03_OutgoingCall/Views/CallsPage.xaml | 2 +- .../03_OutgoingCall/Views/CallsPage.xaml.cs | 53 +++++++-------- .../Views/NavigationRoot.xaml.cs | 20 +++--- uwp/cs/04_BasicChat/04_BasicChat.csproj | 4 +- uwp/cs/04_BasicChat/Readme.md | 17 ++--- uwp/cs/04_BasicChat/Service/CoreService.cs | 30 +++++---- uwp/cs/04_BasicChat/Views/CallsPage.xaml | 2 +- uwp/cs/04_BasicChat/Views/CallsPage.xaml.cs | 33 +++++----- uwp/cs/04_BasicChat/Views/ChatPage.xaml.cs | 25 ++++---- uwp/cs/04_BasicChat/Views/ChatsPage.xaml.cs | 64 ++++++++++--------- .../04_BasicChat/Views/NavigationRoot.xaml.cs | 42 ++++++------ uwp/cs/05_FileTransfer/05_FileTransfer.csproj | 4 +- .../Controls/MessageDisplay.xaml | 2 +- .../Controls/MessageDisplay.xaml.cs | 33 +++++----- uwp/cs/05_FileTransfer/Readme.md | 14 ++-- uwp/cs/05_FileTransfer/Service/CoreService.cs | 44 +++++++------ uwp/cs/05_FileTransfer/Views/CallsPage.xaml | 2 +- .../05_FileTransfer/Views/CallsPage.xaml.cs | 33 +++++----- uwp/cs/05_FileTransfer/Views/ChatPage.xaml.cs | 12 ++-- .../Views/NavigationRoot.xaml.cs | 21 +++--- uwp/cs/06_GroupChat/06_GroupChat.csproj | 4 +- .../06_GroupChat/Controls/ContentDisplay.xaml | 2 +- .../Controls/ContentDisplay.xaml.cs | 17 +++-- .../Controls/EventDisplay.xaml.cs | 16 ++--- .../Controls/GroupChatDisplay.xaml.cs | 24 +++---- .../Controls/MessageDisplay.xaml.cs | 14 ++-- uwp/cs/06_GroupChat/Readme.md | 27 ++++---- uwp/cs/06_GroupChat/Service/CoreService.cs | 56 ++++++++-------- .../Shared/ChatRoomToStringConverter.cs | 4 +- uwp/cs/06_GroupChat/Views/CallsPage.xaml | 2 +- uwp/cs/06_GroupChat/Views/CallsPage.xaml.cs | 33 +++++----- uwp/cs/06_GroupChat/Views/ChatPage.xaml.cs | 10 +-- uwp/cs/06_GroupChat/Views/ChatsPage.xaml.cs | 10 +-- .../Views/CreateGroupChatRoom.xaml.cs | 18 +++--- .../06_GroupChat/Views/NavigationRoot.xaml.cs | 19 +++--- uwp/cs/07_AdvancedChat/07_AdvancedChat.csproj | 4 +- .../Controls/MessageDisplay.xaml.cs | 19 ++++-- uwp/cs/07_AdvancedChat/Readme.md | 15 ++--- uwp/cs/07_AdvancedChat/Service/CoreService.cs | 57 ++++++++--------- .../Shared/ChatRoomToStringConverter.cs | 2 +- uwp/cs/07_AdvancedChat/Views/CallsPage.xaml | 2 +- .../07_AdvancedChat/Views/CallsPage.xaml.cs | 33 +++++----- uwp/cs/07_AdvancedChat/Views/ChatPage.xaml.cs | 37 ++++++----- .../07_AdvancedChat/Views/ChatsPage.xaml.cs | 4 +- .../Views/NavigationRoot.xaml.cs | 27 +++----- uwp/cs/Readme.md | 46 ++++++++----- uwp/cs/TutorialsCS.sln | 1 + 64 files changed, 600 insertions(+), 583 deletions(-) create mode 100644 uwp/cs/.editorconfig diff --git a/uwp/cs/.editorconfig b/uwp/cs/.editorconfig new file mode 100644 index 0000000..d48aaea --- /dev/null +++ b/uwp/cs/.editorconfig @@ -0,0 +1,13 @@ +indent_style = tabs +indent_size = 4 + +[*.cs] + +# IDE0008: Use explicit type +csharp_style_var_when_type_is_apparent = true + +# IDE0008: Use explicit type +csharp_style_var_for_built_in_types = true + +# IDE0008: Use explicit type +csharp_style_var_elsewhere = true diff --git a/uwp/cs/00_HelloWorld/00_HelloWorld.csproj b/uwp/cs/00_HelloWorld/00_HelloWorld.csproj index 0327b75..f55ab21 100644 --- a/uwp/cs/00_HelloWorld/00_HelloWorld.csproj +++ b/uwp/cs/00_HelloWorld/00_HelloWorld.csproj @@ -151,13 +151,16 @@ - 5.1.0-alpha.56 + 5.1.0 - 6.2.11 + 6.2.13 + + .editorconfig + diff --git a/uwp/cs/00_HelloWorld/MainPage.xaml.cs b/uwp/cs/00_HelloWorld/MainPage.xaml.cs index 434dc16..7854be5 100644 --- a/uwp/cs/00_HelloWorld/MainPage.xaml.cs +++ b/uwp/cs/00_HelloWorld/MainPage.xaml.cs @@ -63,16 +63,16 @@ namespace _00_HelloWorld factory.MspluginsDir = "."; // Your Core can use up to 2 configuration files, but that isn't mandatory. - // The third parameter is the application context, he isn't mandatory when working - // with UWP, he is mandatory in an Android context for example. + // The third parameter is the application context, which is *not* mandatory when working + // with UWP, but *is* mandatory in an Android context for example. // You can now create your Core object : Core core = factory.CreateCore("", "", IntPtr.Zero); - // Once you got your core you can start to do a lot of things. + // Once you have your core you can start to do a lot of things. HelloText += Core.Version; - // You should store the Core to keep a reference on it at all times while your app is alive. - // A good solution for that is either subclass the Application object or create a Service. + // You should store the Core to keep a reference to it at all times while your app is alive. + // A good solution for that is to either subclass the Application object or create a Service. StoredCore = core; } diff --git a/uwp/cs/00_HelloWorld/Readme.md b/uwp/cs/00_HelloWorld/Readme.md index 4ff2ab0..77da422 100644 --- a/uwp/cs/00_HelloWorld/Readme.md +++ b/uwp/cs/00_HelloWorld/Readme.md @@ -1,19 +1,15 @@ Linphone X UWP tutorial 00_HelloWorld ====================================== -The first tutorial is just here to display a hello world app with the current Linphone's version number. - -Don't forget to install those NuGet packages : - - LinphoneSDK (can be found here : https://www.linphone.org/snapshots/windows/sdk/) - - Microsoft.NETCore.UniversalWindowsPlatform (version 6.2.12 recommended) +The first tutorial is just a hello world app displaying the current SDK version number. Main files : ``` 00_HelloWorld -│ README.md : you are here +│ README.md : you are here │ App.xaml(.cs) : Default Windows Application file, nothing special here -│ MainPage.xaml(.cs) : This is were the magic happen, -│ jump into this file to learn about Linphone core creation and how to display a hello world. +│ MainPage.xaml(.cs) : This is were the magic happens, +│ jump into this file to learn the basics of how to setup your app to use Linphone by creating the Core object. │ └───Assets : default UWP app assets │ LockScreenLogo.scale-200.png diff --git a/uwp/cs/01_AccountLogin/01_AccountLogin.csproj b/uwp/cs/01_AccountLogin/01_AccountLogin.csproj index b558eef..655445c 100644 --- a/uwp/cs/01_AccountLogin/01_AccountLogin.csproj +++ b/uwp/cs/01_AccountLogin/01_AccountLogin.csproj @@ -151,10 +151,10 @@ - 5.1.0-alpha.56 + 5.1.0 - 6.2.11 + 6.2.13 diff --git a/uwp/cs/01_AccountLogin/MainPage.xaml.cs b/uwp/cs/01_AccountLogin/MainPage.xaml.cs index 2a135be..453f73a 100644 --- a/uwp/cs/01_AccountLogin/MainPage.xaml.cs +++ b/uwp/cs/01_AccountLogin/MainPage.xaml.cs @@ -66,17 +66,18 @@ namespace _01_AccountLogin StoredCore = core; - // We need to indicate to the core where are stored the root ans user certificates, for future TLS exchange. + // We need to indicate to the core where to find the root and user certificates, for future TLS exchange. StoredCore.RootCa = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, "share", "Linphone", "rootca.pem"); StoredCore.UserCertificatesPath = ApplicationData.Current.LocalFolder.Path; - // In this tutorials we are going to log in and our registration state will change. + // In this tutorial we are going to log in and our registration state will change. // Here we show you how to register a delegate method called every time the - // on OnAccountRegistrationStateChanged callback is triggered. + // OnAccountRegistrationStateChanged callback is triggered. StoredCore.Listener.OnAccountRegistrationStateChanged += OnAccountRegistrationStateChanged; // Start the core after setup, and before everything else. StoredCore.Start(); + StoredCore.AutoIterateEnabled = true; // The method Iterate must be permanently called on our core. // The Iterate method runs all the waiting backgrounds tasks and poll networks notifications. @@ -135,7 +136,17 @@ namespace _01_AccountLogin // We also need to configure where the proxy server is located Address serverAddr = Factory.Instance.CreateAddress("sip:" + address.Domain); // We use the Address object to easily set the transport protocol - serverAddr.Transport = TlsRadio.IsChecked ?? false ? TransportType.Tls : TcpRadio.IsChecked ?? false ? TransportType.Tcp : TransportType.Udp; + if (TlsRadio.IsChecked == true) { + serverAddr.Transport = TransportType.Tls; + } + else if (TcpRadio.IsChecked == true) + { + serverAddr.Transport = TransportType.Tcp; + } + else + { + serverAddr.Transport = TransportType.Udp; + } accountParams.ServerAddress = serverAddr; // If RegisterEnabled is set to true, when this account will be added to the core it will // automatically try to connect. diff --git a/uwp/cs/01_AccountLogin/Readme.md b/uwp/cs/01_AccountLogin/Readme.md index b277949..cd927b2 100644 --- a/uwp/cs/01_AccountLogin/Readme.md +++ b/uwp/cs/01_AccountLogin/Readme.md @@ -1,17 +1,13 @@ Linphone X UWP tutorial 01_AccountLogin ================================ -In this tutorial we present you the different steps to login and logout a SIP account. +This project will walk you through the different steps of logging in and out of a SIP account. -To first register an account go here : https://www.linphone.org/freesip/home - -Don't forget to install those NuGet packages : - - LinphoneSDK (can be found here : https://www.linphone.org/snapshots/windows/sdk/) - - Microsoft.NETCore.UniversalWindowsPlatform (version 6.2.12 recommended) +If you do not yet have a SIP account, please create one here : https://www.linphone.org/freesip/home New/updated files to watch : ``` 01_AccountLogin -│ MainPage.xaml(.cs) : This time this page is a minimalist login page and it display your login status. -│ Watch its code to understand how to login/out with LinphoneSDK. +│ MainPage.xaml(.cs) : This was changed to a minimalist login page and displays your login status. +│ take a look at the code to understand how to login/out with LinphoneSDK. ``` \ No newline at end of file diff --git a/uwp/cs/02_IncomingCall/02_IncomingCall.csproj b/uwp/cs/02_IncomingCall/02_IncomingCall.csproj index 2e581c5..90ef382 100644 --- a/uwp/cs/02_IncomingCall/02_IncomingCall.csproj +++ b/uwp/cs/02_IncomingCall/02_IncomingCall.csproj @@ -169,10 +169,10 @@ 2.1.13 - 5.1.0-alpha.56 + 5.1.0 - 6.2.11 + 6.2.13 diff --git a/uwp/cs/02_IncomingCall/Readme.md b/uwp/cs/02_IncomingCall/Readme.md index 9e8151a..3dd9acc 100644 --- a/uwp/cs/02_IncomingCall/Readme.md +++ b/uwp/cs/02_IncomingCall/Readme.md @@ -3,20 +3,16 @@ This time we are going to receive our first calls ! -Because the architecture of the first two tutorials were a bit too simple for a larger app we moved things a bit. -All the code about the core (creation, iterate, log in...) is now in the class Service/CoreService. +The architecture of the first two tutorials was a bit simple for a larger app, so we moved things a bit. +All the core-related code (creation, iterate, log in...) is now in the class Service/CoreService. -The page LoginPage is updated and now redirects to a new page (NavigationRoot) this page only contains a NavigationView. -If you are note familiar with NavigationView you can take a look at [the NavigationView doc](https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/navigationview), +The LoginPage now redirects to a new page (NavigationRoot) this page only contains a NavigationView. +If you are unfamiliar with NavigationView you can take a look at [the NavigationView doc](https://docs.microsoft.com/en-us/windows/uwp/design/controls-and-patterns/navigationview), but this is not mandatory since it contains no Linphone code and is only here for navigation. -By default the NavigationView load the new page CallsPage (the only one for now), on this page you can answer or decline incoming calls. +By default the NavigationView loads the new CallsPage (the only one for now), on this page you can answer or decline incoming calls. -If you don't have SIP friends to make tests we recommend you to install Linphone on your mobile device (Android or iOS) and to make calls to yourself. - -Don't forget to install those NuGet packages : - - LinphoneSDK (can be found here : https://www.linphone.org/snapshots/windows/sdk/) - - Microsoft.NETCore.UniversalWindowsPlatform (version 6.2.12 recommended) +If you don't have SIP friends to test with, you can also install Linphone on your mobile device (Android or iOS) and call yourself with a different account. New/updated files : @@ -33,10 +29,10 @@ New/updated files : │ │ └───Views : -│ │ CallsPage.xaml(.cs) : This is the new page where you can make calls. -│ │ This is where you will find the new Linphone's uses. +│ │ CallsPage.xaml(.cs) : This is the new page from which you can make calls. +│ │ Also contains new Linphone-related code. │ │ -│ │ LoginPage.xaml(.cs) : The same login page as the previous step, now in his own file. +│ │ LoginPage.xaml(.cs) : The same login page as the previous step, now in its own file. │ │ │ │ NavigationRoot.xaml(.cs) : The new page containing the NavigationView and the main app Frame. │ diff --git a/uwp/cs/02_IncomingCall/Service/CoreService.cs b/uwp/cs/02_IncomingCall/Service/CoreService.cs index 6be1a82..8a8d927 100644 --- a/uwp/cs/02_IncomingCall/Service/CoreService.cs +++ b/uwp/cs/02_IncomingCall/Service/CoreService.cs @@ -148,9 +148,9 @@ namespace _02_IncomingCall.Service /// /// Mute/Unmute your microphone. - /// Set MicEnabled=false on the Core mute your microphone globally. + /// Setting MicEnabled=false on the Core mutes your microphone globally. /// - public bool MicEnabledSwitch() + public bool ToggleMic() { // The following toggles the microphone, disabling completely / enabling the sound capture from the device microphone return Core.MicEnabled = !Core.MicEnabled; @@ -158,9 +158,9 @@ namespace _02_IncomingCall.Service /// /// Enable/Disable the speaker sound. - /// Set SpeakerMuted=true on a Call object to disable the sound of this call. + /// Setting SpeakerMuted=true on a Call object disables the sound output of this call. /// - public bool SpeakerMutedSwitch() + public bool ToggleSpeaker() { return Core.CurrentCall.SpeakerMuted = !Core.CurrentCall.SpeakerMuted; } diff --git a/uwp/cs/02_IncomingCall/Views/CallsPage.xaml b/uwp/cs/02_IncomingCall/Views/CallsPage.xaml index c74bda8..9aa121e 100644 --- a/uwp/cs/02_IncomingCall/Views/CallsPage.xaml +++ b/uwp/cs/02_IncomingCall/Views/CallsPage.xaml @@ -25,7 +25,7 @@ -