disposeCall method

Future<void> disposeCall(
  1. CallSession call,
  2. String hangupReason
)

Implementation

Future<void> disposeCall(CallSession call, String hangupReason) async {
  final opponentMemberId = call.opponentDeviceId;

  if (opponentMemberId == null) {
    throw Exception('Cannot dispose call without user id');
  }

  callHandlers.remove(opponentMemberId);

  if (call.hangupReason == CallErrorCode.Replaced) {
    return;
  }

  if (call.state != CallState.kEnded) {
    await call.hangup(hangupReason, false);
  }

  final usermediaStream = getUserMediaStreamByUserId(opponentMemberId);

  if (usermediaStream != null) {
    await removeUserMediaStream(usermediaStream);
  }

  final screenshareStream = getScreenshareStreamByUserId(opponentMemberId);

  if (screenshareStream != null) {
    await removeScreenshareStream(screenshareStream);
  }
}