doDisposeCallback method

dynamic doDisposeCallback({
  1. String? error,
  2. dynamic result,
})

Implementation

doDisposeCallback ({String? error, dynamic result}) {
  if (disposed) {
    logger("doDisposeCallback already called before", level: Level.debug);
    return;
  }
  logger("doDisposeCallback");
  assert(result == null || result is RequestCallResult || result is AcceptingCallResult);
  disposed = true;

  for (final disposeCallback in disposeList) {
    try {
      disposeCallback();
    }catch(e) {
      logger(e.toString());
    }
  }
  for (final listener in onCallCloses) {
    listener();
  }

  if (error != null || result != null) {
    if (resultCompleterForAcceptingCall != null &&
        !resultCompleterForAcceptingCall!.isCompleted) {
      if (error != null) {
        resultCompleterForAcceptingCall!.complete(
            AcceptingCallResult(error: error));
      } else {
        resultCompleterForAcceptingCall!.complete(result);
      }
    }
    if (resultCompleterForRequestingCall != null &&
        !resultCompleterForRequestingCall!.isCompleted) {
      if (error != null) {
        resultCompleterForRequestingCall!.complete(RequestCallResult(callAccepted: false, error: error));
      } else {
        resultCompleterForRequestingCall!.complete(result);
      }
    }
  }

  if (resultCompleterForRequestingCall?.isCompleted == false) {
    resultCompleterForRequestingCall!.complete(RequestCallResult(callAccepted: false, error: "Interrupted"));
  }
  if (resultCompleterForAcceptingCall?.isCompleted == false) {
    resultCompleterForAcceptingCall!.complete(AcceptingCallResult(liveCall: null, error: "Interrupted"));
  }


  rtcPeerConnection?.close();
  localStream?.dispose();
  receivingCall?.dispose();
  requestCallInstance?.dispose();
  liveCall?.dispose();
}