Skip to content

Commit c037f27

Browse files
authored
Merge pull request #9 from Azure-Samples/refactor/DemoErrorAndAvatarHelper
[Refactor] Moved DemoError and RemoteParticipantAvatarHelper in the same bridging file
2 parents ea06c61 + 711eb6c commit c037f27

File tree

4 files changed

+65
-85
lines changed

4 files changed

+65
-85
lines changed

AzureCommunicationUIDemoApp/ios/AzureCommunicationUIDemoApp.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.m */; };
1212
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
1313
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
14-
1B5C13D0287E3A27007CA534 /* RemoteParticipantAvatarHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B5C13CF287E3A27007CA534 /* RemoteParticipantAvatarHelper.swift */; };
1514
1FB5C63A0A000596520ED222 /* Pods_AzureCommunicationUIDemoApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 42C56FDFD33EA711E76AD7E2 /* Pods_AzureCommunicationUIDemoApp.framework */; };
1615
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
1716
980E8BB72792C79B00B08A2B /* RNAzureCommunicationUICalling.swift in Sources */ = {isa = PBXBuildFile; fileRef = 980E8BB62792C79B00B08A2B /* RNAzureCommunicationUICalling.swift */; };
1817
980E8BB92792CD0100B08A2B /* RNAzureCommunicationUICalling.m in Sources */ = {isa = PBXBuildFile; fileRef = 980E8BB82792CD0100B08A2B /* RNAzureCommunicationUICalling.m */; };
19-
98C7EDA62795FDD100FE348A /* DemoError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98C7EDA52795FDD100FE348A /* DemoError.swift */; };
2018
C81489C51CAAC8CF51EA67A7 /* Pods_AzureCommunicationUIDemoApp_AzureCommunicationUIDemoAppTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7C607800A156124E53E8FC73 /* Pods_AzureCommunicationUIDemoApp_AzureCommunicationUIDemoAppTests.framework */; };
2119
/* End PBXBuildFile section */
2220

@@ -40,7 +38,6 @@
4038
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = AzureCommunicationUIDemoApp/Images.xcassets; sourceTree = "<group>"; };
4139
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = AzureCommunicationUIDemoApp/Info.plist; sourceTree = "<group>"; };
4240
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = AzureCommunicationUIDemoApp/main.m; sourceTree = "<group>"; };
43-
1B5C13CF287E3A27007CA534 /* RemoteParticipantAvatarHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteParticipantAvatarHelper.swift; sourceTree = "<group>"; };
4441
1EDE08962FA36EF7A17EC94C /* Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.release.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.release.xcconfig"; sourceTree = "<group>"; };
4542
258596B9858EF9BA08F86452 /* Pods-AzureCommunicationUIDemoApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationUIDemoApp.release.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationUIDemoApp/Pods-AzureCommunicationUIDemoApp.release.xcconfig"; sourceTree = "<group>"; };
4643
31E322F2CC1CEADA4D9EDCAB /* Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.debug.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppTests.debug.xcconfig"; sourceTree = "<group>"; };
@@ -51,7 +48,6 @@
5148
980E8BB52792C79A00B08A2B /* AzureCommunicationUIDemoApp-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "AzureCommunicationUIDemoApp-Bridging-Header.h"; sourceTree = "<group>"; };
5249
980E8BB62792C79B00B08A2B /* RNAzureCommunicationUICalling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RNAzureCommunicationUICalling.swift; sourceTree = "<group>"; };
5350
980E8BB82792CD0100B08A2B /* RNAzureCommunicationUICalling.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNAzureCommunicationUICalling.m; sourceTree = "<group>"; };
54-
98C7EDA52795FDD100FE348A /* DemoError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoError.swift; sourceTree = "<group>"; };
5551
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
5652
/* End PBXFileReference section */
5753

@@ -103,8 +99,6 @@
10399
13B07FB71A68108700A75B9A /* main.m */,
104100
980E8BB82792CD0100B08A2B /* RNAzureCommunicationUICalling.m */,
105101
980E8BB62792C79B00B08A2B /* RNAzureCommunicationUICalling.swift */,
106-
98C7EDA52795FDD100FE348A /* DemoError.swift */,
107-
1B5C13CF287E3A27007CA534 /* RemoteParticipantAvatarHelper.swift */,
108102
980E8BB52792C79A00B08A2B /* AzureCommunicationUIDemoApp-Bridging-Header.h */,
109103
);
110104
name = AzureCommunicationUIDemoApp;
@@ -383,9 +377,7 @@
383377
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
384378
980E8BB72792C79B00B08A2B /* RNAzureCommunicationUICalling.swift in Sources */,
385379
13B07FC11A68108700A75B9A /* main.m in Sources */,
386-
1B5C13D0287E3A27007CA534 /* RemoteParticipantAvatarHelper.swift in Sources */,
387380
980E8BB92792CD0100B08A2B /* RNAzureCommunicationUICalling.m in Sources */,
388-
98C7EDA62795FDD100FE348A /* DemoError.swift in Sources */,
389381
);
390382
runOnlyForDeploymentPostprocessing = 0;
391383
};

AzureCommunicationUIDemoApp/ios/DemoError.swift

Lines changed: 0 additions & 17 deletions
This file was deleted.

AzureCommunicationUIDemoApp/ios/RNAzureCommunicationUICalling.swift

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import AzureCommunicationUICalling
77
import AzureCommunicationCalling
8+
import AzureCommunicationCommon
89
import UIKit
910
import SwiftUI
1011

@@ -108,9 +109,9 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
108109
}
109110
resolve(nil)
110111
} else {
111-
reject(DemoError.invalidToken.getErrorCode(),
112+
reject(RNCallCompositeConnectionError.invalidToken.getErrorCode(),
112113
"Token is invalid",
113-
DemoError.invalidToken)
114+
RNCallCompositeConnectionError.invalidToken)
114115
}
115116
}
116117

@@ -123,13 +124,13 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
123124
if let communicationTokenCredential = try? CommunicationTokenCredential(withOptions: communicationTokenRefreshOptions) {
124125
return communicationTokenCredential
125126
} else {
126-
throw DemoError.invalidToken
127+
throw RNCallCompositeConnectionError.invalidToken
127128
}
128129
} else {
129130
if let communicationTokenCredential = try? CommunicationTokenCredential(token: tokenInput) {
130131
return communicationTokenCredential
131132
} else {
132-
throw DemoError.invalidToken
133+
throw RNCallCompositeConnectionError.invalidToken
133134
}
134135
}
135136
}
@@ -159,9 +160,68 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
159160
guard let remoteAvatar = remoteAvatar, let remoteAvatarImage = RCTConvert.uiImage(remoteAvatar) else {
160161
return
161162
}
162-
RemoteParticipantAvatarHelper.onRemoteParticipantJoined(to: callComposite,
163+
RNCallCompositeRemoteParticipantAvatarHelper.onRemoteParticipantJoined(to: callComposite,
163164
identifiers: identifiers,
164165
remoteAvatar: remoteAvatarImage)
165166
}
166167
}
167168
}
169+
170+
enum RNCallCompositeConnectionError: Error {
171+
case invalidToken
172+
173+
func getErrorCode() -> String {
174+
switch self {
175+
case .invalidToken:
176+
return CallCompositeErrorCode.tokenExpired
177+
}
178+
}
179+
}
180+
181+
struct RNCallCompositeRemoteParticipantAvatarHelper {
182+
private static func getRemoteParticipantId(_ identifier: CommunicationIdentifier) -> String? {
183+
switch identifier {
184+
case is CommunicationUserIdentifier:
185+
return (identifier as? CommunicationUserIdentifier)?.identifier
186+
case is UnknownIdentifier:
187+
return (identifier as? UnknownIdentifier)?.identifier
188+
case is PhoneNumberIdentifier:
189+
return (identifier as? PhoneNumberIdentifier)?.phoneNumber
190+
case is MicrosoftTeamsUserIdentifier:
191+
return (identifier as? MicrosoftTeamsUserIdentifier)?.userId
192+
default:
193+
return nil
194+
}
195+
}
196+
197+
static func onRemoteParticipantJoined(to callComposite: CallComposite,
198+
identifiers: [CommunicationIdentifier],
199+
remoteAvatar: UIImage? = nil) {
200+
let avatars = ["cat", "fox", "koala", "monkey", "mouse", "octopus"]
201+
for identifier in identifiers {
202+
let id = getRemoteParticipantId(identifier)
203+
let nameIdValue = id != nil ? "\(id?.suffix(4) ?? "")" : ""
204+
var avatarImage: UIImage?
205+
var selectedAvatarName = ""
206+
if let lastSymbol = id?.last {
207+
let index = Int((lastSymbol.asciiValue ?? 0 ) % 6)
208+
selectedAvatarName = avatars[index]
209+
avatarImage = UIImage(named: selectedAvatarName)
210+
}
211+
let displayName = selectedAvatarName.isEmpty ? nameIdValue : "\(selectedAvatarName) \(nameIdValue)"
212+
let participantViewData = ParticipantViewData(avatar: remoteAvatar ?? avatarImage,
213+
displayName: displayName)
214+
callComposite.set(remoteParticipantViewData: participantViewData,
215+
for: identifier) { result in
216+
switch result {
217+
case .success:
218+
print("::::RNCallCompositeRemoteParticipantAvatarHelper::onRemoteParticipantJoined::success")
219+
break
220+
case .failure(let error):
221+
print("::::RNCallCompositeRemoteParticipantAvatarHelper::onRemoteParticipantJoined::failure \(error)")
222+
}
223+
}
224+
}
225+
}
226+
}
227+

AzureCommunicationUIDemoApp/ios/RemoteParticipantAvatarHelper.swift

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)