loginEvents property

Stream<SyncLoginEvent> get loginEvents

Get a broadcast stream of login events (success/failure).

Subscribe (listen) to the stream to actually start listening to events.

Implementation

Stream<SyncLoginEvent> get loginEvents {
  if (_loginEvents == null) {
    // Combine events from two C listeners: login & login-failure.
    _loginEvents = _SyncListenerGroup<SyncLoginEvent>('sync-login');

    _loginEvents!.add(_SyncListenerConfig(
        (int nativePort) => C.dartc_sync_listener_login(_ptr, nativePort),
        (dynamic _, controller) => controller.add(SyncLoginEvent.loggedIn)));

    _loginEvents!.add(_SyncListenerConfig(
        (int nativePort) =>
            C.dartc_sync_listener_login_failure(_ptr, nativePort),
        (dynamic code, controller) {
      // see OBXSyncCode - TODO should we match any other codes?
      switch (code as int) {
        case OBXSyncCode.CREDENTIALS_REJECTED:
          return controller.add(SyncLoginEvent.credentialsRejected);
        default:
          return controller.add(SyncLoginEvent.unknownError);
      }
    }));

    _loginEvents!.finish();
  }
  return _loginEvents!.stream;
}