5
5
6
6
import AzureCommunicationUICalling
7
7
import AzureCommunicationCalling
8
+ import AzureCommunicationCommon
8
9
import UIKit
9
10
import SwiftUI
10
11
@@ -108,9 +109,9 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
108
109
}
109
110
resolve ( nil )
110
111
} else {
111
- reject ( DemoError . invalidToken. getErrorCode ( ) ,
112
+ reject ( RNCallCompositeConnectionError . invalidToken. getErrorCode ( ) ,
112
113
" Token is invalid " ,
113
- DemoError . invalidToken)
114
+ RNCallCompositeConnectionError . invalidToken)
114
115
}
115
116
}
116
117
@@ -123,13 +124,13 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
123
124
if let communicationTokenCredential = try ? CommunicationTokenCredential ( withOptions: communicationTokenRefreshOptions) {
124
125
return communicationTokenCredential
125
126
} else {
126
- throw DemoError . invalidToken
127
+ throw RNCallCompositeConnectionError . invalidToken
127
128
}
128
129
} else {
129
130
if let communicationTokenCredential = try ? CommunicationTokenCredential ( token: tokenInput) {
130
131
return communicationTokenCredential
131
132
} else {
132
- throw DemoError . invalidToken
133
+ throw RNCallCompositeConnectionError . invalidToken
133
134
}
134
135
}
135
136
}
@@ -159,9 +160,68 @@ class RNAzureCommunicationUICalling: RCTEventEmitter {
159
160
guard let remoteAvatar = remoteAvatar, let remoteAvatarImage = RCTConvert . uiImage ( remoteAvatar) else {
160
161
return
161
162
}
162
- RemoteParticipantAvatarHelper . onRemoteParticipantJoined ( to: callComposite,
163
+ RNCallCompositeRemoteParticipantAvatarHelper . onRemoteParticipantJoined ( to: callComposite,
163
164
identifiers: identifiers,
164
165
remoteAvatar: remoteAvatarImage)
165
166
}
166
167
}
167
168
}
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
+
0 commit comments