Kuzzle constructor

Kuzzle(
  1. KuzzleProtocol protocol, {
  2. bool autoQueue = false,
  3. bool autoReplay = false,
  4. bool autoResubscribe = true,
  5. bool deprecationWarnings = true,
  6. int eventTimeout = 200,
  7. OfflineMode offlineMode = OfflineMode.manual,
  8. Function? offlineQueueLoader,
  9. Function? queueFilter,
  10. Duration? queueTTL,
  11. int queueMaxSize = 500,
  12. Duration? replayInterval,
  13. Map<String, dynamic>? globalVolatile,
})

Implementation

Kuzzle(
  this.protocol, {
  this.autoQueue = false,
  this.autoReplay = false,
  this.autoResubscribe = true,
  bool deprecationWarnings = true,
  this.eventTimeout = 200,
  this.offlineMode = OfflineMode.manual,
  this.offlineQueueLoader,
  this.queueFilter,
  this.queueTTL,
  this.queueMaxSize = 500,
  this.replayInterval,
  this.globalVolatile,
}) : deprecationHandler =
          DeprecationHandler(deprecationWarning: deprecationWarnings) {
  if (offlineMode == OfflineMode.auto) {
    autoQueue = true;
    autoReplay = true;
  }

  globalVolatile ??= <String, dynamic>{};
  queueTTL ??= const Duration(minutes: 2);
  replayInterval ??= const Duration(milliseconds: 10);

  server = ServerController(this);
  bulk = BulkController(this);
  auth = AuthController(this);
  index = IndexController(this);
  collection = CollectionController(this);
  document = DocumentController(this);
  security = SecurityController(this);
  realtime = RealTimeController(this);

  protocol.on(ProtocolEvents.QUERY_ERROR, (error, request) {
    emit(KuzzleEvents.QUERY_ERROR, [error, request]);
  });

  protocol.on(ProtocolEvents.NETWORK_ON_RESPONSE_RECEIVED,
      (KuzzleResponse response) {
    if (!_requests.contains(response.room)) {
      emit(KuzzleEvents.UNHANDLED_RESPONSE, [response]);
    }
    if (response.error != null &&
        response.error!.id == 'security.token.expired') {
      jwt = null;
      emit(KuzzleEvents.TOKEN_EXPIRED);
    }
    protocol.emit(response.room!, [response]);
  });
}