33
44package com .azure .communication .callingserver ;
55
6- import static com .azure .core .util .FluxUtil .monoError ;
7- import static com .azure .core .util .FluxUtil .withContext ;
8-
9- import java .util .Objects ;
10-
116import com .azure .communication .callingserver .implementation .CallConnectionsImpl ;
12- import com .azure .communication .callingserver .implementation .converters .InviteParticipantRequestConverter ;
13- import com .azure .communication .callingserver .implementation .converters .CancelAllMediaOperationsResultConverter ;
147import com .azure .communication .callingserver .implementation .converters .CallingServerErrorConverter ;
8+ import com .azure .communication .callingserver .implementation .converters .CancelAllMediaOperationsResultConverter ;
9+ import com .azure .communication .callingserver .implementation .converters .AddParticipantRequestConverter ;
1510import com .azure .communication .callingserver .implementation .converters .PlayAudioResultConverter ;
16- import com .azure .communication .callingserver .implementation .models .CommunicationErrorException ;
11+ import com .azure .communication .callingserver .implementation .models .AddParticipantRequest ;
1712import com .azure .communication .callingserver .implementation .models .CancelAllMediaOperationsRequest ;
18- import com .azure .communication .callingserver .implementation .models .InviteParticipantsRequest ;
13+ import com .azure .communication .callingserver .implementation .models .CommunicationErrorResponseException ;
1914import com .azure .communication .callingserver .implementation .models .PlayAudioRequest ;
15+ import com .azure .communication .callingserver .models .AddParticipantResult ;
2016import com .azure .communication .callingserver .models .CancelAllMediaOperationsResult ;
2117import com .azure .communication .callingserver .models .PlayAudioOptions ;
2218import com .azure .communication .callingserver .models .PlayAudioResult ;
2723import com .azure .core .http .rest .SimpleResponse ;
2824import com .azure .core .util .Context ;
2925import com .azure .core .util .logging .ClientLogger ;
30-
3126import reactor .core .publisher .Mono ;
3227
28+ import java .util .Objects ;
29+
30+ import static com .azure .core .util .FluxUtil .monoError ;
31+ import static com .azure .core .util .FluxUtil .withContext ;
32+
3333/**
3434 * Async client that supports call connection operations.
3535 */
@@ -132,7 +132,7 @@ Mono<PlayAudioResult> playAudioInternal(String audioFileUri, PlayAudioOptions pl
132132 Mono <PlayAudioResult > playAudioInternal (PlayAudioRequest playAudioRequest ) {
133133 try {
134134 return callConnectionInternal .playAudioAsync (callConnectionId , playAudioRequest )
135- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException )
135+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
136136 .flatMap (result -> Mono .just (PlayAudioResultConverter .convert (result )));
137137 } catch (RuntimeException ex ) {
138138 return monoError (logger , ex );
@@ -236,7 +236,7 @@ Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
236236 contextValue = context == null ? contextValue : context ;
237237 return callConnectionInternal
238238 .playAudioWithResponseAsync (callConnectionId , playAudioRequest , contextValue )
239- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException )
239+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
240240 .map (response ->
241241 new SimpleResponse <>(response , PlayAudioResultConverter .convert (response .getValue ())));
242242 });
@@ -254,7 +254,8 @@ Mono<Response<PlayAudioResult>> playAudioWithResponseInternal(
254254 public Mono <Void > hangup () {
255255 try {
256256 return callConnectionInternal .hangupCallAsync (callConnectionId )
257- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
257+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
258+ .flatMap (result -> Mono .empty ());
258259 } catch (RuntimeException ex ) {
259260 return monoError (logger , ex );
260261 }
@@ -275,7 +276,7 @@ Mono<Response<Void>> hangupWithResponse(Context context) {
275276 return withContext (contextValue -> {
276277 contextValue = context == null ? contextValue : context ;
277278 return callConnectionInternal .hangupCallWithResponseAsync (callConnectionId , contextValue )
278- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
279+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException );
279280 });
280281 } catch (RuntimeException ex ) {
281282 return monoError (logger , ex );
@@ -295,7 +296,7 @@ public Mono<CancelAllMediaOperationsResult> cancelAllMediaOperations(String oper
295296 CancelAllMediaOperationsRequest request = new CancelAllMediaOperationsRequest ();
296297 request .setOperationContext (operationContext );
297298 return callConnectionInternal .cancelAllMediaOperationsAsync (callConnectionId , request )
298- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException )
299+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
299300 .flatMap (result -> Mono .just (CancelAllMediaOperationsResultConverter .convert (result )));
300301 } catch (RuntimeException ex ) {
301302 return monoError (logger , ex );
@@ -324,7 +325,7 @@ Mono<Response<CancelAllMediaOperationsResult>> cancelAllMediaOperationsWithRespo
324325 contextValue = context == null ? contextValue : context ;
325326 return callConnectionInternal
326327 .cancelAllMediaOperationsWithResponseAsync (callConnectionId , request , contextValue )
327- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException )
328+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
328329 .map (response ->
329330 new SimpleResponse <>(response , CancelAllMediaOperationsResultConverter .convert (response .getValue ())));
330331 });
@@ -336,25 +337,26 @@ Mono<Response<CancelAllMediaOperationsResult>> cancelAllMediaOperationsWithRespo
336337 /**
337338 * Add a participant to the call.
338339 *
339- * @param participant Invited participant.
340+ * @param participant Added participant.
340341 * @param alternateCallerId The phone number to use when adding a phone number participant.
341342 * @param operationContext The value to identify context of the operation. This is used to co-relate other
342343 * communications related to this operation
343344 * @return response for a successful add participant request.
344345 */
345346 @ ServiceMethod (returns = ReturnType .SINGLE )
346- public Mono <Void > addParticipant (
347+ public Mono <AddParticipantResult > addParticipant (
347348 CommunicationIdentifier participant ,
348349 String alternateCallerId ,
349350 String operationContext ) {
350351 try {
351352 Objects .requireNonNull (participant , "'participant' cannot be null." );
352- InviteParticipantsRequest request = InviteParticipantRequestConverter .convert (participant ,
353+ AddParticipantRequest request = AddParticipantRequestConverter .convert (participant ,
353354 alternateCallerId ,
354355 operationContext ,
355356 null );
356- return callConnectionInternal .inviteParticipantsAsync (callConnectionId , request )
357- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
357+ return callConnectionInternal .addParticipantAsync (callConnectionId , request )
358+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
359+ .flatMap (result -> Mono .just (new AddParticipantResult (result .getParticipantId ())));
358360 } catch (RuntimeException ex ) {
359361 return monoError (logger , ex );
360362 }
@@ -363,35 +365,37 @@ public Mono<Void> addParticipant(
363365 /**
364366 * Add a participant to the call.
365367 *
366- * @param participant Invited participant.
368+ * @param participant Added participant.
367369 * @param alternateCallerId The phone number to use when adding a phone number participant.
368370 * @param operationContext The value to identify context of the operation. This is used to co-relate other
369371 * communications related to this operation
370372 * @return response for a successful add participant request.
371373 */
372374 @ ServiceMethod (returns = ReturnType .SINGLE )
373- public Mono <Response <Void >> addParticipantWithResponse (
375+ public Mono <Response <AddParticipantResult >> addParticipantWithResponse (
374376 CommunicationIdentifier participant ,
375377 String alternateCallerId ,
376378 String operationContext ) {
377379 return addParticipantWithResponse (participant , alternateCallerId , operationContext , null );
378380 }
379381
380- Mono <Response <Void >> addParticipantWithResponse (
382+ Mono <Response <AddParticipantResult >> addParticipantWithResponse (
381383 CommunicationIdentifier participant ,
382384 String alternateCallerId ,
383385 String operationContext ,
384386 Context context ) {
385387 try {
386388 Objects .requireNonNull (participant , "'participant' cannot be null." );
387- InviteParticipantsRequest request =
388- InviteParticipantRequestConverter
389+ AddParticipantRequest request =
390+ AddParticipantRequestConverter
389391 .convert (participant , alternateCallerId , operationContext , null );
390392 return withContext (contextValue -> {
391393 contextValue = context == null ? contextValue : context ;
392394 return callConnectionInternal
393- .inviteParticipantsWithResponseAsync (callConnectionId , request , contextValue )
394- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
395+ .addParticipantWithResponseAsync (callConnectionId , request , contextValue )
396+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
397+ .map (response ->
398+ new SimpleResponse <>(response , new AddParticipantResult (response .getValue ().getParticipantId ())));
395399 });
396400 } catch (RuntimeException ex ) {
397401 return monoError (logger , ex );
@@ -408,7 +412,8 @@ Mono<Response<Void>> addParticipantWithResponse(
408412 public Mono <Void > removeParticipant (String participantId ) {
409413 try {
410414 return callConnectionInternal .removeParticipantAsync (callConnectionId , participantId )
411- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
415+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException )
416+ .flatMap (result -> Mono .empty ());
412417 } catch (RuntimeException ex ) {
413418 return monoError (logger , ex );
414419 }
@@ -431,7 +436,7 @@ Mono<Response<Void>> removeParticipantWithResponse(String participantId, Context
431436 contextValue = context == null ? contextValue : context ;
432437 return callConnectionInternal
433438 .removeParticipantWithResponseAsync (callConnectionId , participantId , contextValue )
434- .onErrorMap (CommunicationErrorException .class , CallingServerErrorConverter ::translateException );
439+ .onErrorMap (CommunicationErrorResponseException .class , CallingServerErrorConverter ::translateException );
435440 });
436441 } catch (RuntimeException ex ) {
437442 return monoError (logger , ex );
0 commit comments