Skip to content

Latest commit

 

History

History
169 lines (122 loc) · 5.73 KB

File metadata and controls

169 lines (122 loc) · 5.73 KB

Azure Communication UI Android Library Xamarin Support

This project demonstrates the integration of Communication UI library into Xamarin Forms.

Xamarin Android Sample Application

The sample application has following dependencies.

  • Bindings for azure-communication-common
  • Bindings for azure-communication-ui
  • Packages
    • Slf4jApi (Calling SDK dependency)
    • Xamarin.AndroidX.* (Kotlin)
  • .aar - All these aar's are included in sample application aar folder.
    • azure-communication-calling
    • azure-core-logging
    • dualscreen-layout
    • fluentui_core
    • fluentui_drawer
    • fluentui_listitem
    • fluentui_others
    • fluentui_persona
    • fluentui_transients

Download JAR's/AAR's

Run downloadJarScript.sh and all the required jar/aar's will be downloaded in their specific folders.

After cloning repo, open terminal and navigate to the XamarinAndroidBindings folder and run the following command:

Windows

Windows users can use powershell and run the script as an administator.

./downloadJarScript.sh

Mac

chmod +x downloadJarScript.sh && ./downloadJarScript.sh

Xamarin Android Bindings

To support Xamarin for Calling UI library, the following bindings are required. Bindings are required for .aar when c# code requires to access object.

CommunicationUILibrary - Bindings for Azure Communication UI library. The C# code requires to access CallComposite class from azure-communication-ui-*.aar. This binding has following dependencies.

    <ItemGroup>
        <ProjectReference Include="..\..\CommunicationCommon\CommunicationCommon\CommunicationCommon.csproj">
        <Name>CommunicationCommon</Name>
        </ProjectReference>
        <ProjectReference Include="..\..\CommunicationCore\CommunicationCore\CommunicationCore.csproj">
        <Name>CommunicationCore</Name>
        </ProjectReference>
    </ItemGroup>

CommunicationCommon - Bindings for azure-communication-common-*.aar are required for accessing class CommunicationTokenCredentials in C#. This binding has following dependencies.

    <ItemGroup>
        <EmbeddedReferenceJar Include="Jars\android-retrofuture-1.7.3.jar" />
        <EmbeddedReferenceJar Include="Jars\android-retrostreams-1.7.3.jar" />
    </ItemGroup>
    <ItemGroup>
        <LibraryProjectZip Include="Jars\azure-communication-common-1.0.0.aar" />
    </ItemGroup>

CommunicationCore - Bindings for azure-core-*.aar are required to access ExpandableStringEnum in C#. This binding has following dependencies.

    <ItemGroup>
    <PackageReference Include="Square.OkHttp3">
      <Version>4.9.2.1</Version>
    </PackageReference>
    <PackageReference Include="Square.Retrofit2">
      <Version>2.9.0</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.Android.JakeWharton.ThreeTenAbp">
      <Version>1.3.1</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Annotation">
      <Version>1.2.0.3</Version>
    </PackageReference>
    <PackageReference Include="Xamarin.AndroidX.Lifecycle.Common">
      <Version>2.3.1.3</Version>
    </PackageReference>
  </ItemGroup>
    <ItemGroup>
        <EmbeddedReferenceJar Include="Jars\jackson-annotations-2.11.2.jar" />
        <EmbeddedReferenceJar Include="Jars\jackson-core-2.11.2.jar" />
        <EmbeddedReferenceJar Include="Jars\jackson-databind-2.11.3.jar" />
        <EmbeddedReferenceJar Include="Jars\jackson-dataformat-xml-2.11.2.jar" />
        <EmbeddedReferenceJar Include="Jars\jackson-module-jaxb-annotations-2.11.2.jar" />
    </ItemGroup>

Launching Composite

The Xamarin library supports all the same features as the native UI composite. Developers can launch the composite for a group call using a uuid.

Create Call Composite and Setup Authentication

CallComposite callComposite = new CallCompositeBuilder();

CommunicationTokenCredential credentials = new CommunicationTokenCredential("");

Group Call

CallCompositeGroupCallLocator locator = new CallCompositeGroupCallLocator(UUID.FromString(callID));

CallCompositeRemoteOptions remoteOptions = new CallCompositeRemoteOptions(locator, credentials, name);

callComposite.Launch(MainActivity.Instance, remoteOptions);

Teams interop

CallCompositeTeamsMeetingLinkLocator locator = new CallCompositeTeamsMeetingLinkLocator(callID);

CallCompositeRemoteOptions remoteOptions = new CallCompositeRemoteOptions(locator, credentials, name);

callComposite.Launch(MainActivity.Instance, remoteOptions);

Apply theme configuration

To set theme create style indicated at QuickStart in CommunicationCallingXamarinSampleApp.Android/Resources/values/styles.xml.

Set theme value in Composite.cs.

CallComposite callComposite = compositeBuilder.Theme(
                new Com.Azure.Android.Communication.UI.Configuration.ThemeConfiguration(Resource.Style.MyCompany_CallComposite)).Build();

Error Handling

Create any class implementing ICallingEventHandler and pass object to callComposite.SetOnErrorHandler.

callComposite.SetOnErrorHandler(new EventHandler());

public void Handle(Java.Lang.Object eventArgs)
            {
                if(eventArgs is ErrorEvent)
                {
                    var error = eventArgs as ErrorEvent;
                    Console.WriteLine(error.ErrorCode.ToString());
                }
            }

More information available in QuickStart.