databaseWithFakeServer function

FirebaseDatabase databaseWithFakeServer(
  1. FirebaseApp app,
  2. FakeDatabaseServer server, {
  3. DatabasePersistence? persistence,
  4. DatabaseLogger? logger,
  5. Duration reconnectDelay = const Duration(seconds: 1),
})

A FirebaseDatabase of app connected to server instead of the network.

It is memory only unless persistence is given (see fakePersistence). After a dropped connection it reconnects after reconnectDelay, fixed, with no backoff. Each connection sends the token of the app's authProvider (none when the app has no provider), which FakeDatabaseServer.receivedAuthTokens records.

Implementation

FirebaseDatabase databaseWithFakeServer(
  FirebaseApp app,
  FakeDatabaseServer server, {
  DatabasePersistence? persistence,
  DatabaseLogger? logger,
  Duration reconnectDelay = const Duration(seconds: 1),
}) {
  final AuthTokenProvider provider = app.authProvider;
  // The token source the real connection gets (`persistentConnectionFactory`); with no provider set
  // the app answers as its own provider and throws, which means no user.
  final RealtimeTokenSource tokens = ProviderTokenSource(
    auth: identical(provider, app) ? null : provider,
    forcedRefreshMinInterval:
        const ConnectionTimings().forcedRefreshMinInterval,
    now: DateTime.now,
  );
  return firebaseDatabaseWithConnection(
    app,
    persistence: persistence,
    logger: logger,
    connectionFactory: (ServerActionsDelegate delegate, DatabaseLogger? _) =>
        server.connect(
          delegate,
          reconnectDelay: reconnectDelay,
          tokens: tokens,
        ),
  );
}