getSessionProps method

Future<Map<String, dynamic>> getSessionProps(
  1. String token,
  2. String eventName
)

Implementation

Future<Map<String, dynamic>> getSessionProps(
  String token,
  String eventName,
) async {
  if (!_isInitialized) await _initialize();
  if (eventName == SdkTrackedEvents.sessionMeta.asString) return {};
  return await _sessionLock.synchronized(() async {
    final sessionFuture = sessionManager.getCachedOrNewSession(eventName);
    final sdkConfigFuture = configManager.getConfig(token);
    Session session = await sessionFuture;
    SdkConfig sdkConfig = await sdkConfigFuture;
    Debug.print("TrackingProvider: Session retrieved ${session.sessionId}");
    final now = DateTime.now();
    final nowMs = now.millisecondsSinceEpoch;
    final delta = Duration(minutes: sdkConfig.sessionDurationMins);
    if (now.difference(getTimeFromTs(session.lastCachedTs)) > delta) {
      Debug.print("TrackingProvider: Session expired. Creating new session.");
      captureSession(session);
      session = Session.newSession(createdTs: nowMs, event: eventName);
    } else {
      Debug.print("TrackingProvider: Updating cached timestamp for session.");
      session = session.copyWith(cachedTs: nowMs, endEventName: eventName);
    }
    await sessionManager.storeSessionInCache(session);
    return _getSessionPropsMap(session);
  });
}