Skip to content

Commit

Permalink
[Feature] Custom Data Model injection feature (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaLai authored May 24, 2022
1 parent 0813e3f commit 048acb1
Show file tree
Hide file tree
Showing 44 changed files with 807 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
A8C69FBD2728AE1C00143DB7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A8C69FBC2728AE1C00143DB7 /* Assets.xcassets */; };
A8C69FC02728AE1C00143DB7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A8C69FBE2728AE1C00143DB7 /* LaunchScreen.storyboard */; };
A8FB819C272A082B00AA0930 /* DemoInputTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8FB819B272A082B00AA0930 /* DemoInputTypes.swift */; };
FA7B53EC282330F2001DFAB8 /* RemoteParticipantAvatarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA7B53EB282330F2001DFAB8 /* RemoteParticipantAvatarHelper.swift */; };
FAA448A0282585F700BD0DC0 /* AzureCommunicationUICalling.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FAA4489F282585F700BD0DC0 /* AzureCommunicationUICalling.framework */; };
FAA448A1282585F700BD0DC0 /* AzureCommunicationUICalling.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FAA4489F282585F700BD0DC0 /* AzureCommunicationUICalling.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
FAA448A42825931500BD0DC0 /* AccessibilityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA448A32825931500BD0DC0 /* AccessibilityIdentifier.swift */; };
FAA448A52825931500BD0DC0 /* AccessibilityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA448A32825931500BD0DC0 /* AccessibilityIdentifier.swift */; };
FAC342F5282F1AA5006CB50B /* AccessibilityIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAA448A32825931500BD0DC0 /* AccessibilityIdentifier.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -100,6 +100,7 @@
A8C69FBF2728AE1C00143DB7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
A8C69FC12728AE1C00143DB7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
A8FB819B272A082B00AA0930 /* DemoInputTypes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoInputTypes.swift; sourceTree = "<group>"; };
FA7B53EB282330F2001DFAB8 /* RemoteParticipantAvatarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteParticipantAvatarHelper.swift; sourceTree = "<group>"; };
FAA4489F282585F700BD0DC0 /* AzureCommunicationUICalling.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = AzureCommunicationUICalling.framework; sourceTree = BUILT_PRODUCTS_DIR; };
FAA448A32825931500BD0DC0 /* AccessibilityIdentifier.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AccessibilityIdentifier.swift; path = ../sdk/AzureCommunicationUICalling/AzureCommunicationUICalling/Utilities/AccessibilityIdentifier.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -211,6 +212,7 @@
A8FB819D272A0B3500AA0930 /* Views */,
5075FE9B27FFA84B00136B34 /* Localization */,
A8849E522732FFA10049FB1A /* AuthenticationHelper.swift */,
FA7B53EB282330F2001DFAB8 /* RemoteParticipantAvatarHelper.swift */,
A8FB819B272A082B00AA0930 /* DemoInputTypes.swift */,
A85DDCB22728B140001297B4 /* ThemeConfig.swift */,
A85DDCAF2728B12D001297B4 /* EnvConfig.swift */,
Expand Down Expand Up @@ -476,7 +478,7 @@
buildActionMask = 2147483647;
files = (
5027C1C72821A55E00DC7131 /* AccessibilityId.swift in Sources */,
FAA448A52825931500BD0DC0 /* AccessibilityIdentifier.swift in Sources */,
FAC342F5282F1AA5006CB50B /* AccessibilityIdentifier.swift in Sources */,
1F18191A27B45050006AF3B3 /* XCUIElementExtension.swift in Sources */,
1F18191727B39F36006AF3B3 /* XCUITestBase.swift in Sources */,
1B0D8DC627F3B1B800F0C47A /* AzureCommunicationUIDemoAppCallTests.swift in Sources */,
Expand All @@ -490,12 +492,12 @@
files = (
A8C69FB42728AE1A00143DB7 /* AppDelegate.swift in Sources */,
A8FB819C272A082B00AA0930 /* DemoInputTypes.swift in Sources */,
FAA448A42825931500BD0DC0 /* AccessibilityIdentifier.swift in Sources */,
A8AC66FE2735A41600632D0B /* CustomControls.swift in Sources */,
A85DDCB92728B23B001297B4 /* SwiftUIDemoView.swift in Sources */,
1F8881CD279B456E001427F0 /* Extension.swift in Sources */,
5027C1C62821A07500DC7131 /* AccessibilityId.swift in Sources */,
A85DDCB12728B12D001297B4 /* EnvConfig.swift in Sources */,
FA7B53EC282330F2001DFAB8 /* RemoteParticipantAvatarHelper.swift in Sources */,
A85DDCB32728B140001297B4 /* ThemeConfig.swift in Sources */,
A85DDCB82728B23B001297B4 /* UIKitDemoViewController.swift in Sources */,
A8C69FB62728AE1A00143DB7 /* SceneDelegate.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class EnvConfigSubject: ObservableObject {
@Published var localeIdentifier: String = ""
@Published var isRightToLeft: Bool = false
@Published var useCustomColors: Bool = false
@Published var useCustomRemoteParticipantViewData: Bool = false
@Published var primaryColor: Color = .blue
@Published var tint10: Color = .blue
@Published var tint20: Color = .blue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//

import Foundation
import AzureCommunicationCommon
import AzureCommunicationUICalling

struct RemoteParticipantAvatarHelper {
private static func getRemoteParticipantId(_ identifier: CommunicationIdentifier) -> String? {
switch identifier {
case is CommunicationUserIdentifier:
return (identifier as? CommunicationUserIdentifier)?.identifier
case is UnknownIdentifier:
return (identifier as? UnknownIdentifier)?.identifier
case is PhoneNumberIdentifier:
return (identifier as? PhoneNumberIdentifier)?.phoneNumber
case is MicrosoftTeamsUserIdentifier:
return (identifier as? MicrosoftTeamsUserIdentifier)?.userId
default:
return nil
}
}

static func didRemoteParticipantsJoin(to callComposite: CallComposite, identifiers: [CommunicationIdentifier]) {
let avatars = ["cat", "fox", "koala", "monkey", "mouse", "octopus"]
for identifier in identifiers {
let id = getRemoteParticipantId(identifier)
let nameIdValue = id != nil ? "\(id?.suffix(4) ?? "")" : ""
var avatarImage: UIImage?
var selectedAvatarName = ""
if let lastSymbol = id?.last,
let index = Int(String(lastSymbol)),
index < avatars.count {
selectedAvatarName = avatars[index]
avatarImage = UIImage(named: selectedAvatarName)
}
let renderDisplayName = selectedAvatarName.isEmpty ? nameIdValue : "\(selectedAvatarName) \(nameIdValue)"
let participantViewData = ParticipantViewData(avatar: avatarImage,
renderDisplayName: renderDisplayName)
callComposite.setRemoteParticipantViewData(for: identifier,
participantViewData: participantViewData)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct SettingsView: View {
Form {
localizationSettings
avatarSettings
remoteParticipantsAvatarsSettings
themeSettings
}.navigationTitle("UI Library - Settings")
}
Expand Down Expand Up @@ -68,6 +69,12 @@ struct SettingsView: View {
}
}

var remoteParticipantsAvatarsSettings: some View {
Section(header: Text("Remote Participants View Data")) {
Toggle("Inject avatars", isOn: $envConfigSubject.useCustomRemoteParticipantViewData)
}
}

var themeSettings: some View {
Section(header: Text("Theme")) {
Toggle("Use Custom Theme Colors", isOn: $envConfigSubject.useCustomColors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,17 @@ extension SwiftUIDemoView {
: Theming(envConfigSubject: envConfigSubject),
localization: localizationConfig)
let callComposite = CallComposite(withOptions: callCompositeOptions)
callComposite.setTarget(didFail: didFail)

let didRemoteParticipantsJoin: ([CommunicationIdentifier]) -> Void = { [weak callComposite] identifiers in
guard let composite = callComposite else {
return
}

self.didRemoteParticipantsJoin(to: composite, identifiers: identifiers)
}
callComposite.setDidFailHandler(with: didFail)
callComposite.setRemoteParticipantJoinHandler(with: didRemoteParticipantsJoin)

let renderDisplayName = envConfigSubject.renderedDisplayName.isEmpty ?
nil:envConfigSubject.renderedDisplayName
let participantViewData = ParticipantViewData(avatar: UIImage(named: envConfigSubject.avatarImageName),
Expand Down Expand Up @@ -234,4 +244,14 @@ extension SwiftUIDemoView {
print("::::SwiftUIDemoView error.code \(error.code)")
showError(for: error.code)
}

func didRemoteParticipantsJoin(to callComposite: CallComposite, identifiers: [CommunicationIdentifier]) {
print("::::SwiftUIDemoView::getEventsHandler::didRemoteParticipantsJoin \(identifiers)")
guard envConfigSubject.useCustomRemoteParticipantViewData else {
return
}

RemoteParticipantAvatarHelper.didRemoteParticipantsJoin(to: callComposite,
identifiers: identifiers)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class UIKitDemoViewController: UIViewController {

private var cancellable = Set<AnyCancellable>()
private var envConfigSubject: EnvConfigSubject
private(set) var callComposite: CallComposite?

private lazy var contentView: UIView = {
let view = UIView()
Expand Down Expand Up @@ -128,8 +129,18 @@ class UIKitDemoViewController: UIViewController {
}

func didFail(_ error: CommunicationUIErrorEvent) {
print("::::UIkitDemoView::getEventsHandler::didFail \(error)")
print("::::UIkitDemoView error.code \(error.code)")
print("::::UIKitDemoView::getEventsHandler::didFail \(error)")
print("::::UIKitDemoView error.code \(error.code)")
}

func didRemoteParticipantsJoin(to callComposite: CallComposite, identifiers: [CommunicationIdentifier]) {
print("::::UIKitDemoView::getEventsHandler::didRemoteParticipantsJoin \(identifiers)")
guard envConfigSubject.useCustomRemoteParticipantViewData else {
return
}

RemoteParticipantAvatarHelper.didRemoteParticipantsJoin(to: callComposite,
identifiers: identifiers)
}

func startExperience(with link: String) {
Expand All @@ -150,13 +161,23 @@ class UIKitDemoViewController: UIViewController {
? CustomColorTheming(envConfigSubject: envConfigSubject)
: Theming(envConfigSubject: envConfigSubject),
localization: localizationConfig)
let callComposite = CallComposite(withOptions: callCompositeOptions)
callComposite = CallComposite(withOptions: callCompositeOptions)
let didRemoteParticipantsJoin: ([CommunicationIdentifier]) -> Void = { [weak callComposite] identifiers in
guard let composite = callComposite else {
return
}
self.didRemoteParticipantsJoin(to: composite, identifiers: identifiers)
}
guard let callComposite = callComposite else {
return
}

callComposite.setTarget(didFail: didFail)
callComposite.setDidFailHandler(with: didFail)
callComposite.setRemoteParticipantJoinHandler(with: didRemoteParticipantsJoin)
let renderDisplayName = envConfigSubject.renderedDisplayName.isEmpty ?
nil : envConfigSubject.renderedDisplayName
let participantViewData = ParticipantViewData(avatar: UIImage(named: envConfigSubject.avatarImageName),
renderDisplayName: renderDisplayName)
renderDisplayName: renderDisplayName)
let localSettings = LocalSettings(participantViewData)

if let communicationTokenCredential = try? getTokenCredential() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@
FAC1FECF27C98FC200D95845 /* InfoHeaderViewModelMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC1FEC827C98FC200D95845 /* InfoHeaderViewModelMocking.swift */; };
FAC1FED027C98FC200D95845 /* BannerTextViewModelMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC1FEC927C98FC200D95845 /* BannerTextViewModelMocking.swift */; };
FAC3128F27F24A8B00A4F1D0 /* IconButtonViewModelMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAC3128E27F24A8B00A4F1D0 /* IconButtonViewModelMocking.swift */; };
FAD845402819C129007DAFE1 /* RemoteParticipantsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD8453F2819C129007DAFE1 /* RemoteParticipantsManager.swift */; };
FAD845422819FC8E007DAFE1 /* RemoteParticipantsManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD845412819FC8E007DAFE1 /* RemoteParticipantsManagerTests.swift */; };
FAD845442819FFE6007DAFE1 /* CallingSDKEventsHandlerMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAD845432819FFE6007DAFE1 /* CallingSDKEventsHandlerMocking.swift */; };
FAFA427D28380F7500053EA7 /* AvatarViewManagerMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAFA427C28380F7500053EA7 /* AvatarViewManagerMocking.swift */; };
FB22A9D340197CA3DC74EEBB /* Pods_AzureCommunicationUICalling.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C580DBF67D8B5AEF7A801F90 /* Pods_AzureCommunicationUICalling.framework */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -500,6 +504,10 @@
FAC1FEC827C98FC200D95845 /* InfoHeaderViewModelMocking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InfoHeaderViewModelMocking.swift; sourceTree = "<group>"; };
FAC1FEC927C98FC200D95845 /* BannerTextViewModelMocking.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BannerTextViewModelMocking.swift; sourceTree = "<group>"; };
FAC3128E27F24A8B00A4F1D0 /* IconButtonViewModelMocking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconButtonViewModelMocking.swift; sourceTree = "<group>"; };
FAD8453F2819C129007DAFE1 /* RemoteParticipantsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteParticipantsManager.swift; sourceTree = "<group>"; };
FAD845412819FC8E007DAFE1 /* RemoteParticipantsManagerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteParticipantsManagerTests.swift; sourceTree = "<group>"; };
FAD845432819FFE6007DAFE1 /* CallingSDKEventsHandlerMocking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallingSDKEventsHandlerMocking.swift; sourceTree = "<group>"; };
FAFA427C28380F7500053EA7 /* AvatarViewManagerMocking.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AvatarViewManagerMocking.swift; path = Mocking/AvatarViewManagerMocking.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -737,6 +745,7 @@
children = (
1F4B0EF7269BD17600E87014 /* CompositeErrorManagerTests.swift */,
881D8F7527FCA8C4008EC897 /* AvatarManagerTests.swift */,
FAD845412819FC8E007DAFE1 /* RemoteParticipantsManagerTests.swift */,
);
path = Manager;
sourceTree = "<group>";
Expand Down Expand Up @@ -803,6 +812,7 @@
1F8E0B77268D0EF000DDD18E /* CompositeErrorManager.swift */,
FA94AF3E27D68DFD001063A6 /* AccessibilityProvider.swift */,
881D8F7327FCA6B3008EC897 /* AvatarViewManager.swift */,
FAD8453F2819C129007DAFE1 /* RemoteParticipantsManager.swift */,
);
path = Manager;
sourceTree = "<group>";
Expand Down Expand Up @@ -1125,6 +1135,8 @@
5A3146B0B684264EB57EDA69 /* ErrorMocking.swift */,
FA62233627DAD9AF008B5466 /* AccessibilityProviderMocking.swift */,
50B390D027D82D7E0010A2ED /* LocalizationProviderMocking.swift */,
FAD845432819FFE6007DAFE1 /* CallingSDKEventsHandlerMocking.swift */,
FAFA427C28380F7500053EA7 /* AvatarViewManagerMocking.swift */,
);
name = Mocking;
sourceTree = "<group>";
Expand Down Expand Up @@ -1475,6 +1487,7 @@
503E361C26CC2D0900158CB4 /* CompositeViewModelFactoryTests.swift in Sources */,
503300FC2706763800289BB5 /* BannerViewModelTests.swift in Sources */,
A869A63F26546A2E003CC4F2 /* VideoViewManagerMocking.swift in Sources */,
FAD845422819FC8E007DAFE1 /* RemoteParticipantsManagerTests.swift in Sources */,
A830C306264C3B6400766E3D /* AppStateReducerTests.swift in Sources */,
88BC24C12832D29D00818446 /* AvatarManagerTests.swift in Sources */,
FAC1FECF27C98FC200D95845 /* InfoHeaderViewModelMocking.swift in Sources */,
Expand Down Expand Up @@ -1514,6 +1527,7 @@
FAC1FECB27C98FC200D95845 /* LocalVideoViewModelMocking.swift in Sources */,
1F91849926B31B640049EF5B /* ActionMocking.swift in Sources */,
50C6DECF270E4F020085D04B /* BannerInfoTypeTests.swift in Sources */,
FAD845442819FFE6007DAFE1 /* CallingSDKEventsHandlerMocking.swift in Sources */,
A8ED232D2645C637008A26B2 /* CallingServiceTests.swift in Sources */,
1F09A11526BA484000BACED7 /* ParticipantGridsViewModelTests.swift in Sources */,
881D8F7027F2327B008EC897 /* ErrorInfoViewModelTests.swift in Sources */,
Expand All @@ -1531,6 +1545,7 @@
5A314750E50CDF6A6F4577E5 /* GroupCallOptionsTests.swift in Sources */,
FAC3128F27F24A8B00A4F1D0 /* IconButtonViewModelMocking.swift in Sources */,
FAC1FECD27C98FC200D95845 /* ParticipantGridCellViewModelMocking.swift in Sources */,
FAFA427D28380F7500053EA7 /* AvatarViewManagerMocking.swift in Sources */,
5A31429C377C213B53F19163 /* DependencyContainerTests.swift in Sources */,
1F09A10426BA472A00BACED7 /* ParticipantInfoModelBuilder.swift in Sources */,
FAC1FECE27C98FC200D95845 /* ParticipantGridViewModelMocking.swift in Sources */,
Expand Down Expand Up @@ -1560,6 +1575,7 @@
1F6470A92639DCFA0008B9E9 /* CallingService.swift in Sources */,
1F83813F26803ADF0096A454 /* CallingReducer.swift in Sources */,
1F2BED64262F86E600D98266 /* SetupView.swift in Sources */,
FAD845402819C129007DAFE1 /* RemoteParticipantsManager.swift in Sources */,
A874EDCC2666DF07003C7D92 /* ContainerUIHostingController.swift in Sources */,
A8810CD8263CC46500C88545 /* NavigationRouter.swift in Sources */,
5054610227C5977A00040467 /* LocalizationProvider.swift in Sources */,
Expand Down
Loading

0 comments on commit 048acb1

Please sign in to comment.