replaceCall method

Future<void> replaceCall(
  1. CallSession existingCall,
  2. CallSession replacementCall
)

Implementation

Future<void> replaceCall(
    CallSession existingCall, CallSession replacementCall) async {
  final existingCallIndex =
      calls.indexWhere((element) => element == existingCall);

  if (existingCallIndex == -1) {
    throw Exception('Couldn\'t find call to replace');
  }

  calls.removeAt(existingCallIndex);
  calls.add(replacementCall);

  await disposeCall(existingCall, CallErrorCode.Replaced);
  await initCall(replacementCall);

  onGroupCallEvent.add(GroupCallEvent.CallsChanged);
}