destroy method

Future<void> destroy([
  1. bool needQuitClass = true
])

Implementation

Future<void> destroy([bool needQuitClass = true]) async {
  if (_destroyFuture != null) {
    await _destroyFuture;
    return;
  }
  final completer = Completer<void>();
  _destroyFuture = completer.future;
  try {
    await Future.wait([if (_config.basicConfig?.allowPipMode ?? false) getPip().dispose(), TRTC.stopLocalPreview(), TRTC.closeMic('destroy'), TRTC.closeCamera('destroy'), TRTC.stopScreenCapture()]);
    // 关闭所有弹窗
    Tools.closeAllDialogs();
    Tools.closeAllFloating();
    toastification.dismissAll();

    TRTC.reset();

    await exitRTCRoom();
    cancelHeartBeatTimer();

    if (needQuitClass) {
      // 退出群
      if (!skipQuitClass) {
        await _quitClass();
      }
    }

    await Future.wait([
      // 退群
      _exitImGroup(),
      // 退出登录
      _logout(),
      // 移除监听
      _removeAddvancedMsgListener(),
    ]);
    // 反初始化
    await _uninit();

    resetControllerInstance();

    // 课堂自动切换:解绑 adapter 并重置状态机,避免单例残留旧 Controller 引用。
    ClassSwitcher.instance.unbindEnv();
    ClassSwitcher.instance.reset();

    clearObsData();
    TCICTips.resetConfig();
    _ctrlBusinessLogic.dispose();

    _eventbus.fire(MainEvent(type: EventTypeEnum.destroySuccess));

    _eventbus.clear();

    // 销毁配置
    _config.destroy();
  } finally {
    completer.complete();
    _destroyFuture = null;
  }
}