processEvent method

  1. @protected
void processEvent(
  1. Map<String, dynamic> mapValue
)

Implementation

@protected
void processEvent(Map<String, dynamic> mapValue) {
  String? dataTimeStr = mapValue["updateTime"];
  if (dataTimeStr == null) {
    return;
  }
  if (realTimeKey == null) {
    lastUpdateTimeStr = dataTimeStr;
  } else {
    DateTime dataTime = DateTime.parse(dataTimeStr);
    int dataTimeSec = dataTime.microsecondsSinceEpoch;
    if (dataTimeSec > maxDataTime.microsecondsSinceEpoch) {
      maxDataTime = dataTime;
    }
    if (dataTimeSec < lastUpdateTime.microsecondsSinceEpoch) {
      return;
    }
  }
  String? fromDeviceId = mapValue["deviceId"];
  if (fromDeviceId == null) {
    logger.info('!!! deviceId is null !!! ');
    return;
  }
  if (fromDeviceId == myDeviceId) {
    logger.fine('!!! deviceId same !!! $myDeviceId');
    //print('same deviceId=$fromDeviceId &&&&&&&&&&&&&&&&&&&&&&&&');
    return;
  }

  // mid 와 delta 가 이전 값과 완전히 동일한 데이터도 버려야 한다.
  String? delta = mapValue["delta"];
  if (delta == null || delta.isEmpty || isDuplicationEvent(delta) == true) {
    logger.info('!!! same data  !!!');
    return;
  }

  logger.info('event.payload=$mapValue');
  logger.info('---- matched !!!  ----');
  logger.info('event received=$fromDeviceId, $realTimeKey');

  String directive = mapValue["directive"] ?? '';
  // = mapValue["mid"] ?? '';
  String collectionId = mapValue["collectionId"] ?? '';
  String userId = mapValue["userId"] ?? '';
  //print('$lastUpdateTimeStr,$directive,$collectionId,$userId -----------------------------');

  Map<String, dynamic> dataMap = json.decode(delta) as Map<String, dynamic>;
  String? parentMid = dataMap['parentMid'] as String?;
  if (parentMid == null || parentMid.isEmpty) {
    //print('parentMid is null');
    return;
  }
  for (var key in listenerMap.keys) {
    //print('parentMid=$parentMid, key=$key');
    if (key != parentMid) continue;
    var map = listenerMap[key];
    map![collectionId]?.call(key, directive, userId, dataMap);
    break;
  }
}