tryStartUXCam static method

Future<void> tryStartUXCam()

Initialize UXCam if it is allowed by RemoteConfig

Implementation

static Future<void> tryStartUXCam() async {
  if (_uxCamRunning || _uxCamInitializing) return;

  assert(DSConstants.isInitialized);

  if (kDebugMode && !_debugModeSend) return;
  if (kIsWeb || !Platform.isAndroid && !Platform.isIOS) return;

  if (DSConstants.I.isInternalVersion) {
    await startUXCam();
    return;
  }

  if (!DSRemoteConfig.I.isInitialized) {
    await DSRemoteConfig.I.waitForInit();
  }

  var val = DSRemoteConfig.I.getUXCamPercent();
  if (val == 0) {
    await DSRemoteConfig.I.waitForFullInit(maxWait: const Duration(seconds: 20));
    val = DSRemoteConfig.I.getUXCamPercent();
    if (val == 0) return;
  }
  final sessions = DSRemoteConfig.I.getUXCamSessions();
  if (sessions != 0 && sessions < DSPrefs.I.getSessionId()) {
    return;
  }

  // if yandexId is empty (or non-valid) use simple random
  final yid = int.tryParse(yandexId.let((s) => s.length >= 2 ? s.substring(s.length - 2) : s)) ?? Random().nextInt(100);
  if ((yid % 100).toInt() < val) {
    await DSMetrica.startUXCam();
  }
}