@@ -241,10 +241,18 @@ class CallContext {
241
241
: undefined ;
242
242
const transferCall = latestAcceptedTransfer ? clientState . calls [ latestAcceptedTransfer . callId ] : undefined ;
243
243
244
+ /* @conditional -compile-remove(breakout-rooms) */
245
+ const originCall = call ?. breakoutRooms ?. breakoutRoomOriginCallId
246
+ ? clientState . calls [ call ?. breakoutRooms ?. breakoutRoomOriginCallId ]
247
+ : latestEndedCall ?. breakoutRooms ?. breakoutRoomOriginCallId
248
+ ? clientState . calls [ latestEndedCall ?. breakoutRooms ?. breakoutRoomOriginCallId ]
249
+ : undefined ;
250
+
244
251
const newPage = getCallCompositePage (
245
252
call ,
246
253
latestEndedCall ,
247
254
transferCall ,
255
+ /* @conditional -compile-remove(breakout-rooms) */ originCall ,
248
256
/* @conditional -compile-remove(unsupported-browser) */ environmentInfo
249
257
) ;
250
258
if ( ! IsCallEndedPage ( oldPage ) && IsCallEndedPage ( newPage ) ) {
@@ -349,6 +357,8 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
349
357
private emitter : EventEmitter = new EventEmitter ( ) ;
350
358
private callingSoundSubscriber : CallingSoundSubscriber | undefined ;
351
359
private onClientStateChange : ( clientState : CallClientState ) => void ;
360
+ /* @conditional -compile-remove(breakout-rooms) */
361
+ private originCall : CallCommon | undefined ;
352
362
353
363
private onResolveVideoBackgroundEffectsDependency ?: ( ) => Promise < VideoBackgroundEffectsDependency > ;
354
364
@@ -644,6 +654,8 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
644
654
: { } ;
645
655
const call = this . _joinCall ( audioOptions , videoOptions ) ;
646
656
657
+ /* @conditional -compile-remove(breakout-rooms) */
658
+ this . originCall = call ;
647
659
this . processNewCall ( call ) ;
648
660
return call ;
649
661
} ) ;
@@ -1057,32 +1069,19 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
1057
1069
1058
1070
/* @conditional -compile-remove(breakout-rooms) */
1059
1071
public async returnFromBreakoutRoom ( ) : Promise < void > {
1060
- if ( this . call === undefined ) {
1061
- return ;
1072
+ if ( ! this . originCall ) {
1073
+ throw new Error ( 'Could not return from breakout room because the origin call could not be retrieved.' ) ;
1062
1074
}
1063
1075
1064
- // Find call state of current call from stateful layer. The current call state of breakout room may not be present in calls array
1065
- // if the breakout room call is ended. So search the callsEnded array as well.
1066
- const callState = this . callClient . getState ( ) . calls [ this . call ?. id ]
1067
- ? this . callClient . getState ( ) . callsEnded [ this . call ?. id ]
1068
- : undefined ;
1069
-
1070
- // Find origin call id from breakout room call state
1071
- const originCallId = callState ?. breakoutRooms ?. breakoutRoomOriginCallId ;
1072
-
1073
- // Find origin call from call agent
1074
- const originCall = this . callAgent ?. calls . find ( ( callAgentCall ) => {
1075
- return callAgentCall . id === originCallId ;
1076
- } ) ;
1077
-
1078
- if ( ! originCall ) {
1079
- throw new Error ( 'Could not return from breakout room because the origin call could not be retrieved.' ) ;
1076
+ if ( this . call ?. id === this . originCall . id ) {
1077
+ console . error ( 'Return from breakout room will not be done because current call is the origin call.' ) ;
1078
+ return ;
1080
1079
}
1081
1080
1082
1081
const breakoutRoomCall = this . call ;
1083
- this . processNewCall ( originCall ) ;
1082
+ this . processNewCall ( this . originCall ) ;
1084
1083
await this . resumeCall ( ) ;
1085
- if ( breakoutRoomCall ?. state === 'Connected' ) {
1084
+ if ( breakoutRoomCall ?. state && ! [ 'Disconnecting' , 'Disconnected' ] . includes ( breakoutRoomCall . state ) ) {
1086
1085
breakoutRoomCall . hangUp ( ) ;
1087
1086
}
1088
1087
}
@@ -1220,6 +1219,12 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
1220
1219
if ( this . callingSoundSubscriber ) {
1221
1220
this . callingSoundSubscriber . unsubscribeAll ( ) ;
1222
1221
}
1222
+ /* @conditional -compile-remove(breakout-rooms) */
1223
+ const breakoutRoomsFeature = this . call ?. feature ( Features . BreakoutRooms ) ;
1224
+ /* @conditional -compile-remove(breakout-rooms) */
1225
+ if ( breakoutRoomsFeature ) {
1226
+ breakoutRoomsFeature . off ( 'breakoutRoomsUpdated' , this . breakoutRoomsUpdated . bind ( this ) ) ;
1227
+ }
1223
1228
}
1224
1229
1225
1230
private isMyMutedChanged = ( ) : void => {
@@ -1340,20 +1345,20 @@ export class AzureCommunicationCallAdapter<AgentType extends CallAgent | TeamsCa
1340
1345
1341
1346
/* @conditional -compile-remove(breakout-rooms) */
1342
1347
private breakoutRoomsUpdated ( eventData : BreakoutRoomsEventData ) : void {
1343
- if ( eventData . data ) {
1344
- if ( eventData . type === 'assignedBreakoutRooms' ) {
1345
- this . assignedBreakoutRoomUpdated ( eventData . data ) ;
1346
- } else if ( eventData . type === 'join' ) {
1347
- this . breakoutRoomJoined ( eventData . data ) ;
1348
- }
1348
+ if ( eventData . type === 'assignedBreakoutRooms' ) {
1349
+ this . assignedBreakoutRoomUpdated ( eventData . data ) ;
1350
+ } else if ( eventData . type === 'join' ) {
1351
+ this . breakoutRoomJoined ( eventData . data ) ;
1349
1352
}
1350
-
1351
1353
this . emitter . emit ( 'breakoutRoomsUpdated' , eventData ) ;
1352
1354
}
1353
1355
1354
1356
/* @conditional -compile-remove(breakout-rooms) */
1355
- private assignedBreakoutRoomUpdated ( breakoutRoom : BreakoutRoom ) : void {
1356
- if ( breakoutRoom . state === 'closed' ) {
1357
+ private assignedBreakoutRoomUpdated ( breakoutRoom ?: BreakoutRoom ) : void {
1358
+ if ( ! this . call ?. id ) {
1359
+ return ;
1360
+ }
1361
+ if ( this . originCall ?. id !== this . call ?. id && ( ! breakoutRoom || breakoutRoom . state === 'closed' ) ) {
1357
1362
this . returnFromBreakoutRoom ( ) ;
1358
1363
}
1359
1364
}
0 commit comments